Results 1 to 10 of 10

Thread: Load an image in QLabel

  1. #1
    Join Date
    Feb 2009
    Posts
    32
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Load an image in QLabel

    why if i execute:

    Qt Code:
    1. QImage image(imgPath);
    2. label->setPixmap(QPixmap::fromImage(image));
    To copy to clipboard, switch view to plain text mode 

    don't show image

    qt is install on linux in static mode whitout demo and example...

  2. #2
    Join Date
    Oct 2007
    Location
    Cracow
    Posts
    56
    Thanks
    1
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Load an image in QLabel

    I think that you are doing something wrong when you create object QImage, use this code and see what load function return
    Qt Code:
    1. QImage image;
    2. bool result = image.load( imgPath );
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Load an image in QLabel

    I would say you are using a relative path to the image and QImage simply can't find it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Feb 2009
    Posts
    32
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Load an image in QLabel

    the imgPath is

    /Users/user/Desktop/img.jpg

    is absolute path not relative

    when i do

    Qt Code:
    1. QImage image;
    2. bool result = image.load( imgPath );
    3. cout <<"result ="<<result;
    To copy to clipboard, switch view to plain text mode 

    result =0.

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Load an image in QLabel

    Is the image readable to your application? Try using QFile and get the attributes of the image file. And sorry, but check via
    Qt Code:
    1. qWarning() << QFile::exists(imgPath);
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Feb 2009
    Posts
    32
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Load an image in QLabel

    qWarning return true...

  7. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Load an image in QLabel

    Ok, what't the output of
    Qt Code:
    1. QFileInfo fi(imgPath);
    2. qWarning() << fi.permissions();
    To copy to clipboard, switch view to plain text mode 
    and maybe the jpg is defect, that you may open it with gimp etc. but qt fails. So for debug open the file and save it as png and try to load this in Qt.

  8. #8
    Join Date
    Feb 2009
    Posts
    32
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Load an image in QLabel

    jpg are correct and qWarning output is

    30583

  9. #9
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Load an image in QLabel

    Sorry if I bother you, but then it must be in your code. Last debug question (with your image):
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char **argv)
    4. {
    5. QApplication app(argc, argv);
    6.  
    7. QImage image;
    8. bool result = image.load( "/qt/qtsdk-2009.01/qt/src/3rdparty/libtiff/html/images/smallliz.jpg" );
    9. qWarning() << result;
    10.  
    11. QLabel lab;
    12. lab.setPixmap(QPixmap::fromImage(image));
    13. lab.show();
    14.  
    15. return app.exec();
    16. }
    To copy to clipboard, switch view to plain text mode 

    don't work? Here on my linux machine it works as expected.

  10. #10
    Join Date
    Feb 2009
    Posts
    32
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Load an image in QLabel

    ok thanks the problem was installation of qt... the static mode don't load jpg becouse it find pluging thanks for help

Similar Threads

  1. Replies: 7
    Last Post: 13th August 2008, 18:27
  2. can Qlabel display a series of image one by one ?
    By jirach_gag in forum Qt Tools
    Replies: 3
    Last Post: 11th August 2008, 15:36
  3. Show Image on a QLabel
    By ^NyAw^ in forum Newbie
    Replies: 11
    Last Post: 15th April 2008, 15:45
  4. Replies: 13
    Last Post: 18th February 2008, 00:20
  5. Set the image at the center in QLabel?
    By vishal.chauhan in forum Qt Programming
    Replies: 5
    Last Post: 20th August 2007, 14:07

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.