PDA

View Full Version : Issue with QPixmap in Qt 3.2.1



filmfreak
12th February 2006, 22:03
Hi, I am trying to get an image to display on a button. The code belows does the job

void Form1::init() {
pushButton1->setPixmap(QPixmap::fromMimeSource("ulquarter4.jpg"));
.
.
.
}

However, I'd like to be able to use a pixmap variable instead. After declaring QPixmap *Pixmap 1 as a private member, I tried the following:

void Form1::init() {
*Pixmap1 = QPixmap::fromMimeSource("ulquarter4.jpg);
pushButton1->setPixmap(*Pixmap1);
.
.
.
}

It compiled without errors in the command prompt, but when I tried to execute it, I got a popup dialog box declaring that there was an error trying to open the executable.

Can anyone help me?

jacek
12th February 2006, 22:09
Did you initialize that Pixmap1 variable or did you left it as a dangling pointer?

filmfreak
13th February 2006, 00:56
Did you initialize that Pixmap1 variable or did you left it as a dangling pointer?

Is this line in the init() function not the same thing as initializing it?

*Pixmap1 = QPixmap::fromMimeSource("ulquarter4.jpg");

Please note that I am new to Qt Designer...I've been using it for only a few days now.

jacek
13th February 2006, 01:08
Is this line in the init() function not the same thing as initializing it?

*Pixmap1 = QPixmap::fromMimeSource("ulquarter4.jpg");
No, because you first dereference that pointer. You need something like this:

Pixmap1 = new QPixmap(); // initialize Pixmap1 and make it point to a null pixmap
*Pixmap1 = QPixmap::fromMimeSource("ulquarter4.jpg"); // fill that null pixmap with new data
Although it will be much easier, if you just use QPixmap instead of QPixmap *.


Please note that I am new to Qt Designer...I've been using it for only a few days now.
It has nothing to do with Qt Designer or ever Qt itself --- it's C++ issue.

filmfreak
14th February 2006, 20:45
Thanks, I think that solved the problem.