https://forum.librecad.org/Object-not-deleted-in-main-qc-applicationwindow-cpp-tp4627858p4627919.html
This way we don't have to worry about deleting the painter at all.
diff --git a/src/main/qc_applicationwindow.cpp b/src/main/qc_applicationwindow.cpp
index e8fd64c..84bd3ad 100644
--- a/src/main/qc_applicationwindow.cpp
+++ b/src/main/qc_applicationwindow.cpp
@@ -2413,25 +2413,25 @@ bool QC_ApplicationWindow::slotFileExport(const QString& name,
bool ret = false;
QPixmap* buffer = new QPixmap(size);
- RS_PainterQt* painter = new RS_PainterQt(buffer);
+ RS_PainterQt painter(buffer);
// black background:
if (black) {
- painter->setBackgroundColor(RS_Color(0,0,0));
+ painter.setBackgroundColor(RS_Color(0,0,0));
}
// white background:
else {
- painter->setBackgroundColor(RS_Color(255,255,255));
+ painter.setBackgroundColor(RS_Color(255,255,255));
}
// black/white:
if (bw) {
- painter->setDrawingMode(RS2::ModeBW);
+ painter.setDrawingMode(RS2::ModeBW);
}
- painter->eraseRect(0,0, size.width(), size.height());
+ painter.eraseRect(0,0, size.width(), size.height());
- RS_StaticGraphicView gv(size.width(), size.height(), painter);
+ RS_StaticGraphicView gv(size.width(), size.height(), &painter);
if (black) {
gv.setBackground(RS_Color(0,0,0));
} else {
@@ -2441,7 +2441,7 @@ bool QC_ApplicationWindow::slotFileExport(const QString& name,
gv.zoomAuto(false);
for (RS_Entity* e=graphic->firstEntity(RS2::ResolveAll);
e!=NULL; e=graphic->nextEntity(RS2::ResolveAll)) {
- gv.drawEntity(painter, e);
+ gv.drawEntity(&painter, e);
}
// RVT_PORT QImageIO iio;
@@ -2459,7 +2459,7 @@ bool QC_ApplicationWindow::slotFileExport(const QString& name,
QApplication::restoreOverrideCursor();
// GraphicView deletes painter
- painter->end();
+ painter.end();
delete buffer;
if (ret) {
On Jul 24, 2011, at 7:43 AM, ClaudeQC [via LibreCAD] wrote:
Hello,
- In main/qc_applicationwindow.cpp, in the following function:
slotFileExport( const QString& name, const QString& format,
QSize size, bool black, bool bw)
The "painter" object is not deleted at the end of the export process.
- Code look like below:
// GraphicView deletes painter
painter->end();
delete buffer;
- Should it be like:
// GraphicView deletes painter
painter->end();
delete painter;
delete buffer;
Claude