QML项目给出了不可用的类型错误'使用CMAKE配置(QT 6.2)

发布于 2025-01-26 08:39:48 字数 1507 浏览 1 评论 0原文

我已经使用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.

Project structure

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心如荒岛 2025-02-02 08:39:48

您的问题是Test2有错误。 QTObject没有将您创建的test3对象放置在其内部的默认属性。 item将子元素放在其子女中,但是qtobject没有做出假设。尝试将QTObject更改为itemdocumentation =“ 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, but QtObject does not make that assumption. try changing the QtObject to Item. Documentation for default properties and Documentation for Item data property which is its default.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文