Results 1 to 4 of 4

Thread: QPixmap loading from resources problem on Windows

  1. #1
    Join Date
    Dec 2013
    Posts
    2
    Qt products
    Qt5

    Default QPixmap loading from resources problem on Windows

    I have a problem with loading QPixmap from Qt Resources on Windows 8. I added image pawn.png (with resource editor from Qt Creator) which is in project's directory. Resource editor file res.qrc is in the same place as image. Here is the content:

    <RCC>
    <qresource prefix="/">
    <file>pawn.png</file>
    </qresource>
    </RCC>

    The code for loading image:

    QPixmap pawn;
    if(!pawn.load("://pawn.png"))
    std::cout << "Can't load image" << std::endl;
    scene->addPixmap(pawn);

    There is always printed "Can't load image". I've tried probably all slash/backslash combinations in image path, nothing works. The one above is generated with right clicking in Resource Editor on image and "Copy Resource Path to Clipboard". Can anyone help?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QPixmap loading from resources problem on Windows

    It is only one forward slash, but otherwise this looks ok.

    Try listing the resource root, e..g
    Qt Code:
    1. QDir dir(":/");
    2. qDebug() << dir.entryList();
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  3. #3
    Join Date
    Dec 2013
    Posts
    2
    Qt products
    Qt5

    Default Re: QPixmap loading from resources problem on Windows

    It returns "qt-project.org". How can I change this? I thought that project's directory is root for resources by default.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QPixmap loading from resources problem on Windows

    Yes, you are just seeing the "directory" of Qt's own resources.

    Meaning yours are not there.

    Check that your resource file is properly listes in your .pro file and rebuild.
    Check that the build directory has the generated qrc_resourcefilename.cpp file

    Cheers,
    _

Similar Threads

  1. QWebView sometimes not loading external resources
    By complexgeek in forum Qt Programming
    Replies: 2
    Last Post: 6th June 2011, 02:37
  2. Problem with QPixmap after deployment on Windows
    By MadBear in forum Installation and Deployment
    Replies: 0
    Last Post: 31st August 2010, 15:00
  3. Problem loading QPixmap on Qt 4.2 in Symbian s60
    By Tito in forum Qt Programming
    Replies: 9
    Last Post: 11th May 2010, 13:30
  4. image loading problem using qpixmap
    By dutt_004 in forum Qt Programming
    Replies: 4
    Last Post: 23rd February 2010, 01:18
  5. Problem with embedded resources under windows xp?
    By Kumosan in forum Installation and Deployment
    Replies: 1
    Last Post: 8th October 2008, 08:50

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.