Results 1 to 4 of 4

Thread: Problem with displaying a QPixmap on a QImage

  1. #1
    Join Date
    Sep 2010
    Location
    Germany
    Posts
    7
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Problem with displaying a QPixmap on a QImage

    Hello everyone,

    i've written the following code:
    Qt Code:
    1. img = new QImage("images/01_greyscale.png");
    2. QLabel *text1 = new QLabel(tr("..."));
    3. img_greyscale->setPixmap(QPixmap::fromImage(*img));
    4. img_greyscale->show();
    5.  
    6. QVBoxLayout *leftLayout = new QVBoxLayout;
    7. leftLayout->addWidget(text1);
    8.  
    9. setLayout(leftLayout);
    10. setWindowTitle(tr("Test"));
    To copy to clipboard, switch view to plain text mode 

    "img_greyscale" is defined in the header-file.
    When starting the program with the "img_greyscale->setPixmap" line no Window pops up, nothing happens at all, not even an error is thrown. But i can't terminate the program so there must be a problem with this line.
    What do i do wrong?

    The "images" folder lies in the source-folder. The png-image weights only 8kb.


    Thanks for your help.

    Greetings,
    moat

  2. #2
    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: Problem with displaying a QPixmap on a QImage

    Where do you define img_greyscale? Are you sure img_greyscale is not 0 at this state?

  3. The following user says thank you to Lykurg for this useful post:

    moatilliatta (8th September 2010)

  4. #3
    Join Date
    Sep 2010
    Posts
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Problem with displaying a QPixmap on a QImage

    When you say "defined in the header-file", do you mean it is declared? Is it initialized as well?

    I am guessing img_greyscale has not been initialized (new QLabel) ?

  5. The following user says thank you to koder for this useful post:

    moatilliatta (8th September 2010)

  6. #4
    Join Date
    Sep 2010
    Location
    Germany
    Posts
    7
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with displaying a QPixmap on a QImage

    Damn, thank you very much!
    I just didn't initialized the QLabel. Stupid me..

    Thread can be closed.

Similar Threads

  1. Displaying a QImage on the screen
    By nuser in forum Qt Programming
    Replies: 1
    Last Post: 9th April 2010, 20:51
  2. Replies: 16
    Last Post: 29th March 2010, 07:05
  3. QImage displaying through OpenGL
    By strateng in forum Newbie
    Replies: 0
    Last Post: 23rd March 2010, 04:35
  4. DIB to QImage or QPixmap
    By ^NyAw^ in forum Qt Programming
    Replies: 0
    Last Post: 8th August 2008, 20:18
  5. What's faster: QPixmap-to-QImage or QImage-to-QPixmap
    By forrestfsu in forum Qt Programming
    Replies: 2
    Last Post: 15th December 2006, 17:11

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.