Results 1 to 3 of 3

Thread: Strange QHash crash

  1. #1
    Join Date
    Dec 2013
    Posts
    14
    Thanks
    2
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Question Strange QHash crash

    precondition:

    Qt Code:
    1. static QHash<SomeQObject *, QString> s_register;
    2.  
    3. SomeQObject::~SomeQObject()
    4. {
    5. s_register.remove(this);
    6. }
    To copy to clipboard, switch view to plain text mode 
    if the deconstructor is called during program shutdown there happens a crash in the QHash detach helper (in line 10); the object is valid at the time when "remove" is called, but the key below is now apparently a null pointer...

    Qt Code:
    1. template <class Key, class T>
    2. struct QHashNode
    3. {
    4. QHashNode *next;
    5. uint h;
    6. Key key;
    7. T value;
    8.  
    9. inline QHashNode(const Key &key0) : key(key0) {} // ### remove in 5.0
    10. inline QHashNode(const Key &key0, const T &value0) : key(key0), value(value0) {}
    11. inline bool same_key(uint h0, const Key &key0) { return h0 == h && key0 == key; }
    12. };
    To copy to clipboard, switch view to plain text mode 

    this crash happens not when the deconstructor is explicitly called otherwise, it also does not happen if i use a QMap instead a QHash (what is not a big problem fortunately) - any ideas what may cause this???

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Strange QHash crash

    Please post a minimal compilable example reproducing the problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Dec 2013
    Posts
    14
    Thanks
    2
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Strange QHash crash

    Quote Originally Posted by wysota View Post
    Please post a minimal compilable example reproducing the problem.
    thanks for taking the time to respond; i have found the reason already: the object was (accidentally) deleted on shutdown using a mutable iterator who empties the register container and in addition also deletes the contained items, thus the remove in the deconstructor was called on the already removed QHash node once again. i didn't see it in first (and 2nd and 3rd) place, as it worked (under the same conditions) with a QMap and only got evident after switching to QHash...

Similar Threads

  1. Replies: 3
    Last Post: 12th May 2011, 17:45
  2. !!!A Strange Crash
    By hhf in forum Qt Programming
    Replies: 12
    Last Post: 10th March 2010, 12:45
  3. Replies: 1
    Last Post: 10th February 2009, 09:42
  4. QDataStream and QHash<QString,QVariant> crash on read
    By ^NyAw^ in forum Qt Programming
    Replies: 1
    Last Post: 15th July 2008, 12:14
  5. Can QHash::capacity() be smaller than QHash::size()?!?
    By iw2nhl in forum Qt Programming
    Replies: 2
    Last Post: 24th August 2007, 01:17

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.