Problem with ressource file



  • Hello :)
    I'm having trouble adding images in qt projects, through qrc files. I'm trying to add an image to a label, but can't do it. I click on "Copy path", paste it in the code, but when running the label remains blank. I tried adding an additional '/' but it's not working. If I enter the absolute path(C:\User...) I can see the image.

    Here a screenshot



  • @cpper

    Do you have your resourcefile in your pro file?

    RESOURCES += \
             ress.qrc
    


  • @the_ Yes, it's there.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Can you share the content of the file ?

    And an example of line you use to load an image in a QLabel ?



  • @SGaist
    File untitled3.pro:

    #-------------------------------------------------

    Project created by QtCreator 2016-07-25T14:54:55

    #-------------------------------------------------

    QT += core gui

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = untitled3
    TEMPLATE = app

    SOURCES += main.cpp
    mainwindow.cpp

    HEADERS += mainwindow.h

    FORMS += mainwindow.ui

    RESOURCES +=
    ress.qrc


    Here I load the pic in the QLabel. It's also highlighted in the image in the first post:

    ui->pic->setPixmap(pic.scaled(ui->pic->width(),ui->pic->height(),Qt::KeepAspectRatio));

    ui->pic is the QLabel
    pic is the QPixmal created above.



  • The code in the screeshot looks fine.
    Did you specify an alias in the qrc-file?
    Can you paste the plaintext content of the qrc-file?



  • @micland I haven't specified an alias(Actually don't know what that is,anyway)

    Here is the content of the qrc:

    <RCC>
    <qresource prefix="/">
    <file>cio.jpg</file>
    </qresource>
    </RCC>



  • can you show how you construct pic? it should be QPixmap pic(":/cio.jpg");



  • @VRonin You can see that in the screenshot from the first post. It's the same as your line.



  • Is rcc run on the resource file at all?

    qmake is terrible at detecting changes in the .pro file, try clearing everything and then rebuild



  • @VRonin I've rebuild the project, still can't see the image. I'll try on a fresh project right now.



  • Also, the .pro file that you posted should not work correctly. Newlines in pro files are the same as ; in C++

    RESOURCES +=
    ress.qrc
    

    should become

    RESOURCES += ress.qrc
    

    same as

    SOURCES += main.cpp
    mainwindow.cpp
    

    should become

    SOURCES += main.cpp \
    mainwindow.cpp
    


  • @VRonin Are you sure ? I haven't touched anything in the .pro file. It just auto-generated content, and I guess the compiler knows what he's doing



  • The same code worked on a fresh project and I can see the image. Strange.



  • That means rcc was definitely not running



  • @VRonin

    I tried to quote the post that contained the pro file, and it was correct with \ in the RESOURCE line

    Sometimes backslashes are "consumed" here :)


Log in to reply
 

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