Unknown type name QML_ELEMENT

别说谁变了你拦得住时间么 提交于 2020-06-28 07:59:22

问题


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
     ^~~~~~~~~~~

The class's definition is, for the moment:

#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

EDIT: I already added to the .pro file the following:

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

回答1:


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



来源:https://stackoverflow.com/questions/62251521/unknown-type-name-qml-element

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!