Program directory Structure
Main.cpp Code
Note the path to the Qml file, and compare the file and directory structure in the following post-packaged bar file (figure)
App/native/assets/myqml.qml
#include <QApplication>
#include <QDeclarativeView>
#include <QObject>
int main (int ARGC, Char *argv[])
{
qapplication app (argc, argv);
Qdeclarativeview view;
View.setsource (Qurl ("app/native/assets/myqml.qml"));
View.setattribute (Qt::wa_autoorientation, true);
View.setresizemode (Qdeclarativeview::sizerootobjecttoview);
View.showmaximized ();
return app.exec ();
}
File and directory structure in the packaged bar file (figure)
MYQML.QML Code:
Import QtQuick 1.1
Rectangle {
width:360
height:360
Text {
text:qstr ("Hello World QML")
Anchors.centerIn:parent
}
mousearea {
anchors.fill:parent
onclicked: {
qt.quit ();
}
}
}
Operation effect as shown in figure