Development/Tutorials/Necessitas/Assets: Difference between revisions
Bog dan ro (talk | contribs) |
Bog dan ro (talk | contribs) |
||
Line 24: | Line 24: | ||
QFile file( "qml/foo/main.qml" ); // to open a file just use its path | QFile file( "qml/foo/main.qml" ); // to open a file just use its path | ||
// make sure you set the engine base url to "/" otherwise it will add "file://" in front of your files. | |||
m_qmlAppViewer->engine()->setBaseUrl(QUrl::fromLocalFile("/")); | m_qmlAppViewer->engine()->setBaseUrl(QUrl::fromLocalFile("/")); | ||
m_qmlAppViewer->setSource(QUrl::fromLocalFile("qml/foo/main.qml")); | m_qmlAppViewer->setSource(QUrl::fromLocalFile("qml/foo/main.qml")); |
Revision as of 16:28, 27 November 2011
Android assets
Android assets are read-only arbitrary files bundled in their raw form into your package.Necessitas project provides seamless integration with android assets, meaning that you can access any asset files as you access any ordinary files.
Deploy assets
Before accessing an asset we need to deploy it.
# assuming you want to deploy qml/foo/main.qml file, you need to add the flowing lines to your .pro/.pri file(s)
delployment.files=qml/foo/main.qml
android { #define an android block
delployment.path=/assets/qml/foo #all assets must go to "/assets" folder of your android package
} else : maemo5 { #other platforms
delployment.path=/opt/$${TARGET}
}
INSTALLS += delployment
Access assets
QmlApplicationViewer * m_qmlAppViewer;
#ifdef Q_OS_ANDROID
QFile file( "qml/foo/main.qml" ); // to open a file just use its path
// make sure you set the engine base url to "/" otherwise it will add "file://" in front of your files.
m_qmlAppViewer->engine()->setBaseUrl(QUrl::fromLocalFile("/"));
m_qmlAppViewer->setSource(QUrl::fromLocalFile("qml/foo/main.qml"));
#endif
// do whatever you want with file