PDA

View Full Version : How to delete QwtPlotMarker Objects of QMap<int, QList<QwtPlotMarker *> >



HappyCoder
19th July 2015, 08:31
Hello,

i try to delete the objects of this QMap:



QMap<int, QList<QwtPlotMarker *> > mapTempMarker;


The map contains an integer as curveId of a Curve that is attached to a QwtPlot.
The inner QList contains all pointers to markers that are added to that curve.

i tried:



QMapIterator<int, QList<QwtPlotMarker *> i(mapTempMarker);
while (i.hasNext())
{
i.next();
qDeleteAll( i.value() );
}


but got these to errors:
1. template argument 2 is invalid
QMapIterator<int, QList<QwtPlotMarker *> i(mapTempMarker);

2. i was not decelared in this scope
while (i.hasNext())

What i'm doing wrong and how to delete this map correctly (i mean the objects behind).

The QMap itself is part of this:



class PlotManager::PrivateData
{
public:
PrivateData(){}
~PrivateData()
{
// Necessary, because "delete" deletes only the pointers, but not the objects behind
qDebug() << Q_FUNC_INFO << "Delete Objects";
qDebug() << Q_FUNC_INFO << "qDeleteAll(curvesPressure)"; qDeleteAll(curvesPressure);
qDebug() << Q_FUNC_INFO << "qDeleteAll(curvesPressure)"; qDeleteAll(curvesTemperature);
qDebug() << Q_FUNC_INFO << "qDeleteAll(curvesPressure)"; qDeleteAll(curvesTemperature);

// Delete QMap<int, QList<QwtPlotMarker *> >
QMapIterator<int, QList<QwtPlotMarker *> i(mapTempMarker);
while (i.hasNext())
{
i.next();
qDeleteAll( i.value() );
}

}

QVector<QwtPlotCurve *> curvesPressure;
QVector<QwtPlotCurve *> curvesTemperature;
QMap<int, QList<QwtPlotMarker *> > mapTempMarker;
};


Thx
Stefan

d_stranz
19th July 2015, 18:04
If your code is exactly as you have copied it here, you are missing the closing ">" on the QMapIterator declaration, which means that the compiler never gets a definition for "i", which results in the second error.

HappyCoder
20th July 2015, 07:14
shame on me :(, you are right... now it's working.

Stefan