Program crashes because of some assertion in <qhash.h>
I get access violations frequently when running the debug version of my program, but for release version, it almost never crashes.
It seems my code has some problem with QHash usage, when program crashes, the debug info leads me to:
QHash<QString, QVariant>::findNode in line 884 of qhash.h, which is a Q_ASSERT statement
- template <class Key, class T>
- uint *ahp) const
- {
- Node **node;
- if (d->numBuckets) {
- node = reinterpret_cast<Node **>(&d->buckets[h % d->numBuckets]);
- Q_ASSERT(*node == e || (*node)->next); //line 884
- while (*node != e && !(*node)->same_key(h, akey))
- node = &(*node)->next;
- } else {
- node = const_cast<Node **>(reinterpret_cast<const Node * const *>(&e));
- }
- if (ahp)
- *ahp = h;
- return node;
- }
QHash<QString, QVariant>::value in line 618 of qhash.h,
- template <class Key, class T>
- {
- Node *node;
- if (d->size == 0 || (node = *findNode(akey)) == e) { //line 618
- return adefaultValue;
- } else {
- return node->value;
- }
- }
Some more information about my program:
I use a QList of QHash<QString, QVariant> to store data which will be displayed in a QTreeView, and a QTimer thread updates the data every second, the error always takes place when some QHash data is being updated.
I don’t have a clue, please give me some hints how this takes place, and what kind of misuse of QHash may cause this error.
Thanks for help.
5 replies
Lets start with the assumption that the error is in your program :-) That is usually a save bet.
I would guess you are accessing something that is somehow invalid, perhaps the hash itself. That could be because of your threading. Did you protect access to the data structure using mutexes or something like that so that your threads can savely access the data?
I use a QList of QHash<QString, QVariant> to store data which will be displayed in a QTreeView, and a QTimer thread updates the data every second, the error always takes place when some QHash data is being updated.
A QTimer thread? Are you using threads for timers [developer.qt.nokia.com] ?
OK, here’s some more information about my program.
1. I didn’t use mutexes to protect my data, but since I had only one thread that modifies data, and QTreeView and some delegates are in charge of displaying data, do I have to use something like that?
2. Yeah, referencing memory that has been freed, that’s what I’m suspecting too, and I’m trying to track down that.
But, why’s that not corrupting my release version program?
3. My QTimer thread is something like this:(The code is in the main GUI thread)
- connect(timer, SIGNAL(timeout()), this, SLOT(updateData()));
- timer->start(1000);
You must log in to post a reply. Not a member yet? Register here!




