C++ Backend with Design Studio | CMakeProject
-
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.
Now, say I want do add my own C++ and QML stuff, how would I proceed?
My ideas were:
1 - in./CMakeLists.txt
, doadd_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 - inScreen01.ui.qml
import my module, by addingimport 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. - Adding Q_OBJECT to the Backend Class asks from a
-
@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