Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Jul 2008

    Adding images as a resource (embeded)


    I'm very very new on Nokia QT development. I'm using Nokia QT SDK latest version and I'm trying to learn who to develop with QT Creator.

    I want to change MainPage.qml background adding my own image. I set up an image on MainPage.qml, and change it its source like this:

    import QtQuick 1.1
    import com.nokia.symbian 1.1
    Page {
        id: mainPage
        Image {
            id: background
            x: 61
            y: 113
            width: 239
            height: 414
            fillMode: Image.PreserveAspectFit
            source: "../../Back.png"
        TextField {
            id: textfield1
            x: 90
            y: 30
            width: 180
            height: 50
            text: "TextField"
    But, when I run it on simulator, I don't see the image and I get the following error:

    Starting D:\Sources\Symbian\SymbianFadeCard-build-simulator-Simulator_Qt_for_Visual_Studio_2008__Qt_SDK__Debug\debug\SymbianFadeCard.exe...
    file:///D:/Sources/Symbian/SymbianFadeCard-build-simulator-Simulator_Qt_for_Visual_Studio_2008__Qt_SDK__Debug/qml/SymbianFadeCard/MainPage.qml:7:5: QML Image: Cannot open: file:///D:/Sources/Symbian/SymbianFadeCard-build-simulator-Simulator_Qt_for_Visual_Studio_2008__Qt_SDK__Debug/Back.png

    May I need to something to embed and image in an executable?

  2. #2
    Registered User
    Join Date
    Feb 2010

    Re: Adding images as a resource (embeded)


    you can embed the image with a resource file, but in qml, there is an other and simplier way. In the folder of your project you can find a qml folder. On that is a folder named by your proejct. Example: c:\qt_projects\testsProject\qml\testProject . If you put your Back.png in that folder, qml can simple access to that image without any kind of path. Example: Image { source: "Back.png" } . If you choose this way instead resource file, all of your images will be packed to the application installer automatically.


  3. #3
    Registered User
    Join Date
    Nov 2010

    Re: Adding images as a resource (embeded)


    Alternative way is to using resource file. Here are the steps to use a resource file:
    1. Add a folder containing a .png image inside your application.
    2. Write click your application in Qt Creator and select Add New..
    3. Select Qt->Qt Resouce file and name something
    4. In your project Resources folder will be added. Open .qrc file
    5. Add Prefix->prefix: /
    6. Add Files->browse the .png inside your application. Save the .qrc
    7. Use the resource file like source: "qrc:/xyz.png"

Similar Threads

  1. adding new resource file giving garbage
    By julie_777 in forum Symbian
    Replies: 6
    Last Post: 2011-07-29, 12:16
  2. Adding Resource file to empty project
    By smnsolomon in forum Symbian
    Replies: 4
    Last Post: 2008-10-21, 08:57
  3. Adding items to a listbox coming from resource
    By jasper.dekeijzer in forum Symbian User Interface
    Replies: 3
    Last Post: 2007-10-16, 20:47
  4. adding a new resource file to project
    By strike_noir in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 2
    Last Post: 2007-09-03, 13:35

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts