[Solved] Having trouble using QDeclarativeView
-
I'm trying to get a QML file to run from my C++ program. I looked on the Nokia website, and they have tips posted on how to do it. I got the following code directly from the Nokia website: http://get.qt.nokia.com/training/QtQuickforCppDevelopers/slides/qml-cpp-integration.pdf
@
#include <QApplication>
#include <QDeclarativeView>
#include <QUrl>int main(int argc, char *argv[])
{
QApplication app(argc, argv);QDeclarativeView view; view.setSource(QUrl("qrc:files/animation.qml")); view.show(); return app.exec();
}
@This seems pretty easy and straightforward, right? I put this in Qt Creator, and I get an error when I try to build: QDeclarativeView: No such file or directory. This is the first among 4 errors.
The closest library I could find is <QtDeclarative/QDeclarativeView>, but when I include this, it doesn't work either. Why doesn't code work that's right on the Nokia website? What am I doing wrong here?
-
You will have to add
@
QT += declarative
@
to your .pro file. This has to be done for every Qt module you are going to use besides core (which is set automatically). Others are for example gui, network, xml. -
That wasn't hard at all. Thanks for the info. My pro file already had QT += core. Do I add a "" to the end of this line and put declarative on the next line, or do I even need core?
-
You do need core.
You can do:
@
QT += core declarative
@
or
@
QT += core
declarative
@
or
@
QT += core
QT += declarative
@They're all equivalent.
-
Don't forget you'll need that qml file properly referenced in the resources file (hence the qrc:/) with appropriate path and/or prefix..