Qt Creator / Designer custom widget clock example desktop failing to build
-
wrote on 7 Jun 2024, 12:09 last edited by
I have built from the git sources both Qt6.7.1 and QtCreator 13.0.2 plus built the documentation so I could also get to all the examples.
I have successfully built the dice example hence know everything compiles ok but am now struggling with the setup required for a custom widget to be used
I may be approaching this wrong and so looking for some help on getting it working please.
So far I have:
- Built the analog clock 'custom widget plugin' example in /myQt671/examples/designer/customwidgetplugin/ directory.
- Configured cmake to install to my plugins directory so this /myQt671/plugins/designer/libcustomwidgetplugin.so
- Started a new Creator project (Application, Qt Widgets Application) named cdgClockDesktop, opened the mainwindow.ui and dragged a clock instance onto it which is showing the clock face ticking away.
- Tried to compile and build the solution which initially gave an error that the header file could not be found but fixed that by putting an absolute link to it in the customwidgetplugin.cpp include file section.
Now I am stuck as I am getting a linking error when trying to build using the plugin saying that `AnalogClock::AnalogClock(QWidget*)' is an undefined reference.
I'm assuming that is because I haven't got anything that is telling the linker to include the plugin library where the actual clock functions exist.
I'm using CMake and all the examples i have found are older using QMake so not helped I'm assuming I need something in the CMakeLists.txt to reference out to the libcustomwidgetplugin.so when linking but can't work it out or maybe this approach is wrong and there is a better way ?
-
I have built from the git sources both Qt6.7.1 and QtCreator 13.0.2 plus built the documentation so I could also get to all the examples.
I have successfully built the dice example hence know everything compiles ok but am now struggling with the setup required for a custom widget to be used
I may be approaching this wrong and so looking for some help on getting it working please.
So far I have:
- Built the analog clock 'custom widget plugin' example in /myQt671/examples/designer/customwidgetplugin/ directory.
- Configured cmake to install to my plugins directory so this /myQt671/plugins/designer/libcustomwidgetplugin.so
- Started a new Creator project (Application, Qt Widgets Application) named cdgClockDesktop, opened the mainwindow.ui and dragged a clock instance onto it which is showing the clock face ticking away.
- Tried to compile and build the solution which initially gave an error that the header file could not be found but fixed that by putting an absolute link to it in the customwidgetplugin.cpp include file section.
Now I am stuck as I am getting a linking error when trying to build using the plugin saying that `AnalogClock::AnalogClock(QWidget*)' is an undefined reference.
I'm assuming that is because I haven't got anything that is telling the linker to include the plugin library where the actual clock functions exist.
I'm using CMake and all the examples i have found are older using QMake so not helped I'm assuming I need something in the CMakeLists.txt to reference out to the libcustomwidgetplugin.so when linking but can't work it out or maybe this approach is wrong and there is a better way ?
wrote on 7 Jun 2024, 12:55 last edited by@CG-123 said in Qt Creator / Designer custom widget clock example desktop failing to build:
Tried to compile and build the solution which initially gave an error that the header file could not be found but fixed that by putting an absolute link to it in the customwidgetplugin.cpp include file section.
How does your CMake file look like?
Are you following these steps here?
-
@CG-123 said in Qt Creator / Designer custom widget clock example desktop failing to build:
Tried to compile and build the solution which initially gave an error that the header file could not be found but fixed that by putting an absolute link to it in the customwidgetplugin.cpp include file section.
How does your CMake file look like?
Are you following these steps here?
wrote on 7 Jun 2024, 13:30 last edited by@Pl45m4 Yes I have followed the steps in the example html and the clock plugin itself is working great.
My issue is how to build a proejct using it.
To help try and prove where my issue is I have just created a project using qmake and in the qmake .pro file added the external library through the additional lines
unix:!macx: LIBS += -L$$PWD/../../myQt671/plugins/designer/ -lcustomwidgetplugin INCLUDEPATH += $$PWD/../../myQt671/plugins/designer DEPENDPATH += $$PWD/../../myQt671/plugins/designer
and that works perfectly so it is something in my CMake setup.
My CMakeLists.txt file is:
cmake_minimum_required(VERSION 3.5) project(cdgClockDesktop VERSION 0.1 LANGUAGES CXX) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets) set(PROJECT_SOURCES main.cpp mainwindow.cpp mainwindow.h mainwindow.ui ) qt_add_executable(cdgClockDesktop MANUAL_FINALIZATION ${PROJECT_SOURCES}) target_link_libraries(cdgClockDesktop PRIVATE Qt${QT_VERSION_MAJOR}::Widgets ) # Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1. # If you are developing for iOS or macOS you should consider setting an # explicit, fixed bundle identifier manually though. if(${QT_VERSION} VERSION_LESS 6.1.0) set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.cdgClockDesktop) endif() set_target_properties(cdgClockDesktop PROPERTIES ${BUNDLE_ID_OPTION} MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} MACOSX_BUNDLE TRUE WIN32_EXECUTABLE TRUE ) include(GNUInstallDirs) install(TARGETS cdgClockDesktop BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) if(QT_VERSION_MAJOR EQUAL 6) qt_finalize_executable(cdgClockDesktop) endif()
I don't know how to include the plugin directory and configure Cmake so it is succesfully linked to in the way QMake specifies it.
-
@Pl45m4 Yes I have followed the steps in the example html and the clock plugin itself is working great.
My issue is how to build a proejct using it.
To help try and prove where my issue is I have just created a project using qmake and in the qmake .pro file added the external library through the additional lines
unix:!macx: LIBS += -L$$PWD/../../myQt671/plugins/designer/ -lcustomwidgetplugin INCLUDEPATH += $$PWD/../../myQt671/plugins/designer DEPENDPATH += $$PWD/../../myQt671/plugins/designer
and that works perfectly so it is something in my CMake setup.
My CMakeLists.txt file is:
cmake_minimum_required(VERSION 3.5) project(cdgClockDesktop VERSION 0.1 LANGUAGES CXX) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets) set(PROJECT_SOURCES main.cpp mainwindow.cpp mainwindow.h mainwindow.ui ) qt_add_executable(cdgClockDesktop MANUAL_FINALIZATION ${PROJECT_SOURCES}) target_link_libraries(cdgClockDesktop PRIVATE Qt${QT_VERSION_MAJOR}::Widgets ) # Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1. # If you are developing for iOS or macOS you should consider setting an # explicit, fixed bundle identifier manually though. if(${QT_VERSION} VERSION_LESS 6.1.0) set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.cdgClockDesktop) endif() set_target_properties(cdgClockDesktop PROPERTIES ${BUNDLE_ID_OPTION} MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} MACOSX_BUNDLE TRUE WIN32_EXECUTABLE TRUE ) include(GNUInstallDirs) install(TARGETS cdgClockDesktop BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) if(QT_VERSION_MAJOR EQUAL 6) qt_finalize_executable(cdgClockDesktop) endif()
I don't know how to include the plugin directory and configure Cmake so it is succesfully linked to in the way QMake specifies it.
wrote on 7 Jun 2024, 17:01 last edited by@CG-123 So getting there if anyone else has this problem trying to use CMake.
In my CMakeLists.txt I have found by using the find_library command and ensuring that the directory for the plugins is in my PATH that I can then use the CLOCK_WIDGET result in the target link library section.
find_library(CLOCK_WIDGET customwidgetplugin)
and
target_link_libraries(cdgClockDesktop PRIVATE Qt${QT_VERSION_MAJOR}::Widgets "${CLOCK_WIDGET}")
1/4