Results 1 to 7 of 7

Thread: QMap destructor bug

  1. #1
    Join Date
    Jan 2006
    Posts
    3
    Qt products
    Qt3
    Platforms
    Windows

    Default QMap destructor bug

    Hi all,

    We used a var yyyy of vollowing type:

    typedef QMap<QString, QVariant> XXXX;
    QMap<QString, XXXX> * yyyy;


    This somewhat complex construction with a QMap containing a QMap works fine untill we call the destructor for yyyy . Then we get a crash!

    We think that the problem is that the destructor of QMap calls another destructor of a QMap and we expect this destructor not to be reentrant.

    Does anyone recognize this?
    Does anyone think that the a QMap should not contain another QMap?

    Thanks, Ruud.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMap destructor bug

    Do you have something like this?
    Qt Code:
    1. #include <qmap.h>
    2. #include <qstring.h>
    3. #include <qvariant.h>
    4.  
    5. typedef QMap< QString, QVariant > X;
    6.  
    7. int main()
    8. {
    9. QMap< QString, X > * y = new QMap< QString, X >();
    10.  
    11. X x;
    12. x.insert( "AAA", 10 );
    13.  
    14. y->insert( "BBB", x );
    15.  
    16. delete y;
    17.  
    18. return 0;
    19. }
    To copy to clipboard, switch view to plain text mode 
    It works OK on my system (PLD Linux, Qt 3.3.6). Even if QMap destructor wasn't re-entrant, it's still a class template, so these maps would have different destructors.

  3. #3
    Join Date
    Jan 2006
    Posts
    3
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: QMap destructor bug

    this is the code I used:

    (*yyyy)["stringA"]["stringB"].asMap()["styringC"].asStringList().append("stringD");

    delete yyyy; //crash


    remarkable is that the crash happens on most computers we use, but not all. We do not know what could be the difference between these computers...

  4. #4
    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: QMap destructor bug

    The code you use doesn't make much sense. First of all there are no "as*" methods (I guess you call them from QVariant) but even if we assume these are "to*", they return a copy not a reference, so they create temporary objects which get deleted immediately, thus your '["styringC"].asStringList().append("stringD")' does exactly nothing. And probably it is causing the crash in the destructor.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMap destructor bug

    Qt Code:
    1. #include <qmap.h>
    2. #include <qstring.h>
    3. #include <qvariant.h>
    4.  
    5. typedef QMap< QString, QVariant > X;
    6.  
    7. int main()
    8. {
    9. QMap< QString, X > * y = new QMap< QString, X >();
    10.  
    11. (*y)["stringA"]["stringB"].asMap()["styringC"].asStringList().append("stringD");
    12.  
    13. delete y;
    14.  
    15. return 0;
    16. }
    To copy to clipboard, switch view to plain text mode 

    All seems to be OK:
    (gdb) run
    Starting program: /home/users/jacek/qtcentre/map/map_test

    Program exited normally.
    Does this crash happen always on a given computer? Maybe you create those maps in static or global objects? Did you try to obtain the stack trace?

  6. #6
    Join Date
    Jan 2006
    Posts
    3
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: QMap destructor bug

    It happens on most computers we use. We use QT 3.3.1. On some computers we do not get the crtash but we use same QT version everywhere.
    We are looking for a strange buggy here...

  7. #7
    Join Date
    Jan 2006
    Posts
    109
    Thanks
    2
    Thanked 5 Times in 5 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QMap destructor bug

    There is probably a memory error somewhere else in the program. There's no issue with QMap "reentrancy" here since there are no threads involved. You need to run your program in a memory debugger such as Purify on Windows or Valgrind on Linux.

    By the way, why allocate with new:
    Qt Code:
    1. QMap<QString, XXXX> * yyyy
    To copy to clipboard, switch view to plain text mode 
    instead of allocating on the stack when possible:
    Qt Code:
    1. QMap<QString, XXXX> yyyy
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. How to implement operator<() for QMap
    By learning_qt in forum Qt Programming
    Replies: 6
    Last Post: 9th January 2009, 11:21
  2. QMap model data
    By gyre in forum Newbie
    Replies: 3
    Last Post: 9th December 2007, 23:19
  3. Qmap
    By phillip_Qt in forum Qt Programming
    Replies: 3
    Last Post: 23rd November 2007, 11:43
  4. Problems using QMap
    By importantman in forum Qt Programming
    Replies: 1
    Last Post: 27th October 2006, 23:43
  5. QMap Problem with arguments.
    By ankurjain in forum Qt Programming
    Replies: 1
    Last Post: 24th May 2006, 13:12

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.