Of course I have documentation:
https://doc.qt.io/qt-5/qtqml-cppintegration-topic.html
Unfortunately, it is not clearly enought for me:
CONFIG = qmltypes
QML_IMPORT_NAME = io.qt.examples.backend
QML_IMPORT_MAJOR_VERSION = 1
There is written: "Add the following lines to your project file:"
What does the "project file" mean? I guess it is .pro file. Why this file project does not existing on my Cmake list? Do I have to create this file on my own? How to do this?
I was searching .pro file, but I cannot find it in my project. I couldn't find, where can I create such file. I also have tried to paste code above into cMake list - but it is not that.
I have also watched a few tutorials, where is shown how to integrate QML and C , and I am confused cause it looks like there are a few opportunities to solve this. It seems to me, some people skipping such things as adding .h and .cpp files to cMake list.
I am also expecting if you explain me please, which way for connecting Qml and C I have to choose. Of course if it is not that way in link I attached above. I need universal solution, most common for most of Qt Quick applications.
CodePudding user response:
If you use CMake you should use qt_add_qml_module()
. Here is the content of the CMakeLists.txt which I've used together with the backend.cpp/.h from your link above.
To include that in QML use import untitledStackoverflow
.
cmake_minimum_required(VERSION 3.16)
project(untitledStackoverflow VERSION 0.1 LANGUAGES CXX)
set(CMAKE_AUTOMOC ON)
find_package(Qt6 6.2 COMPONENTS Quick REQUIRED)
qt_add_executable(appuntitledStackoverflow
backend.cpp backend.h
main.cpp
)
qt_add_qml_module(appuntitledStackoverflow
URI untitledStackoverflow
VERSION 1.0
QML_FILES main.qml
)
target_link_libraries(appuntitledStackoverflow
PRIVATE Qt6::Quick)