3
votes

I'm starting an application project using Qt 5.5 with visual studio 2013.
I have to create an highly interactive GUI, so I did research, and found that QML would be the best choice to fit my needs.

I took the basic .cpp and .qml files from a tutorial, the main looks like this.

#include <QtQml/QQmlComponent>
#include <QtQml/QQmlEngine>
#include <QtQml/QQmlContext>
#include <QtGui/QGuiApplication>

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

    QmlApplicationViewer viewer;
    viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
    viewer.setMainQmlFile(QLatin1String("qml/main.qml"));
    viewer.showExpanded();

    return app.exec();
}

but I had this error while building:

'QDeclarativeView' : No such file or directory

so i added #include <QDeclarativeView> but still had the error.

I can't figure out how to successfully build a Qt app using QML in Visual Studio, so any help would be welcomed.

I'm not even sure my .qml file is in the good place.

1

1 Answers

2
votes

QQmlApplicationViewer is not a part of Qt; it's some kind of utility class offered by Qt Creator that sets up a Qt Quick application for you. I don't even know if it still exists these days.

Also, take note of the Qt version that you're using. When looking at documentation online, there are several versions available, so you must ensure that you're searching for the version you're using. For example, here's documentation for a Qt Quick example in Qt 5.5 (at the time of writing):

http://doc.qt.io/qt-5/qtquick-demos-samegame-example.html

And here's that same example in Qt 4.8:

http://doc.qt.io/qt-4.8/qt-demos-declarative-samegame-example.html

Since you're new to Qt and don't seem to have restrictions on which version to use, it's best to use the latest version.

As a general rule while you're a beginner, it's wise not to copy existing parts of examples into a new project, but rather copy the entire example and modify only the parts that you're interested in.

You can find Qt examples under Examples/Qt-5.5/quick/ in your Qt installation, or on the Welcome screen in Qt Creator.