My OS is Ubuntu. I would like to change from QT4 to QT5 in my project. The native package though is 4.x version in Ubuntu right now.
I have downloaded the Linux installer from QT homepage and installed QT5.4 under /opt/Qt/5.4/
This path is not found by
find_package (Qt5 REQUIRED)
I tried adding
set(CMAKE_MODULE_PATH "/opt/QT/5.4;${CMAKE_MODULE_PATH}")
to my CMAKELIST.txt
but that does not help.
Where do I have to link, or am I using the wrong syntax?
Some edits after hint with calling:
cmake -DCMAKE_PREFIX_PATH=/opt/QT/5.4/gcc_64/ ../src/
I also have deleted the CMAKE_MODULE_PATH variable. I still get the same error:
CMake Error at CMakeLists.txt:3 (find_package):
Found package configuration file:
/usr/lib/x86_64-linux-gnu/cmake/Qt5/Qt5Config.cmake
but it set Qt5_FOUND to FALSE so package "Qt5" is considered to be NOT
FOUND. Reason given by package:
The Qt5 package requires at least one component
I dont know why this is happening after reading https://blogs.kde.org/2008/12/12/how-get-cmake-find-what-you-want-it . There it is stated, that the path will be searched before the default search directories. The path I used seems to be right now:
/opt/QT/5.4/gcc_64/
Adding subfolder gcc_64 must be right, as this subfolder has "lib", "include" ect as subfolders.
I remeber that I have called also
sudo apt-get install QT5-default
some time ago. This did not help, I needed the installer from QT. Although I removed qt5-default again to prevent cmake from finding the wrong package configuration file, the same error appears.
See discussion below, moved to here: Cmake and QT5 - Include only takes one argument
You have to use the variable CMAKE_PREFIX_PATH
, i.e. invoke
cmake -DCMAKE_PREFIX_PATH=/opt/QT/5.4 <path_to_source>
at the root of your build tree. Then you can use find_package(Qt5 ...)
etc. See also the Qt5 cmake docs.
Rough distinction within you focus:
CMAKE_MODULE_PATH
is for "general" inclusion of files and "FindXXX.cmake" files in find_package(... MODULE)
.CMAKE_PREFIX_PATH
has a special meaning in the context of find_package(... CONFIG)
.this is a new error and thus should require a new question. if you had that error before you'd have already found the Qt5 config.cmake file :-)
anyways, as the error tells you
The Qt5 package requires at least one component
you need to specify a component of the Qt5 package. As the cmake docs say, you need to use the find_package(Qt5 REQUIRED COMPONENTS Widgets Core ...) interface so that cmake (better: the logic of Qt5 FindQt5.cmake) knows what to look for. that will give you the targets Qt5::Widgets
etc to use/link against.
i dont know if the syntax find_package(Qt5Widgets REQUIRED)
works, could be equivalent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With