【发布时间】:2019-07-28 16:06:02
【问题描述】:
在不使用“QApplication app(argc, argv);”的情况下将静态文本写入图像文件时需要帮助在主()。我的 QT 版本是 5.12.2。
目前我可以用下面的代码做到这一点:
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QCoreApplication::addLibraryPath("./plugins");
QString imagePath(QStringLiteral("./images/output/testOutput1.png"));
QImage image(500, 400, QImage::Format_RGB888);
image.fill(Qt::red);
QPainter painter;
if (!painter.begin(&image))
return;
painter.setPen(QPen(Qt::black));
painter.setFont(QFont("Times", 12, QFont::Bold));
painter.drawText(image.rect(), Qt::AlignCenter, "writing text on image");
painter.end();
image.save(imagePath);
return 0;
}
我正在尝试获得一个不使用“QApplication app(argc, argv);”的类似类型的解决方案在我的代码中。
目前如果我删除“QApplication app(argc, argv);”的减速我的代码在“painter.drawText(...);”处崩溃。
【问题讨论】: