Results 1 to 20 of 22

Thread: Image resources (png, ico) not rendering in app

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2010
    Posts
    99
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Image resources (png, ico) not rendering in app

    Hello,

    I'm having a problem with my Qt app where none of the icons show when the app is ran. I haven't worked on it in a while, but I know it used to work. It must have stopped working when I upgraded from Qt 4 to 5.
    I have created a .qrc file, and all the images are in there. I can also see the "RCC'ing" line in the compile output, so it seems to be compiling the resources correctly. But when I run the app, all the buttons are blank and there are no icons in the menu items. Even the image on the about dialog is not showing.

    Here are some details:
    Qt 5.1.0
    Visual Studio 2010
    VS Addin 1.2.2
    Windows 7, 64bit

    I'm not seeing anything in the debug output, and I don't know where to start looking. Can someone please advise how I can debug this issue?

    thanks
    [Window Detective] - Windows UI spy utility
    [War Thunder]

  2. #2
    Join Date
    Jul 2016
    Posts
    19
    Thanks
    9
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Image resources (png, ico) not rendering in app

    Hello,
    Can you show us your qrc file and some lines of code where you create an icon that doesn't work ?

  3. #3
    Join Date
    Aug 2010
    Posts
    99
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Image resources (png, ico) not rendering in app

    My qrc file is just your basic list of files:
    Qt Code:
    1. <RCC>
    2. <qresource prefix="/">
    3. <file>Window Detective.ico</file>
    4. <file>img/picker.png</file>
    5. <file>img/preferences.png</file>
    6. <file>img/find.png</file>
    7. <file>img/window_large.png</file>
    8. ...
    9. </qresource>
    10. </RCC>
    To copy to clipboard, switch view to plain text mode 

    The button icons are specified in the .ui files. Qt Designer correctly shows all the icons.

    I'm currently looking at the code which loads the image for the About dialog.
    Qt Code:
    1. void AboutDialog::setupUi() {
    2. ...
    3. mainFrame = new QFrame(this);
    4. mainFrameLayout = new QHBoxLayout(mainFrame);
    5. mainFrameLayout->setContentsMargins(10, 10, 0, 0);
    6. leftFrame = new QFrame(mainFrame);
    7. leftFrame->setMinimumSize(QSize(128, 0));
    8. windowImageLabel = new QLabel(leftFrame);
    9. QPixmap windowImage(":img/window_large.png");
    10. windowImageLabel->setGeometry(QRect(QPoint(7, 24), windowImage.size()));
    11. windowImageLabel->setMinimumSize(windowImage.size());
    12. windowImageLabel->setMaximumSize(windowImage.size());
    13. windowImageLabel->setPixmap(windowImage);
    14. mainFrameLayout->addWidget(leftFrame);
    15. ...
    16. }
    To copy to clipboard, switch view to plain text mode 

    Stepping into the qpixmap.cpp code, I can see it's getting QFileInfo and returning false because the file does not exist. Something about the resource not being valid in QResourceFileEngine::fileFlags.
    [Window Detective] - Windows UI spy utility
    [War Thunder]

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Image resources (png, ico) not rendering in app

    Try using ":/img/window_large.png". From the documentation for resource files:

    Resource Collection Files (.qrc)

    The resources associated with an application are specified in a .qrc file, an XML-based file format that lists files on the disk and optionally assigns them a resource name that the application must use to access the resource.

    Here's an example .qrc file:

    <!DOCTYPE RCC><RCC version="1.0">
    <qresource>
    <file>images/copy.png</file>
    <file>images/cut.png</file>
    <file>images/new.png</file>
    <file>images/open.png</file>
    <file>images/paste.png</file>
    <file>images/save.png</file>
    </qresource>
    </RCC>

    The resource files listed in the .qrc file are files that are part of the application's source tree. The specified paths are relative to the directory containing the .qrc file. Note that the listed resource files must be located in the same directory as the .qrc file, or one of its subdirectories.

    Resource data can either be compiled into the binary and thus accessed immediately in application code, or a binary resource can be created and at a later point in application code registered with the resource system.

    By default, resources are accessible in the application under the same file name as they have in the source tree, with a :/ prefix, or by a URL with a qrc scheme.
    For example, the file path :/images/cut.png or the URL qrc:///images/cut.png would give access to the cut.png file, whose location in the application's source tree is images/cut.png.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5
    Join Date
    Aug 2010
    Posts
    99
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Image resources (png, ico) not rendering in app

    Oh, with a leading slash after the colon? I'll try that.
    I suppose that was something that changed in Qt 5, because it used to work with just the colon.
    [Window Detective] - Windows UI spy utility
    [War Thunder]

  6. #6
    Join Date
    Aug 2010
    Posts
    99
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Image resources (png, ico) not rendering in app

    Unfortunately, that didn't work. Many of the other images in my project are already referenced with a leading slash (e.g. ":/img/something.png").

    I traced execution into the QResourcePrivate::load function, and res->findNode() always returns -1. It would seem as though the resources aren't being loaded.

  7. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Image resources (png, ico) not rendering in app

    You can use QDir or QDirIterator on ":/" to look into and traverse the resource "file system".

    Or the resource inspector of GammaRay

    Cheers,
    _

  8. The following user says thank you to anda_skoa for this useful post:

    xtal256 (15th February 2017)

  9. #8
    Join Date
    Aug 2010
    Posts
    99
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Image resources (png, ico) not rendering in app

    Quote Originally Posted by anda_skoa View Post
    Or the resource inspector of GammaRay
    Dude, that looks amazing! It's sort of like what my application is to Windows, but better
    It should definitely help me in debugging Qt issues.

    thanks

  10. #9
    Join Date
    Aug 2010
    Posts
    99
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Image resources (png, ico) not rendering in app

    I used the following code to print all resources:
    Qt Code:
    1. QDirIterator it(":/", QDirIterator::Subdirectories);
    2. while (it.hasNext()) {
    3. qDebug() << it.next();
    4. }
    To copy to clipboard, switch view to plain text mode 
    But none of my images were there. Just a bunch of default Qt resources. So it's clear that the resources are not even getting into the build. They are definitely all there in the .qrc file, and I touched it to make sure the build would run RCC on it.
    [Window Detective] - Windows UI spy utility
    [War Thunder]

  11. #10
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Image resources (png, ico) not rendering in app

    Hmm, is your resource part of the application or a library?

    I.e. is it in the RESOURCES variable of the .pro file that generates the main executable?

    Cheers,
    _

  12. #11
    Join Date
    Aug 2010
    Posts
    99
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Image resources (png, ico) not rendering in app

    I don't have a .pro file, I'm using the VS add-in to handle the build. I suspect that I just haven't configured it right, but I don't know exactly how it works. All I know is that it is definitely processing the .qrc file, but obviously it isn't picking up the images and compiling them into the app.

Similar Threads

  1. Replies: 4
    Last Post: 28th April 2014, 13:01
  2. load image from resources in library
    By stevocz in forum Newbie
    Replies: 0
    Last Post: 11th July 2013, 10:21
  3. Replies: 5
    Last Post: 10th October 2012, 22:05
  4. Replies: 2
    Last Post: 14th January 2012, 23:39
  5. Speeding up Image Rendering
    By reno77 in forum Newbie
    Replies: 2
    Last Post: 15th June 2010, 10:58

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.