I have simple testing code as follow:
test.hpp
#pragma once
#include <QQmlEngine>
class test_gadget {
Q_GADGET
QML_ELEMENT
Q_PROPERTY(int test MEMBER test)
public:
int test;
};
class test_object : public QObject {
Q_OBJECT
QML_ELEMENT
public:
test_object(const test_gadget&);
private:
test_gadget gadget;
};
test.cpp
#include <test.hpp>
test_object::test_object(const test_gadget& other) {
this->gadget = other;
}
main.cpp
#include <QQmlContext>
#include <test.hpp>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
const QUrl url(u"qrc:/testqt/Main.qml"_qs);
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
&app, []() { QCoreApplication::exit(-1); },
Qt::QueuedConnection);
test_gadget gadget;
test_object test_obj(gadget);
engine.rootContext()->setContextProperty("test_obj", &test_obj);
engine.load(url);
return app.exec();
}
However when I try to compile, there were errors:
[ 5%] Built target apptestqt_qmlimportscan
[ 10%] Built target apptestqt_tooling
[ 15%] Automatic MOC and UIC for target apptestqt
[ 20%] Built target apptestqt_autogen
[ 25%] Running AUTOMOC file extraction for target apptestqt
[ 25%] Built target apptestqt_automoc_json_extraction
[ 30%] Automatic QML type registration for target apptestqt
Error 5 while parsing C:/Users/USER/source/repos/build-testqt-Desktop_Qt_6_6_0_MinGW_64_bit-Debug/meta_types/qt6apptestqt_debug_metatypes.json: illegal value
mingw32-make.exe[2]: *** [CMakeFilesapptestqt.dirbuild.make:88: apptestqt_qmltyperegistrations.cpp] Error 1
mingw32-make.exe[1]: *** [CMakeFilesMakefile2:97: CMakeFiles/apptestqt.dir/all] Error 2
mingw32-make.exe: *** [Makefile:135: all] Error 2
13:22:22: The process "C:QtToolsCMake_64bincmake.exe" exited with code 2.
Error while building/deploying project testqt (kit: Desktop Qt 6.6.0 MinGW 64-bit)
When executing step "Build"
Note: build-testqt-Desktop_Qt_6_6_0_MinGW_64_bit-Debugmeta_typesqt6apptestqt_debug_metatypes.json
is empty
How should I fix this?
Qt version: 6.6.0