Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

drawText() on a QImage crashes program

Tags:

qt

qimage

I have an image in uint8_t buffer and I am trying to use QImage as a wrapper to write text on the image. I have used drawLine() with no issues, but drawText() crashes the program. The below code is part of a boost thread in which I want to write text unto each image as it iterates through the function. Are there any bugs in Qt I am unaware of?

uint8_t *frameBuffer; // this contains image pixels
QImage img(frameBuffer, sizeX, m_sizeY, QImage::Format_RGB888);

QPainter p(&img);

p.setPen(QPen(Qt::green));
p.setFont(QFont("Times", 10, QFont::Bold));
p.drawLine(img.rect().bottomLeft().x(), img.rect().bottomLeft().y()-10,
           img.rect().bottomRight().x(), img.rect().bottomRight().y()-10);  //works!

p.drawText(img.rect(), Qt::AlignCenter, "Help");  //crashes program
like image 729
JonnyCplusplus Avatar asked Sep 05 '26 04:09

JonnyCplusplus


1 Answers

My project was set to a QCoreApplication (I had no GUI). Changing it to QApplication did the trick!

like image 89
JonnyCplusplus Avatar answered Sep 08 '26 05:09

JonnyCplusplus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!