问题描述
我正在Ubuntu 14.04上安装qt4和qt5(从存储库中)。我以为我可以在使用qt5构建与使用qt4构建之间切换,只需使用
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
但是该程序仍然使用Qt5生成并给出错误,因为它仅支持Qt4。
But the program still builds with Qt5 and gives error because it only supports Qt4.
我检查了qmake版本,安装了qt4-default后,它给出了
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
我正在与CMake合作,以防万一。另外,如果我这样做
I'm building with CMake in case that is useful. Also, if I do
sudo apt-get remove qtbase5-dev
然后最终使用qt4进行构建。
then finally it builds with qt4.
编辑:我没有使用Qt Creator,而是希望使用命令行解决方案
I am not using Qt Creator and would prefer a command-line solution
推荐答案
您需要将其放入CMakeLists.txt:
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})
这篇关于即使已安装qt5,也可以使用qt4强制编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!