• Linux

    Qt for Linux/X11

    Requirements for Development Host

    Debian/Ubuntu (apt-get)

    sudo apt-get install build-essential libgl1-mesa-dev

    Fedora/RHEL/CentOS (yum)

    sudo yum groupinstall "C Development Tools and Libraries"
    sudo yum install mesa-libGL-devel

    openSUSE (zypper)

    sudo zypper install -t pattern devel_basis

    Downloading and Installing Qt

    Untuk file installer Qt, dapat diunduh disini.

  • RaspberryPi

    Cross-compilation Qt 5.9.6 for RaspberryPi

    Persiapan Raspberry Pi

    Update package

    Edit sources list /etc/apt/sources.list, kemudian uncomment baris deb-src:

    sudo nano /etc/apt/sources.list
    sudo apt-get update
    sudo apt-get dist-upgrade
    sudo reboot

    Update Raspberry Pi firmware

    sudo rpi-update
    sudo reboot

    Install dependencies

    sudo apt-get build-dep qt4-x11
    sudo apt-get build-dep libqt5gui5
    sudo apt-get install libudev-dev libinput-dev libts-dev libxcb-xinerama0-dev libxcb-xinerama0

    Persiapan Linux Host

    Pada tutorial ini digunakan Ubuntu 16.04 x64.

    Update package

    sudo apt-get update
    sudo apt-get -y upgrade

    Install dependencies

    sudo apt-get install git bison python gperf

    Buat folder kerja

    sudo mkdir /opt/qt5pi
    sudo chown akhal:akhal /opt/qt5pi
    cd /opt/qt5pi

    Clone toolchain

    git clone https://github.com/raspberrypi/tools

    Tambahkan toolchain binary di variabel PATH

    nano ~/.bashrc

    Tambahkan baris berikut:

    export PATH=$PATH:/opt/qt5pi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin

    Download QT Source

    https://download.qt.io/official_releases/qt/5.9/5.9.6/single/qt-everywhere-opensource-src-5.9.6.tar.xz

    Untar QT source

    tar -xvf t-everywhere-opensource-src-5.9.6.tar.xz

    Buat hf configuration

    cp -R qt-everywhere-opensource-src-5.9.6/qtbase/mkspecs/linux-arm-gnueabi-g++ qt-everywhere-opensource-src-5.9.6/qtbase/mkspecs/linux-arm-gnueabihf-g++
    sed -i -e 's/arm-linux-gnueabi-/arm-linux-gnueabihf-/g' qt-everywhere-opensource-src-5.9.6/qtbase/mkspecs/linux-arm-gnueabihf-g++/qmake.conf

    Copy raspberry pi sysroot

    mkdir sysroot sysroot/usr sysroot/opt
    rsync -avz akhal@192.168.1.100:/lib sysroot
    rsync -avz akhal@192.168.1.100:/usr/include sysroot/usr
    rsync -avz akhal@192.168.1.100:/usr/lib sysroot/usr
    rsync -avz akhal@192.168.1.100:/opt/vc sysroot/opt

    Buat symlinks to “missing” libraries

    mv sysroot/usr/lib/arm-linux-gnueabihf/libEGL.so.1.0.0 sysroot/usr/lib/arm-linux-gnueabihf/libEGL.so.1.0.0_backup
    ln -s sysroot/opt/vc/lib/libEGL.so sysroot/usr/lib/arm-linux-gnueabihf/libEGL.so.1.0.0
    mv sysroot/usr/lib/arm-linux-gnueabihf/libGLESv2.so.2.0.0 sysroot/usr/lib/arm-linux-gnueabihf/libGLESv2.so.2.0.0_backup
    ln -s sysroot/opt/vc/lib/libGLESv2.so sysroot/usr/lib/arm-linux-gnueabihf/libGLESv2.so.2.0.0
    ln -s sysroot/opt/vc/lib/libEGL.so sysroot/opt/vc/lib/libEGL.so.1
    ln -s sysroot/opt/vc/lib/libGLESv2.so sysroot/opt/vc/lib/libGLESv2.so.2

    Ganti absolute symlinks dalam bentuk relative symlinks

    wget https://raw.githubusercontent.com/riscv/riscv-poky/master/scripts/sysroot-relativelinks.py
    chmod +x sysroot-relativelinks.py
    ./sysroot-relativelinks.py sysroot

    Buat folder untuk build

    mkdir qt5build
    cd qt5build

    Konfigurasi QT Source

    ../qt-everywhere-opensource-src-5.9.6/configure -opengl es2 -device linux-rasp-pi-g++ -device-option CROSS_COMPILE=arm-linux-gnueabihf- -sysroot /opt/qt5pi/sysroot -prefix /usr/local/qt5pi -opensource -confirm-license -skip qtwebengine -skip qtscript -nomake examples -make libs -v

    Jika muncul error unknown CPU architecture ketika konfigurasi, tambahkan baris -no-use-gold-linker sehingga menjadi:

    ../qt-everywhere-opensource-src-5.9.6/configure -opengl es2 -device linux-rasp-pi-g++ -device-option CROSS_COMPILE=arm-linux-gnueabihf- -sysroot /opt/qt5pi/sysroot -prefix /usr/local/qt5pi -opensource -confirm-license -skip qtwebengine -skip qtscript -nomake examples -make libs -v -no-use-gold-linker

    Make

    Jika konfigurasi sudah selesai, jalankan perintah make.

    make
    make install

    Upload hasil compile ke Raspberry Pi

    cd /opt/qt5pi
    rsync -avz sysroot/usr/local/qt5pi akhal@192.168.1.100:/usr/local

    Konfigurasi Pada QT Creator

    Install QT

    Konfigurasi toolkit

    Buka QT Creator, kemudian pilih option dan tambahkan parameter-parameter berikut:

    • Tools->Options…->Devices->Add
      Generic Linux Device
      Edit host, username, dan password.
    • Tools->Build&Run->Debuggers->Add
      Edit name dan path ( /opt/qt5pi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-gdb )
    • Tools->Compilers->Add->GCC->C
      Edit name dan path ( /opt/qt5pi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-gcc )
    • Tools->Compilers->Add->GCC->C++
      Edit name dan path ( /opt/qt5pi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-g++ )
    • Tools->Qt Versions->Add
      Pilih /opt/qt5pi/sysroot/usr/local/qt5pi/bin/qmake
    • Tools->Kits->Add
      Edit name
      Device type: Generic Linux Device
      Device: raspberry pi device
      Sysroot: Choose /opt/qt5pi/sysroot
      C and C++: Choose prior created raspberry pi compilers
      Debugger: Choose prior created raspberry pi debugger
      Qt version: Choose prior created raspberry pi qt version

    Selesai

  • QT

    QtMQTT on Windows 10

    Pada tutorial berikut ini, menggunakan QT versi 5.10.1 dengan mingw53_32.

    Pada QT versi 5.10 atau lebih tinggi, tidak perlu menggunakan modul tambahan, cukup menambahkan baris berikut pada file project.

    QT += mqtt

    Untuk menggunakan MQTT pada QT, diperlukan QtMQTT module yang terinstall pada QT lib directory. Untuk memeriksa apakah module sudah terinstall, bisa dicek dengan melihat pada folder QT lib directory. Untuk mengetahui posisi QT lib directory, dapat menggunakan perintah berikut:

    qmake -query QT_INSTALL_LIBS

    Cek folder yang ditunjukkan, apakah file Qt5Mqtt.dll ada atau tidak. Jika belum ada, perlu install QtMQTT module tersebut. Download source code QT MQTT  dengan menggunakan git command:

    git clone git://code.qt.io/qt/qtmqtt.git

    Setelah selesai, pindah ke folder file qtmqtt.pro dengan menggunakan perintah cd, kemudian jalankan command berikut:

    qmake
    mingw32-make
    mingw32-make install

    Jika sudah selesai, cek lagi folder QT lib directory.

  • QT

    qt error: LNK1181: cannot open input file ‘shell32.lib’

    Suatu saat, saya mendapatkan qt error: LNK1181: cannot open input file ‘shell32.lib’ ketika compiling dengan QT 5.9 dan MSVC2015 32bit. Untuk mengatasi masalah tersebut, dapat menambahkan library Microsoft SDKs pada file project.

    Buka file project (biasanya berekstensi .pro), kemudian tambahkan library berikut ini:

    win32:CONFIG(release, debug|release): LIBS += -L$$quote(C:/Program Files (x86)/Microsoft SDKs/Windows/v7.1A/Lib/) -lshell32
    else:win32:CONFIG(debug, debug|release): LIBS += -L$$quote(C:/Program Files (x86)/Microsoft SDKs/Windows/v7.1A/Lib/) -lshell32
    
    INCLUDEPATH += $$quote(C:/Program Files (x86)/Microsoft SDKs/Windows/v7.1A/Include)
    DEPENDPATH += $$quote(C:/Program Files (x86)/Microsoft SDKs/Windows/v7.1A/Include)