Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. c++/QML issues with CMake setup generated by QtCreator
QtWS25 Last Chance

c++/QML issues with CMake setup generated by QtCreator

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
8 Posts 3 Posters 629 Views
  • 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.
  • F Offline
    F Offline
    FredJupiter
    wrote on last edited by FredJupiter
    #1

    Hi Everyone,
    I'm currently struggeling with the idea behind the automatic C++/QML registration. I've implemented a simple example C++ object like described here:

    https://doc.qt.io/qt-6.2/qtqml-cppintegration-topic.html

    The generated moc code isn't finding my header file, which is at the same level as the main.cpp.

    Could someone be so kind and point me into the right direction? Do I have to move the C++ class into a special named folder?

    Thanks and Best Fred

    SGaistS 1 Reply Last reply
    0
    • F FredJupiter

      Hi Everyone,
      I'm currently struggeling with the idea behind the automatic C++/QML registration. I've implemented a simple example C++ object like described here:

      https://doc.qt.io/qt-6.2/qtqml-cppintegration-topic.html

      The generated moc code isn't finding my header file, which is at the same level as the main.cpp.

      Could someone be so kind and point me into the right direction? Do I have to move the C++ class into a special named folder?

      Thanks and Best Fred

      SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Are you using qmake or CMake ?
      Can you show your project file content ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      F 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Are you using qmake or CMake ?
        Can you show your project file content ?

        F Offline
        F Offline
        FredJupiter
        wrote on last edited by FredJupiter
        #3

        @SGaist I'm using CMake.

        cmake_minimum_required(VERSION 3.21.1)
        
        option(LINK_INSIGHT "Link Qt Insight Tracker library" ON)
        option(BUILD_QDS_COMPONENTS "Build design studio components" ON)
        
        project(testAppApp LANGUAGES CXX)
        
        set(CMAKE_AUTOMOC ON)
        
        find_package(Qt6 6.2 REQUIRED COMPONENTS Core Gui Qml Quick)
        
        if (Qt6_VERSION VERSION_GREATER_EQUAL 6.3)
            qt_standard_project_setup()
        endif()
        
        qt_add_executable(testAppApp src/main.cpp
            src/theorb.h src/theorb.cpp)
        
        qt_add_resources(testAppApp "configuration"
            PREFIX "/"
            FILES
                qtquickcontrols2.conf
        )
        
        target_link_libraries(testAppApp PRIVATE
            Qt6::Core
            Qt6::Gui
            Qt6::Qml
            Qt6::Quick
        )
        
        if (BUILD_QDS_COMPONENTS)
            include(${CMAKE_CURRENT_SOURCE_DIR}/qmlcomponents)
        endif()
        
        include(${CMAKE_CURRENT_SOURCE_DIR}/qmlmodules)
        include_directories(${CMAKE_SOURCE_DIR}/src)   #added by myself
        
        if (LINK_INSIGHT)
            include(${CMAKE_CURRENT_SOURCE_DIR}/insight)
        endif ()
        
        include(GNUInstallDirs)
        install(TARGETS testAppApp
            BUNDLE DESTINATION .
            LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
            RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
        )
                                                                          
        

        I've added the include ./src by myself. This is working but without it the generated QML type registration code is compaining about the include file:
        e66099e3-6628-4e02-ab6a-621aa07b2764-grafik.png

        SGaistS 1 Reply Last reply
        0
        • F FredJupiter

          @SGaist I'm using CMake.

          cmake_minimum_required(VERSION 3.21.1)
          
          option(LINK_INSIGHT "Link Qt Insight Tracker library" ON)
          option(BUILD_QDS_COMPONENTS "Build design studio components" ON)
          
          project(testAppApp LANGUAGES CXX)
          
          set(CMAKE_AUTOMOC ON)
          
          find_package(Qt6 6.2 REQUIRED COMPONENTS Core Gui Qml Quick)
          
          if (Qt6_VERSION VERSION_GREATER_EQUAL 6.3)
              qt_standard_project_setup()
          endif()
          
          qt_add_executable(testAppApp src/main.cpp
              src/theorb.h src/theorb.cpp)
          
          qt_add_resources(testAppApp "configuration"
              PREFIX "/"
              FILES
                  qtquickcontrols2.conf
          )
          
          target_link_libraries(testAppApp PRIVATE
              Qt6::Core
              Qt6::Gui
              Qt6::Qml
              Qt6::Quick
          )
          
          if (BUILD_QDS_COMPONENTS)
              include(${CMAKE_CURRENT_SOURCE_DIR}/qmlcomponents)
          endif()
          
          include(${CMAKE_CURRENT_SOURCE_DIR}/qmlmodules)
          include_directories(${CMAKE_SOURCE_DIR}/src)   #added by myself
          
          if (LINK_INSIGHT)
              include(${CMAKE_CURRENT_SOURCE_DIR}/insight)
          endif ()
          
          include(GNUInstallDirs)
          install(TARGETS testAppApp
              BUNDLE DESTINATION .
              LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
              RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
          )
                                                                            
          

          I've added the include ./src by myself. This is working but without it the generated QML type registration code is compaining about the include file:
          e66099e3-6628-4e02-ab6a-621aa07b2764-grafik.png

          SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Looks like you are working with Qt Design Studio rather than Qt Creator, aren't you ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          F 1 Reply Last reply
          0
          • SGaistS SGaist

            Looks like you are working with Qt Design Studio rather than Qt Creator, aren't you ?

            F Offline
            F Offline
            FredJupiter
            wrote on last edited by
            #5

            @SGaist 60b74ef6-b0f7-4ec5-b32c-333ed3a0d72d-grafik.png

            I'm using the Qt Creator build on my machine some weeks ago...

            jsulmJ 1 Reply Last reply
            0
            • F FredJupiter

              @SGaist 60b74ef6-b0f7-4ec5-b32c-333ed3a0d72d-grafik.png

              I'm using the Qt Creator build on my machine some weeks ago...

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @FredJupiter Is there a reason why you're using a beta version of Qt creator?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              F 1 Reply Last reply
              0
              • jsulmJ jsulm

                @FredJupiter Is there a reason why you're using a beta version of Qt creator?

                F Offline
                F Offline
                FredJupiter
                wrote on last edited by
                #7

                @jsulm Not really, which branch do you suggest and think is working for sure?

                jsulmJ 1 Reply Last reply
                0
                • F FredJupiter

                  @jsulm Not really, which branch do you suggest and think is working for sure?

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @FredJupiter The current stable for example

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  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