melon
5th August 2010, 22:55
Hello everyone,
First: great forum, a lot of useful information. Thanks for all experienced users for support.
I have some issues while trying to iterate through QHash data structure designed as:
QHash<QString, QHash<QString, int> >
A brief description of a class:
class RCDelayedRpcCaller : public QObject
{
Q_OBJECT
public:
explicit RCDelayedRpcCaller(renderclient::RenderClient *rc, QObject *parent = 0);
(...)
private:
// el.name, el.attr, value
// | | |
QHash<QString, QHash<QString, int> > scalarHashTable;
(...)
//object that gets data from above data structure
renderclient::RenderClient *renderClient;
(...)
};
When I'm trying to implement that with QHashIterator, the program crashes:
QHashIterator<QString, QHash<QString, int> > i(scalarHashTable);
while (i.hasNext()){
qDebug() << i.key();// crashes here;
QHash<QString, int> attribute = i.value();
QHashIterator<QString, int> j(attribute);
while (j.hasNext()){
renderClient->set_scalar_type_attribute(i.key(), j.key(), j.value());
}
}
In debuger it shows hashTable structures and it seems to be just fine. I've found that changing from iterator to following code works and does what's expected:
QHash<QString, QHash<QString, int> >::const_iterator i = scalarHashTable.constBegin();
while (i != scalarHashTable.constEnd()){
QHash<QString, int>::const_iterator j = i.value().constBegin();
while (j != i.value().constEnd()){
renderClient->set_scalar_type_attribute(i.key(), j.key(), j.value());
++j;
}
++i;
}
What am I doing wrong? I'd like to use QHashIterator, as it looks better for my eyes:) but can't get it working.
First: great forum, a lot of useful information. Thanks for all experienced users for support.
I have some issues while trying to iterate through QHash data structure designed as:
QHash<QString, QHash<QString, int> >
A brief description of a class:
class RCDelayedRpcCaller : public QObject
{
Q_OBJECT
public:
explicit RCDelayedRpcCaller(renderclient::RenderClient *rc, QObject *parent = 0);
(...)
private:
// el.name, el.attr, value
// | | |
QHash<QString, QHash<QString, int> > scalarHashTable;
(...)
//object that gets data from above data structure
renderclient::RenderClient *renderClient;
(...)
};
When I'm trying to implement that with QHashIterator, the program crashes:
QHashIterator<QString, QHash<QString, int> > i(scalarHashTable);
while (i.hasNext()){
qDebug() << i.key();// crashes here;
QHash<QString, int> attribute = i.value();
QHashIterator<QString, int> j(attribute);
while (j.hasNext()){
renderClient->set_scalar_type_attribute(i.key(), j.key(), j.value());
}
}
In debuger it shows hashTable structures and it seems to be just fine. I've found that changing from iterator to following code works and does what's expected:
QHash<QString, QHash<QString, int> >::const_iterator i = scalarHashTable.constBegin();
while (i != scalarHashTable.constEnd()){
QHash<QString, int>::const_iterator j = i.value().constBegin();
while (j != i.value().constEnd()){
renderClient->set_scalar_type_attribute(i.key(), j.key(), j.value());
++j;
}
++i;
}
What am I doing wrong? I'd like to use QHashIterator, as it looks better for my eyes:) but can't get it working.