2010-06-14

Set Base Url of QML Files

You may deploy all qml file to a fold called qml in the same place of main.exe file. For example

debian:~/project/tmp/release# tree
.
|-- main.exe
`-- qml
    |-- BasicButton.qml
    |-- Battery.qml
    |-- Calendar.qml
    |-- main.qml

In the main.cpp, you have to specifiy the base url of qml. See the sampe:

#include <QApplication>
#include <QDeclarativeView>
#include <QDeclarativeContext>
#include <QDeclarativeEngine>

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

    view.engine()->setBaseUrl(QUrl("./qml/"));
    view.setSource(QUrl("main.qml"));
    view.show();

    return app.exec();
}

No comments:

Post a Comment