QMap inheritance with QMapIterator

Posted by gregseth on Stack Overflow See other posts from Stack Overflow or by gregseth
Published on 2010-02-02T16:56:09Z Indexed on 2010/04/12 13:13 UTC
Read the original article Hit count: 201

Filed under:
|
|
|

Hi,

I made a personnal class which inherits QMap:

class CfgMgr : public QMap<QString, CfgSet*> {...}

I'm trying to iterate over all its elements like that:

CfgMgr* m_pDefaults = new CfgMgr;

// .../...

QMapIterator<QString, CfgSet*> ics(*m_pDefaults);
while (ics.hasNext()) {
   // doing my stuff
}

And I get the compile error:

Can't convert parameter 1 from 'CfgMgr' to 'const QMap< Key,T > &' with [ Key=QString, T=CfgSet * ]

I tried with a dynamic_cast:

QMapIterator<QString, CfgSet*> ics(
    *dynamic_cast< QMap<QString,CfgSet*>* >(m_pDefaults)
);

it compiles, but always returns NULL.

What's wrong? How can I solve this?

© Stack Overflow or respective owner

Related posts about qt

Related posts about qmap