Object not deleted in main/qc_applicationwindow.cpp

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Object not deleted in main/qc_applicationwindow.cpp

ClaudeQC

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

Reply | Threaded
Open this post in threaded view
|

Re: Object not deleted in main/qc_applicationwindow.cpp

R. van Twisk
Administrator
Claude,

this is properly true I also see the same for slotFilePrint
where the painter isn't deleted.

Ries
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




If you reply to this email, your message will be added to the discussion below:
http://librecad.1049103.n5.nabble.com/Object-not-deleted-in-main-qc-applicationwindow-cpp-tp4627858p4627858.html
To start a new topic under LibreCAD, email [hidden email]
To unsubscribe from LibreCAD, click here.

Reply | Threaded
Open this post in threaded view
|

Re: Object not deleted in main/qc_applicationwindow.cpp

R. van Twisk
Administrator
In reply to this post by ClaudeQC
Claude,

what if we just do it like this??
This way we don't have to worry about deleting the painter at all.

Ries


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




If you reply to this email, your message will be added to the discussion below:
http://librecad.1049103.n5.nabble.com/Object-not-deleted-in-main-qc-applicationwindow-cpp-tp4627858p4627858.html
To start a new topic under LibreCAD, email [hidden email]
To unsubscribe from LibreCAD, click here.

Reply | Threaded
Open this post in threaded view
|

Re: Object not deleted in main/qc_applicationwindow.cpp

ClaudeQC

On 24/07/2011 09:15, R. van Twisk [via LibreCAD] wrote:

 > Claude,
 >
 > what if we just do it like this??
 > This way we don't have to worry about deleting the painter at all.
 >

Hello Ries,

- I don't like creating objects in the stack.
   Prefer to create them in the heap memory (with new).

- I don't know RS_PainterQt class.
   If this class is not too big in term of data memory usage, it may be
   acceptable to create associated objects in the stack.


Claude


Reply | Threaded
Open this post in threaded view
|

Re: Object not deleted in main/qc_applicationwindow.cpp

R. van Twisk
Administrator
Claude,

al Qt examples I have just looked at are creating the painter on the stack,
except the project called dbscreen (it does soem fnacy bitblk's....

This give me the impression that it's fine to create a QPainter on the stack.

RS_PainterQt extends QPainter and RS_Painter, RS_Painter.

RS_Painter is a abstract class and only holds 

    /**
     * Current drawing mode.
     */
    RS2::DrawingMode drawingMode;
    /**
     * A fixed offset added to all entities drawn (useful for previews).
     */
    RS_Vector offset;

So in terms of memory usage, I think it's neglect-able, no long arrays
are anything are stored in a RS_PAinterQT.

Ries

On Jul 24, 2011, at 9:39 AM, ClaudeQC [via LibreCAD] wrote:


On 24/07/2011 09:15, R. van Twisk [via LibreCAD] wrote:

 > Claude,
 >
 > what if we just do it like this??
 > This way we don't have to worry about deleting the painter at all.
 >

Hello Ries,

- I don't like creating objects in the stack.
   Prefer to create them in the heap memory (with new).

- I don't know RS_PainterQt class.
   If this class is not too big in term of data memory usage, it may be
   acceptable to create associated objects in the stack.


Claude





If you reply to this email, your message will be added to the discussion below:
http://librecad.1049103.n5.nabble.com/Object-not-deleted-in-main-qc-applicationwindow-cpp-tp4627858p4628044.html
To start a new topic under LibreCAD, email [hidden email]
To unsubscribe from LibreCAD, click here.

Reply | Threaded
Open this post in threaded view
|

Re: Object not deleted in main/qc_applicationwindow.cpp

R. van Twisk
Administrator
Claude,

I just asked this question on the IRC channel and they mentioned 'stack' :)

For this case, I think I need to agree with that. The QPainter is just used in that function and doesn't use any memory anyways.

Ries
Reply | Threaded
Open this post in threaded view
|

Re: Object not deleted in main/qc_applicationwindow.cpp

ClaudeQC

On 24/07/2011 13:54, R. van Twisk [via LibreCAD] wrote:

 >
 >
 > I just asked this question on the IRC channel and they mentioned 'stack' :)
 >
 > For this case, I think I need to agree with that. The QPainter is just used in
 > that function and doesn't use any memory anyways.
 >

- Ok.

- Given your explanation, I agreed with you to create these objects
   from the stack.


Claude


Reply | Threaded
Open this post in threaded view
|

Re: Object not deleted in main/qc_applicationwindow.cpp

R. van Twisk
Administrator
Claude,

I fixed 3 occasions of this and all now use the stack.
Thanks for spotting this!

Ries
On Jul 24, 2011, at 1:45 PM, ClaudeQC [via LibreCAD] wrote:


On 24/07/2011 13:54, R. van Twisk [via LibreCAD] wrote:

 >
 >
 > I just asked this question on the IRC channel and they mentioned 'stack' :)
 >
 > For this case, I think I need to agree with that. The QPainter is just used in
 > that function and doesn't use any memory anyways.
 >

- Ok.

- Given your explanation, I agreed with you to create these objects
   from the stack.


Claude





If you reply to this email, your message will be added to the discussion below:
http://librecad.1049103.n5.nabble.com/Object-not-deleted-in-main-qc-applicationwindow-cpp-tp4627858p4628511.html
To start a new topic under LibreCAD, email [hidden email]
To unsubscribe from LibreCAD, click here.