QML项目给出了不可用的类型错误'使用CMAKE配置(QT 6.2)
我已经使用QT6.2-MINGW-64BIT创建了一个测试项目,并且选择了CMAKE。 项目结构显示在图片中。彼此仅嵌入3个测试文件,并且在main.qml中使用了第一个测试文件(test1.qml)。
现在,当我想启动程序时,test2不可用时给出了一个奇怪的错误。我尝试了不同的方案,并检查了CMAKE中的所有步骤,但没有成功。
这是主要的。qml:
import QtQuick
import untitled35
Window {
width: 640
height: 480
visible: true
title: qsTr("Hello World")
property Test1 _example: Test1 {}
}
这是cmakefile:
cmake_minimum_required(VERSION 3.16)
project(untitled35 VERSION 0.1 LANGUAGES CXX)
set(CMAKE_AUTOMOC ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt6 6.2 COMPONENTS Quick REQUIRED)
qt_add_executable(appuntitled35
main.cpp
)
qt_add_qml_module(appuntitled35
URI "untitled35"
VERSION 1.0
QML_FILES
main.qml
core/Test1.qml
core/Test2.qml
core/components/Test3.qml
)
set_target_properties(appuntitled35 PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
)
target_compile_definitions(appuntitled35
PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
target_link_libraries(appuntitled35
PRIVATE Qt6::Quick)
I have created a test project with Qt6.2-MinGW-64bit and I choose CMake.
The project structure is shown in the picture. Only 3 test files are embedded in each other and the first test file (test1.qml) is used in main.qml.
Now when I want to start the program it gives a weird error that the Test2 is unavailable. I have tried different scenarios and have checked all steps in CMake but with no success.
Here is the main.qml:
import QtQuick
import untitled35
Window {
width: 640
height: 480
visible: true
title: qsTr("Hello World")
property Test1 _example: Test1 {}
}
Here is the CMakeFile:
cmake_minimum_required(VERSION 3.16)
project(untitled35 VERSION 0.1 LANGUAGES CXX)
set(CMAKE_AUTOMOC ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt6 6.2 COMPONENTS Quick REQUIRED)
qt_add_executable(appuntitled35
main.cpp
)
qt_add_qml_module(appuntitled35
URI "untitled35"
VERSION 1.0
QML_FILES
main.qml
core/Test1.qml
core/Test2.qml
core/components/Test3.qml
)
set_target_properties(appuntitled35 PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
)
target_compile_definitions(appuntitled35
PRIVATE lt;lt;OR:lt;CONFIG:Debug>,lt;CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
target_link_libraries(appuntitled35
PRIVATE Qt6::Quick)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的问题是Test2有错误。
QTObject
没有将您创建的test3对象放置在其内部的默认属性。item
将子元素放在其子女中,但是qtobject
没有做出假设。尝试将QTObject
更改为item
。 documentation =“ https://doc.qt.io/qt-5/qml-qtquick-item.html#data-prop” rel =“ nofollow noreferrer”>文档属性是其默认值。Your issue is that Test2 has an error.
QtObject
does not have a default property to put the Test3 object you created inside of it.Item
places child elements in its children, butQtObject
does not make that assumption. try changing theQtObject
toItem
. Documentation for default properties and Documentation forItem
data property which is its default.