【发布时间】:2016-10-28 21:33:31
【问题描述】:
使用 Qt 5.7,Windows 7,MinGW 32 位,以下程序:
#include <QImage>
#include <QPainter>
int main () {
QImage i(100, 100, QImage::Format_RGB888);
QPainter p(&i);
p.drawText(0, 0, "abc"); // line 7
}
p.drawText 调用的 Seg 错误,给出以下堆栈跟踪,以 initializeDb 结尾:
1 initializeDb qfontdatabase.cpp 896 0x7930ed0
2 QFontDatabase::findFont qfontdatabase.cpp 2640 0x79361f6
3 QFontDatabase::load qfontdatabase.cpp 2795 0x7936b5e
4 QFontPrivate::engineForScript qfont.cpp 215 0x79194ff
5 QTextEngine::fontEngine qtextengine.cpp 2094 0x793d24b
6 QTextEngine::shapeText qtextengine.cpp 1000 0x7938c0b
7 QTextEngine::shape qtextengine.cpp 1534 0x793b090
8 QTextEngine::shapeLine qtextengine.cpp 938 0x793884a
9 QPainter::drawText qpainter.cpp 5877 0x7a3dc91
10 QPainter::drawText qpainter.cpp 5700 0x7a3cfe6
11 QPainter::drawText qpainter.h 890 0x402a1e
12 main main.cpp 7 0x4016b6
为什么会发生这种情况,我怎样才能让它不发生?
.pro 文件,为了完整性:
QT += core gui
CONFIG += c++11
TARGET = untitled18
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
这是用于生成图像的命令行实用程序。
注意:添加QCoreApplication 并没有什么不同。
【问题讨论】:
-
试试 QApplication 而不是 QCoreApplication。
标签: c++ qt qt5 qpainter qimage