Qt5 -> Qt6 problem: hidden reference to Qt5?
-
I'm migrating from Qt5 to Qt6.7.2.
I have an app "qt-test" successfully built with Qt5. I've replaced references to "Qt5" with "Qt6"> Below is the qt-test CMakeLists.txt :find_package( Qt6 COMPONENTS Gui Widgets Quick REQUIRED) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_AUTOUIC ON) add_executable(qt-test main.cpp ToDoModel.cpp qml.qrc) target_compile_options(qt-test PUBLIC "-Wunused-variable") target_link_libraries(qt-test PRIVATE MBGui Qt6::Core Qt6::Quick mbaux)
But now cmake gives this error:
CMake Error: The INTERFACE_QT_MAJOR_VERSION property of "Qt6::Core" does not agree with the value of QT_MAJOR_VERSION already determined for "qt-test".
How is QT_MAJOR_VERSION already determined for "qt-test"? I've done 'make clean' and removed CMakeCache.txt. I don't see explicit references to Qt5 in my source code. Where else should I look for references to Qt5?
Thanks! -
Please add this to your ``CMakeLists.txt```
message(STATUS "QT_MAJOR_VERSION=${QT_MAJOR_VERSION}")
My guess is, that it outputs "5". In that case,
configure
in an empty build directory and try again. -
@Axel-Spoerl - cmake outputs the message
QT_MAJOR_VERSION=
I also print INTERFACE_QT_MAJOR_VERSION, which is also empty.
I tried rebuilding in an empty build directory, with the same result.
Thanks! -
cmake --trace-expand --trace-redirect=trace.txt
and have a look throughtrace.txt
and see what CMake is doing. -
@cristian-adam - I ran cmake with --trace-expand, but I don't really know how to interpret the results.
One thing I did learn is that my ubuntu 22.04 system contains numerous Qt5 libraries in /usr/lib/ - but I don't dare to remove them as I think that ubuntu may depend on some of them:
$ find /usr/lib -name '*qt5*' /usr/lib/x86_64-linux-gnu/metatypes/qt5core_metatypes.json /usr/lib/x86_64-linux-gnu/metatypes/qt5gui_metatypes.json /usr/lib/x86_64-linux-gnu/metatypes/qt5widgets_metatypes.json /usr/lib/x86_64-linux-gnu/qtchooser/qt5.conf /usr/lib/x86_64-linux-gnu/libqt5keychain.so.1 /usr/lib/x86_64-linux-gnu/libqca-qt5.so.2.3.4 /usr/lib/x86_64-linux-gnu/qt5 /usr/lib/x86_64-linux-gnu/qt5/plugins/designer/libpyqt5.so /usr/lib/x86_64-linux-gnu/libqca-qt5.so.2 /usr/lib/x86_64-linux-gnu/libqt5keychain.so.0.13.2 /usr/lib/x86_64-linux-gnu/qca-qt5 /usr/lib/libqscintilla2_qt5.so.15.0 /usr/lib/libqwt-qt5.so.6.1.4 /usr/lib/libqwt-qt5.so.6 /usr/lib/qt5 /usr/lib/python3/dist-packages/matplotlib/backends/backend_qt5.py /usr/lib/python3/dist-packages/matplotlib/backends/backend_qt5agg.py /usr/lib/python3/dist-packages/matplotlib/backends/__pycache__/backend_qt5.cpython-310.pyc /usr/lib/python3/dist-packages/matplotlib/backends/__pycache__/backend_qt5cairo.cpython-310.pyc /usr/lib/python3/dist-packages/matplotlib/backends/__pycache__/backend_qt5agg.cpython-310.pyc /usr/lib/python3/dist-packages/matplotlib/backends/backend_qt5cairo.py /usr/lib/libqscintilla2_qt5.so.15 /usr/lib/libqscintilla2_qt5.so.15.0.0 /usr/lib/libqwt-qt5.so.6.1
Thanks!
-
-
It's all about
CMAKE_PREFIX_PATH
and alsoCMAKE_IGNORE_PREFIX_PATH
. This is how you control where CMake would look for packages.You can add
-D CMAKE_IGNORE_PREFIX_PATH=/usr/lib
or-D CMAKE_IGNORE_PREFIX_PATH=/usr/lib/x86_64-linux-gnu
to tell CMake to ignore looking into those directories.In the trace log you can see what CMake is trying. If that's too much, you can look in the
CMakeCache.txt
to see what package found has an out of place directory.Compiling on Linux where you can have system packages that can interfere, is more error prone.
-