Create Simple qml application

2.1k views Asked by At

I am new to Qt. I am creating simple qml application. Qt Version :- QMake version 2.01a Using Qt version 4.6.2 I am on Linux system. I have created qml containing two buttons(button.qml) and also created c++ code(main.cpp).

Code for main.cpp

 #include<QtGui/QApplication>
 #include<QtGui/QLabel>
 #include"qmlapplicationviewer.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QmlApplicationViewer viewer;

    viewer.setOrientation(QmlApplicationViewer::ScreenOrientationLockLandscape);   
    viewer.setMainQmlFile(QLatin1String("button.qml"));
    viewer.showExpanded();
    a.exec();
}

I am compiling it with qmake && make and got error as

qmlapplicationviewer.h: No such file or directory
QmlApplicationViewerâ was not declared in this scope

I tried to search for "qmlapplicationviewer.h" and "QmlApplicationViewer" on my system. But unable to find it.

Please help.

1

There are 1 answers

1
László Papp On BEST ANSWER

I would not use the application viewer for such a simple case, so I would drop it. I would write something like this:

#include <QDeclarativeView>
#include <QApplication>

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

    QDeclarativeView view;
    view.setSource(QUrl("button.qml"));
    view.showFullScreen();

    return app.exec();
}

If you really wish to use the qml application viewer, you could obtain the header and source file from here, and add them to the corresponding HEADERS and SOURCES variables in your project file.