未知类型名称 QML_ELEMENT [英] Unknown type name QML_ELEMENT

查看:195
本文介绍了未知类型名称 QML_ELEMENT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在新的 Qt 5.15.0 中,有一种新的声明方式来注册 C++ 类型以在 QML 中使用.我按照 Qt 帮助(https://doc.qt.io/qt-5/qtqml-cppintegration-definetypes.html#registering-an-instantiable-object-type) 但它给出我出现以下错误:

In the new Qt 5.15.0 there is a new declarative way to register C++ types for usage in QML. I followed the steps given in Qt Help (https://doc.qt.io/qt-5/qtqml-cppintegration-definetypes.html#registering-an-instantiable-object-type) but it givens to me the following error:

/.../randomnumbergenerator.h:10: error: ‘QML_ELEMENT’ does not name a type
     QML_ELEMENT
     ^~~~~~~~~~~

该类的定义暂时是:

#ifndef RANDOMNUMBERGENERATOR_H
#define RANDOMNUMBERGENERATOR_H

#include <QObject>
#include <QRandomGenerator>

class RandomNumberGenerator : public QObject
{
    Q_OBJECT
    QML_ELEMENT
    QML_SINGLETON

public:
    explicit RandomNumberGenerator(QObject *parent = nullptr);

signals:

};

#endif // RANDOMNUMBERGENERATOR_H

我已经在 .pro 文件中添加了以下内容:

I already added to the .pro file the following:

CONFIG += c++11 qmltypes
QML_IMPORT_NAME = SimpleRng
QML_IMPORT_MAJOR_VERSION = 1

推荐答案

正如他们在 Qt 论坛 你必须包含 (或 )

As they point out in the Qt forum you have to include <qml.h> (or <QtQml>)

这篇关于未知类型名称 QML_ELEMENT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆