Results 1 to 3 of 3

Thread: Qt resources not working

  1. #1
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    692
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Qt resources not working

    Hi to all,
    I migrated some weeks ago to Qt 5.5 ( from Qt 4.x ) and resources mechanism stopped working ( at least on my machine ).
    Looking at the documentation, seems the same as per Qt 4, so I followed the same logic.

    In my project structure I have a folder named Images containing some icons that I would add to a toolbar.

    Here my simple resources.qrc file:

    Qt Code:
    1. <RCC>
    2. <qresource prefix="/MyFiles">
    3. <file>Images/cut.png</file>
    4. <file>Images/bringtofront.png</file>
    5. <file>Images/colors.png</file>
    6. <file>Images/copy.png</file>
    7. <file>Images/delete.png</file>
    8. <file>Images/link.png</file>
    9. <file>Images/node.png</file>
    10. <file>Images/paste.png</file>
    11. <file>Images/sendtoback.png</file>
    12. </qresource>
    13. </RCC>
    To copy to clipboard, switch view to plain text mode 

    And here the c++ code that does not have any effect

    Qt Code:
    1. addNodeAction = new QAction(tr("Add &Node"), this);
    2. addNodeAction->setIcon(QIcon(":/MyFiles/Images/node.png"));
    3. addNodeAction->setShortcut(tr("Ctrl+N"));
    4. connect(addNodeAction, SIGNAL(triggered()), this, SLOT(addNode()));
    To copy to clipboard, switch view to plain text mode 

    I tried many path combinations, none of them is working:
    Qt Code:
    1. addNodeAction->setIcon(QIcon(":/Images/node.png"));
    2. addNodeAction->setIcon(QIcon("://MyFiles/Images/node.png"));
    3. addNodeAction->setIcon(QIcon(":/node.png"));
    To copy to clipboard, switch view to plain text mode 


    I hope to get some help

    Regards
    Franco Amato

  2. #2
    Join Date
    Apr 2011
    Posts
    195
    Thanks
    49
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt resources not working

    Try to create a QPixmap instance and check if its not null. If so your ressources work.
    So check for the plugins, which handle the showing of pictures, like your png's, in qt applications.

  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: Qt resources not working

    Use something like Gammaray to inspect the resource tree in the running application or use QDir starting at :/ to list the resource tree manually.

    Cheers,
    _

Similar Threads

  1. Is it possible to add QT resources to a DLL?
    By cboles in forum Qt Programming
    Replies: 4
    Last Post: 17th January 2017, 00:12
  2. MP3 file from Resources :-/
    By qtpat in forum Qt Programming
    Replies: 5
    Last Post: 26th March 2014, 16:34
  3. Replies: 7
    Last Post: 24th September 2012, 07:17
  4. Qt Resources
    By kaushal_gaurav in forum Qt Programming
    Replies: 3
    Last Post: 3rd October 2008, 16:30
  5. Resources files (.qrc) not working
    By degs2k4 in forum Qt Programming
    Replies: 16
    Last Post: 21st February 2008, 09:54

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.