Qt for Linux

prerequisits

  • graphic driver (latest) 설치

QT 통합 online installer, window

QT 5.15

installer (offline)

sudo apt-get install libxcb-xinerama0
export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH
qtcreator
  • 설치 위치 /home/ko/Qt5.12.12

apt-get install

sudo apt-get install qt5-default

QT 6.6

installer

chmod +x qt-unified-linux-x64-4.6.1-online.run
./qt-unified-linux-x64-4.6.1-online.run
  • QT account 생성

  • 라이선스 확인: GPLv3, LGPLv3
    • LGPL 라이선스를 사용하면 무료로 Qt를 상업 및 개인 프로젝트에 사용할 수 있습니다. LGPL 라이선스를 사용하는 경우에도 Qt의 소스 코드를 수정한 경우 해당 수정 사항을 공개해야 할 수 있으므로 주의가 필요합니다
    • 그러나 Qt를 LGPL 라이선스로 사용할 때도 특정 조건과 제약 사항이 있을 수 있으므로 정확한 사용 사례와 라이선스에 대한 이해가 필요합니다.
    • 라이선스 CMake license agreement, GPLv3 with Qt company GPL exception license agreement, Ninja license agreement, Qt installer LGPL License Agreement
  • 일단 옵션 중에서, Qt 6.6 for Desktop development 옵션을 선택했다.

  • 설치까지 20분 정도 걸림.

  • Qt creator를 실행하면 오류 메시지가 나옴
from 6.5.0, xcb-cursor0 or libxcb-cursor0 is needed to load the Qt xcb plaform plugin. Could not load the Qt platform plugin xcb in '' even though it was found. This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem. Available platform plugins are: minimal, vkkhrdisplay, eglfs, linuxfb, offscreen, vnc, wayland-egl, minimalegl, wayland, xcb.
  • xcb-cursor0 또는 libxcb-cursor0 설치
sudo apt-get install libxcb-cursor0
export QT_DEBUG_PLUGINS=1 # 환경변수 설정
  • 다시 Qt creator 실행 -> 성공!

QT creator

  • File > New File or Project
  • Application > Qt widget Application > Choose…
  • 프로젝트 이름, 위치 및 기타 설정 지정
  • Kit selection > 사용할 Qt 버전과 킷을 선택
  • 코드 작성 (생성된 프로젝트에서 main.cpp 파일을 열고 C++ 코드를 작성한다.)

코드 예제

QT5 example (github)

Qt creator로 자동 생성된 예제

#include <QCoreApplication>
#include <QLocale>
#include <QTranslator>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QTranslator translator;
    const QStringList uiLanguages = QLocale::system().uiLanguages();
    for (const QString &locale : uiLanguages) {
        const QString baseName = "Qt_practice_01_" + QLocale(locale).name();
        if (translator.load(":/i18n/" + baseName)) {
            a.installTranslator(&translator);
            break;
        }
    }

    return a.exec();
}

이미지 합성 예제 (Qt creator 제공)

Qt creator로 생성한 Cmake와 main.cpp들을 가져와서 VS code에서 응용하여 빌드할 때

  • 터미널에 cmake에게 Qt가 어디에 설치되어 있는 지 알려줘야 한다(일회용)
cmake -DCMAKE_PREFIX_PATH=/home/ko/Qt/6.6.1/gcc_64 .. # lib 나오기 전까지의 설치경로

삭제

sudo apt-get remove --purge 'qt*'