Results 1 to 6 of 6

Thread: Problem with ressource file

  1. #1
    Join Date
    Jul 2016
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Question 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: http://i.imgur.com/8JoRQYZ.png

  2. #2
    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: Problem with ressource file

    Check if the file is actually in the resource system.

    E.g. use QDir to list ":/" or use the resource inspector in GammaRay https://www.kdab.com/gammaray/

    Btw, QLabel can scale its contents to its size, but if you want to scale yourself, load into a QImage and convert the result of it scaling function to QPixmap.
    This is more efficient, since QPixmap scaling needs to convert to QImage anyway.

    Cheers,
    _

  3. #3
    Join Date
    Jul 2016
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Problem with ressource file

    Thanks for the reply. Could you please provide the code for checking if the file is in the ressource system via QDir ? I'm a complete beginner and am having a hard time.

  4. #4
    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: Problem with ressource file

    Qt Code:
    1. foreach (const QString &file, QDir(":/").entryList()) {
    2. qDebug() << file;
    3. }
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  5. #5
    Join Date
    Jul 2016
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Problem with ressource file

    I wrote the same code in a new project and could see the image. Strange.

  6. #6
    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: Problem with ressource file

    Most likely -wasn't- "the same code", and if it was, then most likely you hadn't put your image files into the Qt resources for your program correctly. Compilers don't generally take "the same code" and produce different results each time through.
    <=== 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: 2
    Last Post: 14th April 2015, 13:03
  2. QWebView does not display <img> vom qrc-Ressource
    By MisterIKS in forum Qt Programming
    Replies: 0
    Last Post: 12th November 2012, 18:40
  3. File Problem
    By oonursrc in forum Qt Programming
    Replies: 6
    Last Post: 11th September 2011, 19:39
  4. problem in qss file
    By phillip_Qt in forum Qt Programming
    Replies: 10
    Last Post: 9th April 2008, 12:36
  5. EXE File problem
    By triperzz in forum Installation and Deployment
    Replies: 8
    Last Post: 18th January 2008, 19:00

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.