Results 1 to 4 of 4

Thread: QImage problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QImage problem

    Hi,
    why my programm didn't show JPG? There is definitely wrong with my code.Can the expert help me figure it out.

    Thx in advance

    Qt Code:
    1. //@main.cpp
    2.  
    3. #include <QtGui/QApplication>
    4. #include <QLabel>
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication a(argc, argv);
    9.  
    10. QImage myImage;
    11. myImage.load("file:///home/ipan/test.JPG");
    12.  
    13. QLabel myLabel;
    14. myLabel.setPixmap(QPixmap::fromImage(myImage));
    15.  
    16.  
    17. myLabel.show();
    18.  
    19. return a.exec();
    20. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    May 2011
    Posts
    239
    Qt products
    Qt4
    Platforms
    Unix/X11 Symbian S60
    Thanks
    4
    Thanked 35 Times in 35 Posts

    Default Re: QImage problem

    Help for figuring it out:
    Start with the obvious one: check what .load returns. "Returns true if the image was successfully loaded; otherwise returns false."

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: QImage problem

    Two observations:
    • You don't need a file URI for a local file, just use the path.
    • QImage::load() takes a file name, not a URI (it uses QFile).
    • You don't need to go via a QImage to load QPixmap from a JPEG file.


    OK, that's three.

  4. #4
    Join Date
    Sep 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QImage problem

    Thx mvuori and ChrisQ67.

    i changed the Path to:
    Qt Code:
    1. myImage.load("/home/ipan/test.png");
    To copy to clipboard, switch view to plain text mode 

    and it works.

    @ChrisW67
    You don't need to go via a QImage to load QPixmap from a JPEG file.
    This is just a test programm. Actually i have to fetch "picture file" that has been loaded with QImage class and showing it in on the screen. So i actualy need this to works.

    thx again guys

Similar Threads

  1. Problem with pixelIndex in QImage
    By danilodsp in forum Newbie
    Replies: 2
    Last Post: 17th September 2011, 07:14
  2. Problem with displaying a QPixmap on a QImage
    By moatilliatta in forum Newbie
    Replies: 3
    Last Post: 7th September 2010, 18:30
  3. qImage saving to jpg problem
    By sqarpi in forum Qt Programming
    Replies: 9
    Last Post: 1st September 2010, 16:43
  4. RGBComponents / QImage Conversion problem
    By sincnarf in forum Qt Programming
    Replies: 2
    Last Post: 31st July 2007, 00:41

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
  •  
Qt is a trademark of The Qt Company.