Phrogz
Phrogz

Reputation: 303224

Building QML applications from command line (without Qt Creator)

I'm writing a QML application using Qt 5.7 on Ubuntu 14.04. I prefer to use an editor other than Qt Creator, so it makes it slightly cumbersome to launch Qt Creator and switch to it just to press Ctrl-R each time I want to run. I'd like to compile and launch my app from the command line.

Following this answer and then this answer I was able to install qmake and make it the default:

sudo apt-get install qt5-qmake
sudo apt-get install qt5-default

Following this answer I am copying the qmake build command listed by Qt Creator in the Project tab and successfully building the make file:

qmake qt-client.pro -r -spec linux-g++

However, when I run make (on my already-working-in-Qt-Creator code) I get:

phrogz@Slub:~/Code/rb3jay/qt-client$ make
g++ -c -pipe -O2 -std=c++0x -Wall -W -D_REENTRANT -fPIE -DQT_NO_DEBUG -DQT_QUICK_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ -I. -I/usr/include/qt5 -I/usr/include/qt5/QtQuick -I/usr/include/qt5/QtQml -I/usr/include/qt5/QtNetwork -I/usr/include/qt5/QtGui -I/usr/include/qt5/QtCore -I. -o main.o main.cpp
main.cpp: In function ‘int main(int, char**)’:
main.cpp:6:36: error: ‘AA_EnableHighDpiScaling’ is not a member of ‘Qt’
     QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
                                    ^
make: *** [main.o] Error 1

I'm guessing that perhaps the version of Qt being picked up by qmake or g++ is not the 5.7 version Qt Creator is using, since AA_EnableHighDpiScaling was added in Qt 5.6.

The full generated Makefile includes 99 references to /usr/include/qt5 and 179 references to /usr/lib/x86_64-linux-gnu/qt5. Qt 5.7 is installed in /home/phrogz/Qt5.7.0. Obviously I need to modify something in the qmake command to get this pointing elsewhere.

How can I get this to work? Do I need to somehow remove an older version of qt libraries installed by Ubuntu? Point some configuration to the version of Qt 5.7 that's now installed (by the Qt Installer) in my home directory? Replace existing/old Qt directories with symlinks?

Upvotes: 1

Views: 3477

Answers (1)

Velkan
Velkan

Reputation: 7582

Or you can use CMake:

cmake_minimum_required (VERSION 2.8.11)

project(myproject)

find_package(Qt5 5.7.0 REQUIRED COMPONENTS
    Core
    Quick
    Widgets
)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

add_executable(${PROJECT_NAME}
    main.cpp
)

target_link_libraries(${PROJECT_NAME}
    Qt5::Core
    Qt5::Quick
    Qt5::Widgets
)

Upvotes: 1

Related Questions