Results 1 to 2 of 2

Thread: QwtPlot::clear() and ownership of QwtLegend

  1. #1
    Join Date
    Jun 2006
    Posts
    11
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QwtPlot::clear() and ownership of QwtLegend

    Hi folks

    I have a doubt.

    QwtPlot *aQwtPlot = new QwtPlot;
    QwtLegend *aQwtLegend = new QwtLegend;
    aQwtPlot->insertLegend(aQwtLegend);
    aQwtPlot->clear();

    Can we say that here we have a mem leak. i.e. memory allocated for aQwtLegend is not taken back (delete is not called) ?

    I did look at this below piece of code. I think I should looking into autoDelete and it's default value.

    if ( rtti == QwtPlotItem::Rtti_PlotItem || item->rtti() == rtti )
    00172 {
    00173 item->attach(NULL);
    00174 if ( autoDelete )
    00175 delete item;
    00176 }

    This is valgrind output I got.

    ==7469== at 0x4005C8C: operator new(unsigned) (vg_replace_malloc.c:163)
    ==7469== by 0x472A6FC: QLayout::addWidget(QWidget*) (qlayout.cpp:240)
    ==7469== by 0x444F765: QwtLegend::insert(QwtPlotItem const*, QWidget*) (in /usr/local/qwt/lib/libqwt.so.5.0.0)
    ==7469== by 0x445E326: QwtPlotItem::updateLegend(QwtLegend*) const (in /usr/local/qwt/lib/libqwt.so.5.0.0)
    ==7469== by 0x4457F6F: QwtPlotCurve::updateLegend(QwtLegend*) const (in /usr/local/qwt/lib/libqwt.so.5.0.0)
    ==7469== by 0x4453269: QwtPlot::insertLegend(QwtLegend*, QwtPlot::LegendPosition, double) (in /usr/local/qwt/lib/libqwt.so.5.0.0)

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,277
    Thanked 871 Times in 819 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QwtPlot::clear() and ownership of QwtLegend

    QwtPlot::clear is a legacy method from early Qwt versions, that removes all curves and markes from the plot. Today there are more types of QwtPlotItems, so that this method doesn't make too much sense. Better use plot->detachItems().

    Removing plot items from the plot also removes the items from the corresponding legend. But QwtPlot::clear doesn't delete the legend and was never defined to do so.

    Uwe

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.