Results 1 to 11 of 11

Thread: Problem when load JPG

  1. #1
    Join Date
    Mar 2010
    Location
    Brazil
    Posts
    39
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Problem when load JPG

    I'm trying load a jpg image, but the code doesnt works.

    Look, have this:

    Qt Code:
    1. ...
    2. QImage *img1;
    3. QLabel *imgLbl1;
    4.  
    5.  
    6. img1->load(fileName);
    7.  
    8. imgLbl1->clear();
    9.  
    10. imgLbl1->setPixmap(QPixmap::fromImage(*img1));
    11. ...
    To copy to clipboard, switch view to plain text mode 

    This code only works with png, gif and bmp files but doesnt with jpg.

    Any advice?

    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Problem when load JPG

    Install a jpg decoder.
    Or, in other words, did you compile Qt with jpg support?

  3. #3
    Join Date
    Mar 2010
    Location
    Brazil
    Posts
    39
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem when load JPG

    I dont know. How can i "compile Qt with jpg suppot"?

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Problem when load JPG

    What Qt package did you install?

  5. #5
    Join Date
    Mar 2010
    Location
    Brazil
    Posts
    39
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem when load JPG

    I installed only Qt SDK.

  6. #6
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Problem when load JPG

    Check if the qt/2010.05/bin/imageFormats folder contains qjpeg4.dll

  7. #7
    Join Date
    Mar 2010
    Location
    Brazil
    Posts
    39
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem when load JPG

    Yes, its there.

  8. #8
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Problem when load JPG

    Change your code to use a value instead of a pointer for the image.
    Example:

    Qt Code:
    1. class YourWidgetClass
    2. {
    3. private:
    4. QImage img;
    5. };
    To copy to clipboard, switch view to plain text mode 

    In the constructor:
    Qt Code:
    1. img.load(fileName);
    2. imgLbl1->setPixmap(QPixmap::fromImage(img));
    To copy to clipboard, switch view to plain text mode 

    If that doesn't solve your problem, the filename is wrong.

  9. #9
    Join Date
    Mar 2010
    Location
    Brazil
    Posts
    39
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem when load JPG

    I did what you told me. But doesnt works.
    Only the bmp, png and gif works....

    The path is correct otherwise how can the others formats works?

  10. #10
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Problem when load JPG

    Very simple:
    1. The code you posted is not the real code of your program? But I guess it is.
    2. Back to my first reply, you do not have a jpg decoder on your computer that is able to work with Qt.

    I don't understand your problem. I installed the Qt SDK and showing jpg's works for me, so it is not a Qt SDK problem, it is either a problem with your code or with your system.

  11. #11
    Join Date
    Mar 2010
    Location
    Brazil
    Posts
    39
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem when load JPG

    I think that problem is with system.
    I compiled/ran the same code just now but in linux, and its works!

    tbscope, thanks for your attention!

    Just a last question: Why did you say to me change the *img pointers to img? Is there any problem with pointers use? How can I know when use pointer or not?

    Thanks again.

Similar Threads

  1. Replies: 3
    Last Post: 8th September 2010, 02:01
  2. problem about load resource file dynamically
    By Raul in forum Qt Programming
    Replies: 1
    Last Post: 27th August 2010, 05:56
  3. SQL driver load problem
    By vieraci in forum Qt Programming
    Replies: 1
    Last Post: 12th December 2009, 14:59
  4. QWebView::Load problem
    By yogeshgokul in forum Qt Programming
    Replies: 2
    Last Post: 3rd December 2008, 10:28
  5. QStandardItemModel save/load Problem
    By sun in forum Newbie
    Replies: 9
    Last Post: 1st October 2008, 18:20

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.