Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. C++ Backend with Design Studio | CMakeProject
QtWS25 Last Chance

C++ Backend with Design Studio | CMakeProject

Scheduled Pinned Locked Moved Unsolved Installation and Deployment
designstudiocmakec++qt6.5qtquick
3 Posts 3 Posters 1.2k 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.
  • KelvK Offline
    KelvK Offline
    Kelv
    wrote on last edited by Kelv
    #1

    Hi All.
    So, I need/want to use C++ for some of my backend and although I have read at least 95% of everything on extending QML with C++ Plugins, I can't understand how I should do it, because the tutorials either don't relate to CMake, Design Studio, use no-longer supported stuff or has a structure different from what someone would use and since they use structures completely different from what one would use, I couldn't do the knowledge transfer. I followed the timer example, CityUI, pie charts, etc. and still.
    Anyways...
    So, I created this project on Qt Creator [I'm using its version 6.5, and the version 4.0, Enterprise, of the Design Studio] and got this structure.
    qt.png
    Now, say I want do add my own C++ and QML stuff, how would I proceed?
    My ideas were:
    1 - in ./CMakeLists.txt , do add_subdirectory(backend)
    2 - design the C++ backend module [class, functions, etc.]
    3 - create a qmldir saying, I don't know, module Backend and(new line) plugin Backend maybe?
    4 - in ./backend/CMakeLists.txt file for my C++ modules|partition units write:

    find_package(Qt6 REQUIRED COMPONENTS <...>)
    qt_add_library(Backend STATIC)
    qt_add_qml_module(backendmodule
        URI Backend
        VERSION 1.0
        SOURCES
            backend.cpp
            backend-datamanagement.cppm
            backend-fileio.cppm
        RESOURCE_PREFIX "/"
    )
    target_link_libraries(backendmodule PUBLIC <...>)
    ...
    # btw: good question: how should I write the CMake install directives, so that the main app can find this plugin and statically link to it?
    

    PS: don't mind the files; this is just to have somethis as example.
    5 - in the .qmlproject file, add "." to the import paths
    6 - in Screen01.ui.qml import my module, by adding import Backend

    I must be missing something, because I can't find the module, so, I need help. I must be forgetting something related to a plugin registration, somehow. Or maybe forget a target linking somewhere? So, where am I messing up?

    Regarding the errors I am having:

    • Adding Q_OBJECT to the Backend Class asks from a #include backend.moc, which can't be found. By removing this macro from the class, the error goes away, but it still doesn't work.
    • Compiler says that Screen01 is not available; that Backend isn't a type. Maybe ./src/main.cpp should just point to Screen01.ui.qml as a QuickView? I don't know.
    • I have also tried the deriving from QQmlEngineExtensionPlugin, but in the end I can't figure out how to tell the MOC to find the module, as the example I followed doesn't relate to the Design Studio Folder structure and I am too stupid :/
    • Upon building, it says that Screen01 isn't available or that Backend isn't installed, etc.

    I appreciate any help.
    Thank you.

    R 1 Reply Last reply
    0
    • KelvK Kelv

      Hi All.
      So, I need/want to use C++ for some of my backend and although I have read at least 95% of everything on extending QML with C++ Plugins, I can't understand how I should do it, because the tutorials either don't relate to CMake, Design Studio, use no-longer supported stuff or has a structure different from what someone would use and since they use structures completely different from what one would use, I couldn't do the knowledge transfer. I followed the timer example, CityUI, pie charts, etc. and still.
      Anyways...
      So, I created this project on Qt Creator [I'm using its version 6.5, and the version 4.0, Enterprise, of the Design Studio] and got this structure.
      qt.png
      Now, say I want do add my own C++ and QML stuff, how would I proceed?
      My ideas were:
      1 - in ./CMakeLists.txt , do add_subdirectory(backend)
      2 - design the C++ backend module [class, functions, etc.]
      3 - create a qmldir saying, I don't know, module Backend and(new line) plugin Backend maybe?
      4 - in ./backend/CMakeLists.txt file for my C++ modules|partition units write:

      find_package(Qt6 REQUIRED COMPONENTS <...>)
      qt_add_library(Backend STATIC)
      qt_add_qml_module(backendmodule
          URI Backend
          VERSION 1.0
          SOURCES
              backend.cpp
              backend-datamanagement.cppm
              backend-fileio.cppm
          RESOURCE_PREFIX "/"
      )
      target_link_libraries(backendmodule PUBLIC <...>)
      ...
      # btw: good question: how should I write the CMake install directives, so that the main app can find this plugin and statically link to it?
      

      PS: don't mind the files; this is just to have somethis as example.
      5 - in the .qmlproject file, add "." to the import paths
      6 - in Screen01.ui.qml import my module, by adding import Backend

      I must be missing something, because I can't find the module, so, I need help. I must be forgetting something related to a plugin registration, somehow. Or maybe forget a target linking somewhere? So, where am I messing up?

      Regarding the errors I am having:

      • Adding Q_OBJECT to the Backend Class asks from a #include backend.moc, which can't be found. By removing this macro from the class, the error goes away, but it still doesn't work.
      • Compiler says that Screen01 is not available; that Backend isn't a type. Maybe ./src/main.cpp should just point to Screen01.ui.qml as a QuickView? I don't know.
      • I have also tried the deriving from QQmlEngineExtensionPlugin, but in the end I can't figure out how to tell the MOC to find the module, as the example I followed doesn't relate to the Design Studio Folder structure and I am too stupid :/
      • Upon building, it says that Screen01 isn't available or that Backend isn't installed, etc.

      I appreciate any help.
      Thank you.

      R Offline
      R Offline
      Raphael_PF
      wrote on last edited by
      #2

      @Kelv Hi there, have you found any solution?
      I am facing a similar problem:

      • Trying to work on project in DS and Creator simultanously (DS: ONLY Qml/GUI, Creator: ONLY C++)
      • Integrating C++ backend in QML should be quite easy according to Qt-Docs, but I assume that's not valid for a project worked on with DS!?
      • Spent days on reading and trying to find a tutorial video but nothing fits or works
      1 Reply Last reply
      0
      • B Offline
        B Offline
        BVladimir
        wrote on last edited by
        #3

        It's the same with me...

        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