错误:未在此范围内声明'qmlRegisterType'

时间:2013-10-30 12:03:52

标签: qt qml qt-quick

使用Qt 5和QtQuick 2.0

的.pro

# Add more folders to ship with the application, here
folder_01.source = qml/untitled
folder_01.target = qml
DEPLOYMENTFOLDERS = folder_01

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

# If your application uses the Qt Mobility libraries, uncomment the following
# lines and add the respective components to the MOBILITY variable.
# CONFIG += mobility
# MOBILITY +=

#CONFIG += qt plugin
#QT += qml quick

# The .cpp file which was generated for your project. Feel free to hack it.
SOURCES += main.cpp \
    ../DummyClass.cpp \
    ../aa.cpp

# Installation path
# target.path =

# Please do not modify the following two lines. Required for deployment.
include(qtquick2applicationviewer/qtquick2applicationviewer.pri)
qtcAddDeployment()

HEADERS += \
    ../DummyClass.h \
    ../aa.h

的main.cpp

#include <QtGui/QGuiApplication>
#include "qtquick2applicationviewer.h"
#include "/home/***/qmllistproperties/DummyClass.h"

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    const char* ocuui = "OCUUI"; // @uri OCUUI

    qmlRegisterType <DummyClass> (ocuui, 1, 0, "DummyClass");

    QtQuick2ApplicationViewer viewer;
    viewer.setMainQmlFile(QStringLiteral("qml/untitled/main.qml"));
    viewer.showExpanded();

    return app.exec();
}

1 个答案:

答案 0 :(得分:30)

qmlRegisterType位于QtQml。您必须包含QtQml

#include <QtQml>