How to compile resources and use them for any device

by Developer on ‎10-29-2013 01:37 PM (1,561 Views)



Static asset selection is not supported with compiled resources. For example, if your app stores QML assets in a 720x720 folder, you can't compile your QML resources.


As I quoted above, you can not compile resources and use asset selection for different devices (resolution).


Link bbdevice library

#your pro (project qt) file
LIBS += -lbbdevice


Include DisplayInfo class

#include <bb/device/DisplayInfo>

using namespace bb::device;

Create a QML property in your ApplicationUI class . I call it fullTouch. This means that is not 720x720 device.

Q_PROPERTY(bool fullTouch READ fullTouch WRITE setFullTouch NOTIFY fullTouchChanged)

4.Then set this property before you load qml ui

DisplayInfo display;
int width = display.pixelSize().width()
int height = display.pixelSize().height();
if (width == 720 && height == 720){

3. Expose it to QML

QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this).property("_App", this)

4. Use it

    // some properties
    imageSource: _App.fullTouch ? "asset:///Images/fullTouchImage.png" : "asset:///Images/720x720image.png"