gpt4 book ai didi

c++ - 即使直接从官方示例复制,也找不到未知类型名称 QML_ELEMENT 和 QML 模块

转载 作者:行者123 更新时间:2023-12-02 10:01:03 33 4
gpt4 key购买 nike

当我想运行 this集成 QML 和 C++ 的示例我得到一个错误(在 backend.h 中)QML_ELEMENT不是定义的类型。我知道有人问过类似的问题here已经,但是因为我从官方示例中复制粘贴,所以我做了 #include <qqml.h> .这意味着我的错误原因必须是不同的。
另外导入io.qt.examples.backend 1.0给我一个错误,找不到这个 QML 模块。我使用 Qt 5.9 和 Qt Quick Application。

我的backend.cpp、backend.h和main.qml的内容都是从例子里复制粘贴过来的,就不转贴了。我的项目文件只是默认文件,添加了示例:

QT += quick

CONFIG += c++11 qmltypes

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Refer to the documentation for the
# deprecated API to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
backend.cpp \
main.cpp

RESOURCES += qml.qrc

QML_IMPORT_NAME = io.qt.examples.backend
QML_IMPORT_MAJOR_VERSION = 1

# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =

# Additional import path used to resolve QML modules just for Qt Quick Designer
QML_DESIGNER_IMPORT_PATH =

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

HEADERS += \
backend.h

最佳答案

QML_ELEMENT 从 Qt >= 5.15 开始可用,因为您使用的是 Qt 5.9,那么您必须使用 qmlRegisterType<BackEnd>("io.qt.examples.backend", 1, 0, "BackEnd");正如 Qt 5.9 docs 所指出的那样

关于c++ - 即使直接从官方示例复制,也找不到未知类型名称 QML_ELEMENT 和 QML 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62545830/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com