How to conditionally embed resources(icons) at compile time into the application package based on the target (Symbian/MeeGo)?



  • Hi all,

    On my application I have different versions of icons: let's say for the about dialog I have 2 icons: about64x64.png and about32x32.png. In qml I want to use the shop64x64.png icon if compiling for MeeGo(N950) or the shop32x32.png if compiling for Symbian;
    I have 2 issues:

    1. how to determine in QML at compile time which target is used, so something like below(but how exactly)?

    @ Image {
    id: aboutImg
    source: isMeego()?"qrc:/icons/about64x64.png":"qrc:/icons/about32x32.png";
    }@

    How would I write a function like isMeego()?

    1. the 2nd issue is how to include/or not include these icons in the resources.qrc in my project?
      That is if compiling for Symbian, resources.qrc should be something like:

    @<RCC>
    <qresource prefix="/">
    <file>icons/about32x32.png</file>
    </qresource>
    </RCC>@

    but if compiling for MeeGo(N950) it should be like:
    @<RCC>
    <qresource prefix="/">
    <file>icons/about64x64.png</file>
    </qresource>
    </RCC>@

    I want to use only QtCreator, that is no ant/java or pearl, etc to generate my files...

    Can anyone help?

    Thanks&regards,
    Ionut



  • What I would do, is make the difference in your .pro file. You just create two resource files, one for Symbian, and one for Meego. They contain images with the same names (or at least: aliases), but with the styling and resolution appropriate for the platform. Then, from your .pro file, you select the actual resource file you want to compile in.

    Edit:
    It will simplify your code to this:
    @
    Image {
    id: aboutImg
    source: "qrc:/icons/about.png";
    }
    @



  • Hi Andre,

    Thanks a lot, that was very helpful.

    However I also want to define different font sizes to use in my qml files based on the platform. So how can one code a function like isMeego() in the first post?

    Thanks,
    Ionut



  • You can use defines. There are platform defines (Q_OS_...) in Qt already, but you can also create your own in your .pro file. I don't know if there is something specific for Meego, but there is for Symbian.

    Instead of using an isMeego() method, you could use conditional compilation like this:
    @
    #ifdef Q_OS_S60
    setFontSize(10);
    #else
    setFOntSize(12);
    #endif
    @

    The benefit is, that the if statement is evaluated at compilation time, not every time at runtime. That makes your application a bit smaller and faster.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.