Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt Creator / Designer custom widget clock example desktop failing to build
Forum Updated to NodeBB v4.3 + New Features

Qt Creator / Designer custom widget clock example desktop failing to build

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 267 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CG-123
    wrote on last edited by
    #1

    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:

    1. Built the analog clock 'custom widget plugin' example in /myQt671/examples/designer/customwidgetplugin/ directory.
    2. Configured cmake to install to my plugins directory so this /myQt671/plugins/designer/libcustomwidgetplugin.so
    3. 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.
    4. 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 ?

    Pl45m4P 1 Reply Last reply
    0
    • C CG-123

      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:

      1. Built the analog clock 'custom widget plugin' example in /myQt671/examples/designer/customwidgetplugin/ directory.
      2. Configured cmake to install to my plugins directory so this /myQt671/plugins/designer/libcustomwidgetplugin.so
      3. 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.
      4. 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 ?

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by
      #2

      @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?

      • https://doc.qt.io/qt-6/qtdesigner-customwidgetplugin-example.html

      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      C 1 Reply Last reply
      0
      • Pl45m4P Pl45m4

        @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?

        • https://doc.qt.io/qt-6/qtdesigner-customwidgetplugin-example.html
        C Offline
        C Offline
        CG-123
        wrote on last edited by
        #3

        @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.

        C 1 Reply Last reply
        0
        • C CG-123

          @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.

          C Offline
          C Offline
          CG-123
          wrote on last edited by
          #4

          @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 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved