i have one problem with the example of Qt site, the message error compile is:
this is error:
error: variable 'QQmlComponent component' has initializer but incomplete type
QQmlComponent component(&engine, QUrl::fromLocalFile("qml/untitled3/main.qml"));
^
My code is similar at this post and with the correction in this post but not work, i am new using qt 5.1... any idea?.
I try add the library
#include <QQmlComponent>
or
#include <QtQml/QQmlContext>
but the message error is same.
the path from my main.qml is correct: qml/untitled3/main.qml
Please help me.
untitled3.pro
# 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
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
main.cpp
#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();
}