Results 1 to 4 of 4

Thread: Crash on function exit (destructor) while using QVariantList with VS2010 ?

  1. #1
    Join Date
    Apr 2011
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Question Crash on function exit (destructor) while using QVariantList with VS2010 ?

    Hello all, it seems that when this is compiled with VS2010, it crashes at the destructor call, as can be seen by the stack dump:
    Qt Code:
    1. msvcr100d.dll!operator delete(void * pUserData) Line 52 + 0x51 bytes C++
    2. > testini.exe!QVariant::`scalar deleting destructor'() + 0x46 bytes C++
    3. testini.exe!QList<QVariant>::node_destruct(QList<QVariant>::Node * from, QList<QVariant>::Node * to) Line 418 + 0x3e bytes C++
    4. testini.exe!QList<QVariant>::free(QListData::Data * data) Line 744 C++
    5. testini.exe!QList<QVariant>::~QList<QVariant>() Line 718 C++
    6. testini.exe!WzConfig::vector2i(const QString & name) Line 65 + 0x1d bytes C++
    7. testini.exe!main(int argc, char * * argv) Line 82 + 0x31 bytes C++
    To copy to clipboard, switch view to plain text mode 

    The code in question looks like (it crashes on exit of this function):
    Qt Code:
    1. Vector2i WzConfig::vector2i(const QString &name)
    2. {
    3. Vector2i r;
    4. ASSERT_OR_RETURN(r, contains(name), "Missing %s", name.toUtf8().constData());
    5. QVariantList v = value(name).toList();
    6. ASSERT(v.size() == 2, "Bad list of %s", name.toUtf8().constData());
    7. r.x = v[0].toInt();
    8. r.y = v[1].toInt();
    9. return r;
    10. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QCoreApplication a(argc, argv);
    4.  
    5. {
    6. WzConfig ini("test.ini");
    7. ini.setVector2i("test", Vector2i(1, 2));
    8. ini.setVector3i("test2", Vector3i(1, 2, 3));
    9. ini.setVector3f("test3", Vector3f(1, 2, 3));
    10. ini.setVector3f("test3", Vector3i(1, 2, 3));
    11. ini.setVector3i("test3", Rotation(1, 2, 3));
    12. }
    13. {
    14. WzConfig ini("test.ini");
    15. Vector2i v = ini.vector2i("test");
    16. qWarning("x = %d, y = %d", v.x, v.y);
    17. }
    18.  
    19. return 0;
    20. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. struct Vector2i
    2. {
    3. Vector2i() {}
    4. Vector2i(int x, int y) : x(x), y(y) {}
    5.  
    6. int x, y;
    7. };
    8.  
    9.  
    10. class WzConfig : public QSettings
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. WzConfig(const QString &name, QObject *parent = 0) : QSettings(QString("test.ini"), QSettings::IniFormat, parent) { Q_UNUSED(name); }
    16. Vector3f vector3f(const QString &name);
    17. void setVector3f(const QString &name, const Vector3f &v);
    18. Vector3i vector3i(const QString &name);
    19. void setVector3i(const QString &name, const Vector3i &v);
    20. Vector2i vector2i(const QString &name);
    21. void setVector2i(const QString &name, const Vector2i &v);
    22. };
    To copy to clipboard, switch view to plain text mode 

    Does anyone know if this is a Qt bug (version 4.7.2) or is this a compiler bug (VS 2k10)--it don't seem to crash on linux, or are we doing something wrong ?
    Note: VS2k10 was used to compile 4.7.2 libs, since that isn't made available yet on Qt's main site)

    Thanks for the info.

  2. #2
    Join Date
    Apr 2011
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Crash on function exit (destructor) while using QVariantList with VS2010 ?

    If I change the above code to this
    Qt Code:
    1. Vector2i WzConfig::vector2i(const QString &name)
    2. {
    3. Vector2i r;
    4. ASSERT_OR_RETURN(r, contains(name), "Missing %s", name.toUtf8().constData());
    5. QStringList v = value(name).toStringList();
    6. ASSERT(v.size() == 2, "Bad list of %s", name.toUtf8().constData());
    7. r.x = v[0].toInt();
    8. r.y = v[1].toInt();
    9. return r;
    10. }
    To copy to clipboard, switch view to plain text mode 
    Then I don't get any crashes.

    So it is a problem with QVariantList for some reason.

  3. #3
    Join Date
    Apr 2011
    Posts
    124
    Thanks
    1
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60

    Default Re: Crash on function exit (destructor) while using QVariantList with VS2010 ?

    What does method value() do??

    The basic problem is that QVariantList is attempting to destruct the objects it "owns", and one of those has already been destructed. Scenarios like this may work or not work, depending on the precise order that things appear in the "child" chain.

    I suspect your problem is in your implementations of value() and toList().

  4. #4
    Join Date
    Apr 2011
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Crash on function exit (destructor) while using QVariantList with VS2010 ?

    Quote Originally Posted by DanH View Post
    What does method value() do??

    The basic problem is that QVariantList is attempting to destruct the objects it "owns", and one of those has already been destructed. Scenarios like this may work or not work, depending on the precise order that things appear in the "child" chain.

    I suspect your problem is in your implementations of value() and toList().
    Hmm?

    It is:
    class WzConfig : public QSettings
    ie, Qsettings::value().toList().
    And value is defined as:
    QVariant value ( const QString & key, const QVariant & defaultValue = QVariant() ) const

Similar Threads

  1. QSqlQuery crash in destructor
    By seim in forum Qt Programming
    Replies: 5
    Last Post: 22nd January 2010, 22:12
  2. QTableWidget Crash in Destructor
    By mclark in forum Qt Programming
    Replies: 19
    Last Post: 25th July 2008, 14:44
  3. Crash on QString Destructor
    By ToddAtWSU in forum Qt Programming
    Replies: 1
    Last Post: 14th June 2007, 14:28
  4. QList crash in destructor
    By mclark in forum Newbie
    Replies: 7
    Last Post: 6th December 2006, 15:27
  5. QVariantList HELP!!!
    By magikalpnoi in forum Qt Programming
    Replies: 1
    Last Post: 12th September 2006, 09:13

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.