我有一组SVG文件,希望在QWidget中用作图标。在我的QWidget paintEvent函数中,我有以下内容:
void Tool::paintEvent(QPaintEvent *e) {
QImage icon = QImage(32, 32, QImage::Format_ARGB32);
QSvgRenderer *ren = new QSvgRenderer(QString(m_part_dir.c_str()) + "\\drawing.svg");
QPainter painter(&icon);
ren->render(&painter);
}
我看了很多关于如何做这件事的建议,这种方法一直被提出。然而,当我运行这段代码时,它会抛出一个异常,在这一行:
ren->render(&painter);
这个中断停在一个名为dbgrptt.c的文件中:
_CRTIMP void __cdecl _CrtDbgBreak(
void
)
{
__debugbreak();
}
调用栈看起来像这样:
msvcr110d.dll!_CrtDbgBreak() Line 87 C
msvcr110d.dll!_VCrtDbgReportW(int nRptType=2, void * returnAddress=0x0f8a7553, const wchar_t * szFile=0x0f793148, int nLine=52, const wchar_t * szModule=0x00000000, const wchar_t * szFormat=0x0f77127c, char * arglist=0x0029e954) Line 506 C
msvcr110d.dll!_CrtDbgReportWV(int nRptType=2, void * returnAddress=0x0f8a7553, const wchar_t * szFile=0x0f793148, int nLine=52, const wchar_t * szModule=0x00000000, const wchar_t * szFormat=0x0f77127c, char * arglist=0x0029e954) Line 262 C++
msvcr110d.dll!_CrtDbgReportW(int nRptType=2, const wchar_t * szFile=0x0f793148, int nLine=52, const wchar_t * szModule=0x00000000, const wchar_t * szFormat=0x0f77127c, ...) Line 279 C++
msvcr110d.dll!operator delete(void * pUserData=0x031392e0) Line 52 C++
QtGuid4.dll!QPenPrivate::`scalar deleting destructor'(unsigned int) C++
QtGuid4.dll!QPen::~QPen() Line 346 C++
QtGuid4.dll!QPaintEngineExPrivate::~QPaintEngineExPrivate() Line 172 C++
QtGuid4.dll!QRasterPaintEnginePrivate::~QRasterPaintEnginePrivate() C++
QtGuid4.dll!QRasterPaintEnginePrivate::`scalar deleting destructor'(unsigned int) C++
QtGuid4.dll!QScopedPointerDeleter<QPaintEnginePrivate>::cleanup(QPaintEnginePrivate * pointer=0x03135d80) Line 62 C++
QtGuid4.dll!QScopedPointer<QPaintEnginePrivate,QScopedPointerDeleter<QPaintEnginePrivate> >::~QScopedPointer<QPaintEnginePrivate,QScopedPointerDeleter<QPaintEnginePrivate> >() Line 100 C++
QtGuid4.dll!QPaintEngine::~QPaintEngine() Line 723 C++
QtGuid4.dll!QPaintEngineEx::~QPaintEngineEx() C++
QtGuid4.dll!QRasterPaintEngine::~QRasterPaintEngine() Line 428 C++
QtGuid4.dll!QRasterPaintEngine::`scalar deleting destructor'(unsigned int) C++
QtGuid4.dll!QImageData::~QImageData() Line 224 C++
QtGuid4.dll!QImageData::`scalar deleting destructor'(unsigned int) C++
QtGuid4.dll!QImage::~QImage() Line 1283 C++
SystemDesigner_d.exe!Parts::Tool::paintEvent(QPaintEvent * e=0x0029f238) Line 39 C++
有人能理解这个吗?