QImage to Qpixmap conversion is too slow
-
Hi This is what I have done so far:
class MyGLPainter : public QOpenGLWidget { Q_OBJECT public: MyGLPainter (QWidget *parent = nullptr); void paintEvent(QPaintEvent *) override; void drawImage(const QImage &image); private: QImage m_frameImage;
MyGLPainter::MyGLPainter (QWidget *parent): QOpenGLWidget(parent) { } void MyGLPainter::paintEvent(QPaintEvent *) { QPainter painter(this); painter.drawImage(m_frameImage.width(),m_frameImage.height(), m_frameImage); painter.end(); } void MyGLPainter::drawImage(const QImage &image) { m_frameImage = image; update(); }
But when I pass the image to
drawImage()
, the program will just crash. Am I doing this correctly? -
Do you update your image from a different thread? If so you should learn about threading: Threading Basics
-
Do you update your image from a different thread? If so you should learn about threading: Threading Basics
HI, is this related to the crash?
-
HI, is this related to the crash?
-
@lansing
Hi
then something is wrong with the image then.
Else why crash on copy.can you try with Image that you are 100% sure is valid ?
Hi, I have set the image to one in my resource folder for testing, now it has crashed at line
m_frameImage = image
. I have changed the image argument fromconst QImage &
toQImage*
, I don't know if that have a effect on it. But in debug, it did show my image dimension.QImage *img= new QImage(":/cross.png"); myGLPainter->drawImage(img);
-
Hi, I have set the image to one in my resource folder for testing, now it has crashed at line
m_frameImage = image
. I have changed the image argument fromconst QImage &
toQImage*
, I don't know if that have a effect on it. But in debug, it did show my image dimension.QImage *img= new QImage(":/cross.png"); myGLPainter->drawImage(img);
-
Hi, I have set the image to one in my resource folder for testing, now it has crashed at line
m_frameImage = image
. I have changed the image argument fromconst QImage &
toQImage*
, I don't know if that have a effect on it. But in debug, it did show my image dimension.QImage *img= new QImage(":/cross.png"); myGLPainter->drawImage(img);
@lansing said in QImage to Qpixmap conversion is too slow:
myGLPainter
Where do you initialize this variable?
-
Hi, I have set the image to one in my resource folder for testing, now it has crashed at line
m_frameImage = image
. I have changed the image argument fromconst QImage &
toQImage*
, I don't know if that have a effect on it. But in debug, it did show my image dimension.QImage *img= new QImage(":/cross.png"); myGLPainter->drawImage(img);
@lansing said in QImage to Qpixmap conversion is too slow:
QImage *img= new QImage(":/cross.png");
myGLPainter->drawImage(img);That's the wrong thing to do as you will leak images doing so.
Beside the initialization issue pointed by @Christian-Ehrlicher can you provide the stack trace of your crash ?