skm
skm

Reputation: 5679

How to set QLabel using setPixmap from pointer QImage *image?

i am trying to run two threads. One is the non-Gui thread and the other one is the GUI thread. Now, when i am trying to put the image in the QLabel using the command
imageLabel->setPixmap(QPixmap::fromImage(image));
then i get an error:QPixmap: It is not safe to use pixmaps outside the GUI thread.

So, to deal with the above mentioned problem. I have declared QImage *image; in my header file and i get my image from msg into *image using image = new QImage(&(msg->data[0]), msg->width, msg->height, QImage::Format_RGB888);and then i want to set my image in the QLabel from this pointer. But i don't understand, what format of setPixmap should be used now. The usual code imageLabel->setPixmap(QPixmap::fromImage(image));is not working now as QImage *image is pointer of type.

So, basically i am trying to do the following:-

QImage *image; //in header file
QLabel *imageLabel: //in header file

image = new QImage(&(msg->data[0]), msg->width, msg->height, QImage::Format_RGB888);
imageLabel->setPixmap(QPixmap::fromImage(???????));

Upvotes: 1

Views: 4628

Answers (1)

Pavel Strakhov
Pavel Strakhov

Reputation: 40512

You need to use * operator to convert QImage* to QImage&:

imageLabel->setPixmap(QPixmap::fromImage(*image));

But if you get the "outside of GUI thread" in your error message, you're trying to set the label's pixmap in the other thread. It's not possible. Aside from QPixmap issue, it is not allowed to use GUI objects outside of GUI thread as well.

Upvotes: 2

Related Questions