14

使用 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

主文件

#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();
}
4

1 回答 1

34

qmlRegisterTypeQtQml. 您必须包括QtQml

#include <QtQml>
于 2013-10-30T12:09:45.577 回答