Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Program crashes because of some assertion in <qhash.h>
Forum Updated to NodeBB v4.3 + New Features

Program crashes because of some assertion in <qhash.h>

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 6.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    leonidwang
    wrote on last edited by
    #1

    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>
    Q_OUTOFLINE_TEMPLATE typename QHash<Key, T>::Node **QHash<Key, T>::findNode(const Key &akey,
    uint *ahp) const
    {
    Node **node;
    uint h = qHash(akey);

    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>
    Q_INLINE_TEMPLATE const T QHash<Key, T>::value(const Key &akey, const T &adefaultValue) const
    {
    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.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      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?

      1 Reply Last reply
      0
      • T Offline
        T Offline
        theoriginalgri
        wrote on last edited by
        #3

        Indeed, some more information about your usage would be nice.

        • Are you accessing QHash from another thread?
        • Are you sure the instance you're accessing was not delete before? (Corrupted memory)

        I've done pretty much with QHash and I can tell you it works perfectly ;)

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dangelog
          wrote on last edited by
          #4

          [quote]
          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.
          [/quote]

          A QTimer thread? Are you using "threads for timers":http://developer.qt.nokia.com/wiki/Threads_Events_QObjects#92dd35cc61ffc41d02defdcef071856d ?

          Software Engineer
          KDAB (UK) Ltd., a KDAB Group company

          1 Reply Last reply
          0
          • L Offline
            L Offline
            leonidwang
            wrote on last edited by
            #5

            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)
              @
              timer = new QTimer(this);
              connect(timer, SIGNAL(timeout()), this, SLOT(updateData()));
              timer->start(1000);
              @

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              If the above code is really in your GUI thread, and this is your timer, than forget everything about mutexes and the likes. You are not using threading, so that is not the solution.

              Look for your solution around your point 2.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved