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 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]

  2. #2
    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.

  3. #3
    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,
    _

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

    xtal256 (15th February 2017)

  5. #4
    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

  6. #5
    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]

  7. #6
    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,
    _

  8. #7
    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.

  9. #8
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,233
    Thanks
    303
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

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

    The more important part of anda_skoa's question is whether the resources you are trying to use are in your app EXE or if they are in a DLL you are dynamically loading into your app. If they are in a DLL, you'll need to put a Q_INIT_RESOURCE() macro in main() after your QApplication instance is declared so it will load them properly:

    Qt Code:
    1. QApplication app( argc, argv );
    2.  
    3. Q_INIT_RESOURCE( MyDLL );
    To copy to clipboard, switch view to plain text mode 

    (assuming your DLL is named "MyDLL.dll")

    In Visual Studio, right-click on your qrc file name in the Solution Browser and go to the General properties page. It should look something like the attached screenshot; basically, it should be running rcc on the resource file and putting something in the GeneratedFiles directory.

    Capture.jpg
    Last edited by d_stranz; 16th February 2017 at 03:35.
    <=== 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.

  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

    It's in my app's exe, not a dll.

    But I think the problem is that the properties that are not correct.
    Comparing my property window to your screenshot, the only difference is that my "Additional Dependencies" doesn't list any of the image files like yours does. It just has "%(FullPath);%(AdditionalInputs)". I don't know what %(AdditionalInputs) is.

    However, even when I change "Additional Dependencies" to include all my images (using relative paths, like in your screenshot), it still doesn't work. I even tried touching one of the images thinking maybe the incremental build was skipping over them, but nope.

    Here is the build output, at "diagnostic" verbosity.

  11. #10
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

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

    Try to remove all qrc_*.cpp files from GeneratedFiles folder and then build the project.
    If this work something is wrong with the qrc file definition in the project.

  12. #11
    Join Date
    Jan 2017
    Posts
    58
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Windows

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

    I had the same problem. Try to uncheck "Shadow build" in "Projects".

  13. #12
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,233
    Thanks
    303
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

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

    I had the same problem. Try to uncheck "Shadow build" in "Projects".
    The OP is using Visual Studio, not Qt Creator. VS has no explicit concept of shadow builds although it does allow you to set various output and intermediate directories so you can do an out-of-source build in the same way as a shadow build.

    I doubt this is the OP's problem. It is probably a dependency issue - maybe the resource files are being excluded from the build because of some VS property setting.
    <=== 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.

Similar Threads

  1. Replies: 4
    Last Post: 28th April 2014, 12:01
  2. load image from resources in library
    By stevocz in forum Newbie
    Replies: 0
    Last Post: 11th July 2013, 09:21
  3. Replies: 5
    Last Post: 10th October 2012, 21:05
  4. Replies: 2
    Last Post: 14th January 2012, 22:39
  5. Speeding up Image Rendering
    By reno77 in forum Newbie
    Replies: 2
    Last Post: 15th June 2010, 09: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.