Мой файл CMake выглядит так:
Код: Выделить всё
cmake_minimum_required(VERSION 3.16)
project(testqt VERSION 0.1 LANGUAGES CXX)
set(CMAKE_AUTOMOC ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt6 6.4 REQUIRED COMPONENTS Quick)
qt_standard_project_setup()
qt_add_executable(apptestqt
main.cpp test.cpp test.hpp
)
qt_add_qml_module(apptestqt
URI testqt
VERSION 1.0
QML_FILES Main.qml
)
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
# If you are developing for iOS or macOS you should consider setting an
# explicit, fixed bundle identifier manually though.
set_target_properties(apptestqt PROPERTIES
# MACOSX_BUNDLE_GUI_IDENTIFIER com.example.apptestqt
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
)
target_link_libraries(apptestqt
PRIVATE Qt6::Quick
)
include(GNUInstallDirs)
install(TARGETS apptestqt
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
У меня есть простой код тестирования:
Код: Выделить всё
test.hppКод: Выделить всё
#pragma once
#include
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_object::test_object(const test_gadget& other) {
this->gadget = other;
}
Код: Выделить всё
main.cppКод: Выделить всё
#include
#include
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();
}
Код: Выделить всё
[ 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]: *** [CMakeFiles\apptestqt.dir\build.make:88: apptestqt_qmltyperegistrations.cpp] Error 1
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:97: CMakeFiles/apptestqt.dir/all] Error 2
mingw32-make.exe: *** [Makefile:135: all] Error 2
13:22:22: The process "C:\Qt\Tools\CMake_64\bin\cmake.exe" exited with code 2.
Error while building/deploying project testqt (kit: Desktop Qt 6.6.0 MinGW 64-bit)
When executing step "Build"
Как мне это исправить?
Версия Qt: 6.6.0
Подробнее здесь: https://stackoverflow.com/questions/787 ... egal-value
Мобильная версия