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

Qt에서 emacs key binding 사용하기

tips & tricks/Qt 2020. 8. 19. 15:04 by manywaypark
  1. Help > About Plugins... 에서 emacs plugin을 활성화 (이후 Qt Creator 재시작 필요함)
  2. Tools > Options... 에서 Environment > Keyboard 에서 아래 Emacs.kms 다운로드 후 import!
    Emacs.kms

ref: machinekoder.com/running-qt-creator-in-emacs-mode/

갑자기 코드 자동완성이 안되는 경우가 발생했는데, 해결법은 아래와 같다. 좀 이상하게도 플러그인을 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'

윈도우즈에서는 뒤에 버전번호가 붙은 DLL은 좀 귀찮은 면이 많다. 아마도 자동으로 symlink를 생성할 수 없어서 기본으로 버전번호가 붙은 DLL만 생성되는 것으로 보인다.

따라서 그냥 없애는 것이 편하다.

간단하게 아래 두 방법 중 하나를 선택하면 되는데...

CONFIG += skip_target_version_ext

또는

VERSION = 0.0.1
win32:TARGET_EXT = .dll

win32에서만 버전번호 없는 dll을 하나 더 생성하게 하는 두번째 방법이 좀더 유용한듯하다.

(즉, 다시말해 완전히 없애는 첫번째 방법을 취한다면 unix 계열에서 우아하게 버전번호 붙이고 버전 번호 없는 대표명으로 링크 생성하는 것이 동작하지 않는다)

refs:

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'

problem

win32환경에서 qt/mingw를 사용해서 빌드할 때 아래 같이 moc.exe 를 못찾겠다고 하면서 컴파일 실패하는 경우가 있다.


......

compiling ../../qwt/src/qwt_thermo.cpp

compiling ../../qwt/src/qwt_wheel.cpp

moc ../../qwt/src/qwt_dyngrid_layout.h

/usr/bin/sh: C:\Qt\5.3\mingw482_32\bin\moc.exe: command not found

Makefile.Release:368: recipe for target 'moc/moc_qwt_dyngrid_layout.cpp' failed

mingw32-make[2]: *** [moc/moc_qwt_dyngrid_layout.cpp] Error 127

mingw32-make[2]: Leaving directory 'C:/Users/dhpark/hacking/qwt-code/build-qwt-Desktop_Qt_5_3_MinGW_32bit-Release/src'

mingw32-make[1]: *** [release-all] Error 2

Makefile:38: recipe for target 'release-all' failed

mingw32-make[1]: Leaving directory 'C:/Users/dhpark/hacking/qwt-code/build-qwt-Desktop_Qt_5_3_MinGW_32bit-Release/src'

Makefile:45: recipe for target 'sub-src-make_first-ordered' failed

mingw32-make: *** [sub-src-make_first-ordered] Error 2

14:27:20: The process "C:\Qt\Tools\mingw482_32\bin\mingw32-make.exe" exited with code 2.

Error while building/deploying project qwt (kit: Desktop Qt 5.3 MinGW 32bit)

When executing step 'Make'

14:27:20: Elapsed time: 03:23.


solution

sh의 문제로 파악됨. 즉, 다른 sh가 compile 과정에 개입되어서 생기는 문제임.

Qt/MingW 설치 디렉토리 이외의 sh를 사용하지 못하게 PATH에서 Cygwin, MSYS등을 제거한다.


ref: http://www.qtcentre.org/threads/947-Problem-with-make-(can-t-call-moc-exe)


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'

1 2 
분류 전체보기 (306)
잡담 (20)
함수형 언어 (65)
emacs (16)
java (18)
tips & tricks (154)
Linux/Unix (57)
Win (19)
Qt (11)
Xcode (1)
Mac (8)
사랑 (1)
가사 (0)
독서 (4)
mobile (6)
비함수형 언어 (2)

공지사항

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

04-25 01:31