PDA

View Full Version : Problem with displaying a QPixmap on a QImage



moatilliatta
7th September 2010, 17:05
Hello everyone,

i've written the following code:

img = new QImage("images/01_greyscale.png");
QLabel *text1 = new QLabel(tr("..."));
img_greyscale->setPixmap(QPixmap::fromImage(*img));
img_greyscale->show();

QVBoxLayout *leftLayout = new QVBoxLayout;
leftLayout->addWidget(text1);

setLayout(leftLayout);
setWindowTitle(tr("Test"));

"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

Lykurg
7th September 2010, 17:09
Where do you define img_greyscale? Are you sure img_greyscale is not 0 at this state?

koder
7th September 2010, 17:10
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) ?

moatilliatta
7th September 2010, 17:30
Damn, thank you very much!
I just didn't initialized the QLabel. Stupid me.. :confused:

Thread can be closed.