Results 1 to 10 of 10

Thread: JPEG Image isn't displayed!?

  1. #1
    Join Date
    Apr 2007
    Location
    Italy
    Posts
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default JPEG Image isn't displayed!?

    Hi there!
    This my first time on this forum.
    I'm creating an application for an exam and I need to display a JPEG image in the application.
    Here is the code:

    Qt Code:
    1. #include <QApplication>
    2. #include <QImageReader>
    3. #include <QWidget>
    4.  
    5. class MyWidget : public QWidget
    6. {
    7. public:
    8. MyWidget(QWidget *parent = 0);
    9. QImageReader *lettore;
    10. };
    11.  
    12. MyWidget::MyWidget(QWidget *parent)
    13. : QWidget(parent)
    14. {
    15. lettore=new QImageReader("k8055.jpg");
    16. }
    17.  
    18. int main(int argc, char *argv[])
    19. {
    20. QApplication app(argc, argv);
    21. MyWidget widget;
    22. widget.show();
    23. return app.exec();
    24. }
    To copy to clipboard, switch view to plain text mode 

    I'm using QT 4.2.3 Open Source with Visual Studio 2005.
    When I run the application I see a blank dialog with the same image size. Where is the mistake? Can you help me?

    PS. Sorry for bad english but I am Italian

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: JPEG Image isn't displayed!?

    Qt Code:
    1. #include <QApplication>
    2. #include <QWidget>
    3. #include <QPixmap>
    4. #include <QPainter>
    5. #include <QPaintEvent>
    6. class MyWidget : public QWidget
    7. {
    8. public:
    9. MyWidget(QWidget *parent = 0);
    10. QPixmap mPixmap;
    11. protected:
    12. virtual void paintEvent( QPaintEvent* );
    13. };
    14.  
    15. MyWidget::MyWidget(QWidget *parent)
    16.  
    17. : QWidget(parent)
    18. {
    19. mPixmap = QPixmap( "k8055.jpg" );
    20. setFixedSize( mPixmap.size() );
    21. }
    22.  
    23.  
    24. void MyWidget::paintEvent( QPaintEvent* e )
    25. {
    26. if( !mPixmap.isNull() )
    27. {
    28. QPainter painter( this );
    29. p.drawPixmap( 0, 0, mPixmap );
    30. }
    31. }
    32.  
    33. int main(int argc, char *argv[])
    34. {
    35. QApplication app(argc, argv);
    36. MyWidget widget;
    37. widget.show();
    38. return app.exec();
    39. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Oct 2006
    Location
    Germany
    Posts
    84
    Thanks
    5
    Thanked 5 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: JPEG Image isn't displayed!?

    Try using QLabel::setPixmap().

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: JPEG Image isn't displayed!?

    Maybe you don't have JPEG support turned on? What does
    Qt Code:
    1. qDebug() << QImageReader::supportedImageFormats();
    To copy to clipboard, switch view to plain text mode 
    output? This requires reconfiguring and rebuilding Qt libs, see configure -help for more info.
    J-P Nurmi

  5. #5
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: JPEG Image isn't displayed!?

    Make sure the image is in the same folder as the executable. Otherwise, give the complete path when you create the QPixmap.

  6. #6
    Join Date
    Jan 2006
    Posts
    368
    Thanks
    14
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: JPEG Image isn't displayed!?

    [ot]

    how are you using Qt4 OpenSource + Visual Studio?

  7. #7
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: JPEG Image isn't displayed!?

    The hardest part is to get Qt compiled.
    To start a project, you just need to set the appropriate include paths and library paths in the project properties, just as Qt VS Integration does.

    Regards

  8. #8
    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: JPEG Image isn't displayed!?

    To start a project you just need to call "qmake -tp vc"

  9. #9
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: JPEG Image isn't displayed!?

    To start a project you just need to call "qmake -tp vc"
    Or that...

  10. #10
    Join Date
    Apr 2007
    Location
    Italy
    Posts
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: JPEG Image isn't displayed!?

    Quote Originally Posted by marcel View Post
    Qt Code:
    1. #include <QApplication>
    2. #include <QWidget>
    3. #include <QPixmap>
    4. #include <QPainter>
    5. #include <QPaintEvent>
    6. class MyWidget : public QWidget
    7. {
    8. public:
    9. MyWidget(QWidget *parent = 0);
    10. QPixmap mPixmap;
    11. protected:
    12. virtual void paintEvent( QPaintEvent* );
    13. };
    14.  
    15. MyWidget::MyWidget(QWidget *parent)
    16.  
    17. : QWidget(parent)
    18. {
    19. mPixmap = QPixmap( "k8055.jpg" );
    20. setFixedSize( mPixmap.size() );
    21. }
    22.  
    23.  
    24. void MyWidget::paintEvent( QPaintEvent* e )
    25. {
    26. if( !mPixmap.isNull() )
    27. {
    28. QPainter painter( this );
    29. p.drawPixmap( 0, 0, mPixmap );
    30. }
    31. }
    32.  
    33. int main(int argc, char *argv[])
    34. {
    35. QApplication app(argc, argv);
    36. MyWidget widget;
    37. widget.show();
    38. return app.exec();
    39. }
    To copy to clipboard, switch view to plain text mode 
    I managed to make it work using this code thx ! (Actually I had to modify line 29).
    @jpn
    Where do I have to place that instruction in order to show something??

    FOR ALL:
    Can someone explain me why it doesn't work with the QImageReader?
    Sorry for Bad English!

Similar Threads

  1. mouse tracking on image
    By vermarajeev in forum Qt Programming
    Replies: 14
    Last Post: 12th May 2010, 13:06
  2. Replies: 3
    Last Post: 11th March 2007, 13:04
  3. how i can add image in my toolbar
    By jyoti in forum Qt Tools
    Replies: 7
    Last Post: 19th December 2006, 14:39
  4. How and when to repaint a widget ?
    By yellowmat in forum Newbie
    Replies: 7
    Last Post: 3rd April 2006, 16:36
  5. Question about updating an image on screen
    By SkripT in forum Qt Programming
    Replies: 1
    Last Post: 24th February 2006, 19:01

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.