我对Qt site的例子有一个问题,消息错误编译是:
这是错误:
error: variable 'QQmlComponent component' has initializer but incomplete type
QQmlComponent component(&engine, QUrl::fromLocalFile("qml/untitled3/main.qml"));
^
我的代码在这个post上是相似的,并且在这篇文章中进行了修正,但没有工作,我是新的使用qt 5.1 ......任何想法?。
我尝试添加库
#include <QQmlComponent>
要么
#include <QtQml/QQmlContext>
但是消息错误是一样的。
我的main.qml的路径是正确的:qml / untitled3 / main.qml
请帮帮我。
# Add more folders to ship with the application, here
folder_01.source = qml/untitled3
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 +=
# The .cpp file which was generated for your project. Feel free to hack it.
SOURCES += main.cpp
# Installation path
# target.path =
# Please do not modify the following two lines. Required for deployment.
include(qtquick2applicationviewer/qtquick2applicationviewer.pri)
qtcAddDeployment()
HEADERS += \
message.h
#ifndef MESSAGE_H
#define MESSAGE_H
#include <QObject>
class Message : public QObject
{
Q_OBJECT
Q_PROPERTY(QString author READ author WRITE setAuthor NOTIFY authorChanged)
public:
void setAuthor(const QString &a) {
if (a != m_author) {
m_author = a;
emit authorChanged();
}
}
QString author() const {
return m_author;
}
signals:
void authorChanged();
private:
QString m_author;
};
#endif
#include <QtGui/QGuiApplication>
#include <QtQml/QQmlContext>
#include <QQmlEngine>
#include <QQmlComponent>
#include "message.h"
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlEngine *engine = new QQmlEngine;
Message msg;
engine->rootContext()->setContextProperty("msg", &msg);
QQmlComponent component(&engine, QUrl::fromLocalFile("qml/untitled3/main.qml"));
component.create();
return app.exec();
}