manywaypark's Blog
개발, 검색, 함수

갑자기 코드 자동완성이 안되는 경우가 발생했는데, 해결법은 아래와 같다. 좀 이상하게도 플러그인을 disable해야한다.

Help > About Plugins... 에 들어가서 ClangCodeModel을 시작시 로드하지 않게 uncheck한 다음 Qt Creator를 재시작한다.

현재 환경 참고:

Qt Creator 4.11.0
Based on Qt 5.14.0 (MSVC 2017, 32 bit)
Built on Dec 10 2019 12:27:13
From revision 017ed74400

ref: https://forum.qt.io/topic/107498/code-completion-is-not-working-in-qtcreator/3

 

Code completion is not working in QtCreator?

Hi, Great. Works like a charm. :) But what is the problem with ClangCodeModel? Is this BUG?... Regardsi Mucip:)

forum.qt.io

 

happy hackin'

qmake file 에서의 INSTALLS

tips & tricks/Qt 2018. 10. 26. 14:01 by manywaypark

qmake 파일에서 INSTALLS에 뭔가 추가할 때는 한번에 하나씩해야한다.

problem:

.lib 파일과 .dll을 각각 /path/to/install의 하위에 설치하려는 (제법 멋진) 의도를 가진 아래 코드는 (n)make install 했을 때 제대로 동작하지 않고 .lib 파일만 설치된다.

    target_lib.path  = /path/to/install/lib

    target_lib.files = $${DESTDIR}/*.lib

    target_dll.path  = /path/to/install/bin

    target_dll.files = $${DESTDIR}/*.dll

    INSTALLS += target_lib target_dll


solution:

이렇게 두 종류의 파일 타입을 각각 써줘야 제대로 동작한다.

    target_lib.path  = /path/to/install/lib

    target_lib.files = $${DESTDIR}/*.lib

    INSTALLS += target_lib

    target_dll.path  = /path/to/install/bin

    target_dll.files = $${DESTDIR}/*.dll

    INSTALLS += target_dll


happy hackin'


PS. 몇년이나 지난 코드에서, 그동안 사용할 때마다 dll은 수동 복사했던 project file에서 발견함. Orz.


Qt + MSVC 2017

tips & tricks/Qt 2018. 10. 16. 18:00 by manywaypark

현재 기준(VS2017)으로 설명한다. 

일단 VS를 설치하면 기본적으로는 VC가 안깔린다. 

요즘은 다들 C++ 따위 쓰지 않나봐. Orz.

VC 설치:

Visual Studio Installer에서 Visual Studio Community 2017 > (More 밑의) Modify > Desktop development with C++ 을 선택해서 VC를 설치한다.

Qt 설치:

Qt 설치 시에 msvc 어쩌구 하는 component들 중에서 2017 관련이 보이면 그걸 설치하고, 없으면 2015 관련을 설치한다 (2015와 2017은 호환된다고 어디서 봤다).


매번 헷갈리네. 이건 내 문제가 아니라 MS 문제일지도...


happy hackin'


refs: 

  • https://forum.qt.io/topic/78962/how-to-use-qt-with-visual-studio-2017/12
  • https://stackoverflow.com/questions/45164515/how-to-use-visual-studio-2017-with-qt-to-develop-gui-applications


problem:

Windows, MSVC 환경에서 min이나 max가 포함된 qt 파일(eg, qrandom.h 등)에서 다음과 같은 경고가 나온 후에, 괴상한 에러가 나면서 컴파일에 실패하는 경우가 발생했다.

warning C4003: not enough actual parameters for macro 'max'


solution:

windows.h가 include 되기 전에 다음과 같은 선언을 넣어준다.

#ifndef NOMINMAX

# define NOMINMAX

#endif


ref: https://stackoverflow.com/questions/6884093/warning-c4003-not-enough-actual-parameters-for-macro-max-visual-studio-2010


happy hackin'

Qt에서 pkg-config 쓰기

tips & tricks/Qt 2017. 3. 28. 23:42 by manywaypark


보통 아래처럼 패키지 정보를 조회후에 결과 스트링을 Makefile이나 build script의 CFLAGS나 CXXFLAGS, LDFLAGS등에 추가해서 쓰는데...


$ pkg-config --cflags protobuf

-pthread -I/usr/local/include

$ pkg-config --libs protobuf

-L/usr/local/lib -lprotobuf -pthread -lpthread


Qt의 qmake에서는 프로젝트 파일에 아래처럼 써주면 똑같은 효과를 낼 수 있다.


CONFIG += link_pkgconfig

PKGCONFIG += protobuf


ref: http://stackoverflow.com/questions/3517694/linking-libraries-to-a-qt-project-using-pkg-config-output


happy hackin'

google breakpad + qt

카테고리 없음 2014. 11. 12. 18:02 by manywaypark
  • https://github.com/JPNaude/dev_notes/wiki/Using-Google-Breakpad-with-Qt
  • http://blog.inventic.eu/2012/08/qt-and-google-breakpad/


happy hackin'

Qt에서 c++11 쓰기

tips & tricks/Qt 2014. 8. 25. 10:51 by manywaypark

현재(Qt 5.3.1) 버전 기준으로 .pro 파일에 다음 라인을 추가하면 된다.

CONFIG += c++11


refs: 

http://woboq.com/blog/cpp11-in-qt5.html

https://www.ics.com/blog/qt-and-c11#.U_q2zfnV_bI


happy hackin'

문제:
Qt의 QFile::copy()는 Windows와 Symbian에서만 native copy를 사용해 구현되어있다(2011-07-20 기준).
http://bugreports.qt.nokia.com/browse/QTBUG-10369
http://bugreports.qt.nokia.com/browse/QTBUG-10337
따라서 다른 platform에서 copy()를 사용하면 복사된 파일이 copy() 수행 시점의 timestamp를 가지게 된다.

해결:
지금 내 경우에는 생성시간의 유지가 중요한 상황이므로 다음과 같이 간단하게 회피하는 QFileFixed class를 만들어서 해결했다.

// file: QFileFixed.h

//! \author manywaypark at gmail.com http://manywaypark.tistory.com
 

class QFileFixed : public QFile

{

public:

    QFileFixed(const QString &name);

#if !(defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN))

    bool copy(const QString &newName);

    static bool copy(const QString &fileName, const QString &newName);

private:

    static void copyFileTime(const QFileInfo &srcInfo, const QString &dstPath);

#endif

};


// file: QFileFixed.cpp

//! \author manywaypark at gmail.com http://manywaypark.tistory.com


#if !(defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN))

#include <sys/time.h>

#endif


QFileFixed::QFileFixed(const QString &name)

    : QFile(name)

{}


#if !(defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN))

bool QFileFixed::copy(const QString &newName){

    bool r(QFile::copy(newName));

    if (r) copyFileTime(QFileInfo(*this), newName);

    return r;

}


bool QFileFixed::copy(const QString &fileName, const QString &newName)

{

    bool r(QFile::copy(fileName, newName));

    if (r) copyFileTime(QFileInfo(fileName), newName);

    return r;

}


void QFileFixed::copyFileTime(const QFileInfo &srcInfo, const QString &dstPath)

{

    QDateTime access(srcInfo.lastRead());

    QDateTime created(srcInfo.created()); /* created == modification?? */

    struct timeval time[2];

    time[0].tv_sec = access.toTime_t();

    time[0].tv_usec = access.time().msec() * 1000; /* millisecond to microsecond */

    time[1].tv_sec = created.toTime_t();

    time[1].tv_usec = created.time().msec() * 1000; /* millisecond to microsecond */

    int r = utimes(dstPath.toAscii().constData(), time);


    Q_ASSERT(r == 0);

}

#endif // !(defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN)


Windows와 Mac OSX에서 테스트되었고, 내가 필요한 파일 생성 시간 유지는 잘 되는 것을 확인했다.

happy hackin'

문제
원래 Qt에서 단축키 추가는 너무 쉽다. 아래와 같이 하면 그냥 잘 된다.
action.setShortcut(QKeySequence(Qt::ALT + Qt::Key_C));
다만 문제는 MainWindow에서만 잘 된다는 것...   Orz
구글링을 해봐도 오래된 질문만 있고 답변은 없었다.

해결
처음에는 keyPressEvent 쪽에서 처리하는 다소 지저분한 방법을 쓰려했으나,
영 내키지 않던 차에 Qt Help에서 힌트를 얻을 수 있었다.
QShortcut이라는 클래스가 있었던 것이다.
QShortcut *shortcut = new QShortcut(QKeySequence(Qt::ALT + Qt::Key_C), parent);
connect(shortcut, SIGNAL(activated()),
        &action, SLOT(trigger()));

동작은 잘 하는데 메뉴 등에 표시를 위해서는 action.setShortcut()도 해주어야한다.

happy hackin'

.pro 또는 .pri 파일에 다음 내용을 추가하면 된다.

CONFIG(debug, debug|release):DEFINES+=DEBUG
CONFIG(release, debug|release):DEFINES+=RELEASE

refs:
1 2 
분류 전체보기 (306)
잡담 (20)
함수형 언어 (65)
emacs (16)
java (18)
tips & tricks (154)
사랑 (1)
가사 (0)
독서 (4)
mobile (6)
비함수형 언어 (2)

공지사항

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

04-19 07:18