Force compilation with qt4 even if qt5 is installe

2019-08-04 12:01发布

问题:

I'm on Ubuntu 14.04 and have both qt4 and qt5 installed (from the repositories). I thought I could switch between building with qt5 to building with qt4 simply with

sudo apt-get install qt4-default

But the program still builds with Qt5 and gives error because it only supports Qt4.

I checked the qmake version and after qt4-default is installed it gives

$ qmake --version
QMake version 2.01a
Using Qt version 4.8.6 in /usr/lib/x86_64-linux-gnu

I'm building with CMake in case that is useful. Also, if I do

sudo apt-get remove qtbase5-dev

then finally it builds with qt4.

EDIT: I am not using Qt Creator and would prefer a command-line solution

回答1:

You would need to put this into your CMakeLists.txt:

find_package(Qt4 REQUIRED)
... 
include_directories(${QT_INCLUDES})
target_link_libraries(main ${QT_QTCORE_LIBRARY})