Reputation: 463
My Ubuntu computer installed both qt4 and qt5 because of the compatibility with some libs. Currently, I want to rebuild opencv with qt4 (for highgui). But cmake always uses qt5 (default version). I edited CMakeLists.txt
find_package(Qt4 COMPONENTS QTCORE QTGUI)
// I remove HAVE_QT5 variable
if(HAVE_QT)
status(" QT 4.x:" HAVE_QT THEN "YES (ver ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH} ${QT_EDITION})" ELSE NO)
status(" QT OpenGL support:" HAVE_QT_OPENGL THEN "YES (${QT_QTOPENGL_LIBRARY})" ELSE NO)
else()
...................
After I rebuilt opencv, I check dependencies using ldd libopencv_highgui.so
libQt5Core.so.5 => /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 (0x00007f4e5245a000) libQt5Gui.so.5 => /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5 (0x00007f4e51e0d000) libQt5Widgets.so.5 => /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5 (0x00007f4e515e4000) libQt5Test.so.5 => /usr/lib/x86_64-linux-gnu/libQt5Test.so.5 (0x00007f4e513bb000) libQt5OpenGL.so.5 => /usr/lib/x86_64-linux-gnu/libQt5OpenGL.so.5 (0x00007f4e51157000)
Highgui still link to Qt5. Can anybody help me ? Thanks !
Upvotes: 0
Views: 1060
Reputation: 52367
To work with both Qt versions, use the *FOUND
variables.
# QtWidgets 5
find_package(Qt5Widgets)
if(Qt5Widgets_FOUND)
set(QT5_FOUND TRUE)
set(QT5_INCLUDE_DIRS "${Qt5Widgets_INCLUDE_DIRS}")
set(QT5_LIBRARIES "${Qt5Widgets_LIBRARIES}")
# QtGui 4
find_package(Qt4 ${MINIMUM_REQUIRED_QT4_VERSION} COMPONENTS QtCore QtGui)
if(QT_FOUND)
set(QT4_FOUND TRUE)
set(QT4_INCLUDE_DIRS "${QT_INCLUDE_DIR};${QT_QTCORE_INCLUDE_DIR};${QT_QTGUI_INCLUDE_DIR}")
set(QT4_LIBRARIES "${QT_QTCORE_LIBRARY};${QT_QTGUI_LIBRARY}")
As you can see, now you have both versions available and can use the respective include/library variables.
Upvotes: 0