QImage 上的 drawText() 崩溃程序

Jon*_*lus 3 qt qimage

我在 uint8_t 缓冲区中有一个图像,我正在尝试使用 QImage 作为包装器在图像上写入文本。我使用 drawLine() 没有问题,但 drawText() 使程序崩溃。下面的代码是 boost 线程的一部分,我想在它遍历函数时将文本写入每个图像。Qt 中是否存在我不知道的错误?

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
Run Code Online (Sandbox Code Playgroud)

Jon*_*lus 5

我的项目被设置为 QCoreApplication (我没有 GUI)。将其更改为 QApplication 就成功了!