PDA

View Full Version : QMap



AnithaRagupathy
23rd November 2007, 05:51
hi,
How to use auto pointer in qmap.
I tried giving like QMap<qint32, auto_Ptr Name> m_xxx; .But it gives error.

mchara
23rd November 2007, 07:42
hi, could you paste error you had?
and what do you mean by auto pointer? is it QPointer? Or maybe it is some data type not from qt?

jpn
23rd November 2007, 09:01
How to use auto pointer in qmap.
I tried giving like QMap<qint32, auto_Ptr Name> m_xxx; .But it gives error.
First of all, get used to a habit of pasting errors you get. We are not mind-readers..

Secondly, "QMap<qint32, auto_Ptr Name>" is not valid C++. Try to be exact what you write because, again, we cannot guess if you actually wrote for example "QMap<qint32, auto_ptr<Name> >". Anyway, in case you mean std::auto_ptr, you cannot use it in containers. There are solutions like "counted_ptr" which can be used in containers.

AnithaRagupathy
23rd November 2007, 14:02
I created auto pointer and wanted to use it like this..

typedef std::auto_ptr<IBaureihe> IBaureihePtr;
IBaureihePtr create_IBaureihe();
QMap<qint32, IBaureihePtr>::iterator lIter

Errors that i get

d:/Qt/4.3.0/src/corelib/tools/qhash.h: In constructor `QHashNode<int,
T>::QHashNode(int, const T&) [with T = LaufwegSbFr::IDSOrgaPtr]':
d:/Qt/4.3.0/src/corelib/tools/qhash.h:93: instantiated from `static void QHash<Key, T>::duplicat
ode(QHashData::Node*, void*) [with Key = qint32, T = LaufwegSbFr::IDSOrgaPtr]'
d:/Qt/4.3.0/src/corelib/tools/qhash.h:535: instantiated from `void QHash<Key, T>::detach_helper(
[with Key = qint32, T = LaufwegSbFr::IDSOrgaPtr]'
d:/Qt/4.3.0/src/corelib/tools/qhash.h:551: instantiated from `QHash<Key, T>& QHash<Key, T>::oper
or=(const QHash<Key, T>&) [with Key = qint32, T = LaufwegSbFr::IDSOrgaPtr]'
GlobalLaufwegImpl.cpp:528: instantiated from `void QHash<Key, T>::clear() [with Key = qint32, T
LaufwegSbFr::IDSOrgaPtr]'
GlobalLaufwegImpl.cpp:21: instantiated from here
d:/Qt/4.3.0/src/corelib/tools/qhash.h:215: passing `const
LaufwegSbFr::IDSOrgaPtr' as `this' argument of `std::auto_ptr<_Tp>::operator
std::auto_ptr_ref<_Tp1>() [with _Tp1 = LaufwegSbFr::IDSOrga, _Tp =
LaufwegSbFr::IDSOrga]' discards qualifiers

jacek
23rd November 2007, 14:12
I created auto pointer and wanted to use it like this..

typedef std::auto_ptr<IBaureihe> IBaureihePtr;
When auto_ptr is destroyed, it destroys also the object it points to, which makes it completely unsuable for storing in any containers. Use boost::shared_ptr instead.

mchara
23rd November 2007, 14:26
typedef std::auto_ptr<IBaureihe> IBaureihePtr;
IBaureihePtr create_IBaureihe();
QMap<qint32, IBaureihePtr>::iterator lIter

You're putting variable name instead of type try with


QMap<qint32, std::auto_ptr<IBaureihe> >::iterator lIter