Results 1 to 7 of 7

Thread: QVariant, QList, QSettings

  1. #1
    Join Date
    Jan 2006
    Location
    Munich, Germany.
    Posts
    111
    Thanks
    29
    Thanked 3 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default QVariant, QList, QSettings

    Hello all,
    what's going wrong here:
    I'm reading in a list of integers from QSettings and that means doing some juggling with QList<QVariant>, no problem but I get a crash on leaving the function.
    Qt Code:
    1. QList<QVariant> widths;
    2. //fill the QList with some default value
    3. for(int col=0; col<tableWidget->columnCount(); ++col){
    4. widths << 80;//some standard width
    5. }
    6. //read a QVariant from QSettings and convert it to a QList<QVariant>
    7. widths = settings.value("column widths").toList();
    8. //or with a default value
    9. widths = settings.value("column widths", QVariant(widths)).toList();
    10. //then I use the widths variable and get a crash on leaving the function
    To copy to clipboard, switch view to plain text mode 

    thanks
    K

  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: QVariant, QList, QSettings

    Are you sure the variant is a list? How did you store the value in the settings object?

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany.
    Posts
    111
    Thanks
    29
    Thanked 3 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QVariant, QList, QSettings

    I did this

    Qt Code:
    1. QList<QVariant> widths;
    2. for(int col=0; col<tableWidget->columnCount(); ++col){
    3. widths << header->sectionSize ( header->logicalIndex ( col ) ) ;
    4. }
    5. settings.setValue("column widths", widths);
    To copy to clipboard, switch view to plain text mode 

    and I get a nice list in the settings (registry)


    The list is read correctly. I can see each value with a test variable in the loop. eg.
    Qt Code:
    1. QHeaderView* header = tableWidget->horizontalHeader();
    2. for(int col=0; col<tableWidget->columnCount(); ++col){
    3. header->resizeSection ( col, 80);//widths.at(col).toInt() ) ;
    4. int thing = widths.at(col).toInt();//have a look at what's in the list - everything ok
    5. }
    To copy to clipboard, switch view to plain text mode 

    I have the feeling it's something to do with some allocation or other....

    K
    Last edited by TheKedge; 6th March 2007 at 14:20.

  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: QVariant, QList, QSettings

    Did you try debugging? Most probably some destructor crashes. Also try recompiling the whole project - sometimes the call stack gets corrupted due to recompilation errors (especially if using MSVC) and forcing all modules to be recompiled and relinked helps.

  5. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany.
    Posts
    111
    Thanks
    29
    Thanked 3 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QVariant, QList, QSettings

    absolutely right.
    Q_OUTOFLINE_TEMPLATE QList<T>::~QList()
    crashes (on leaving the function). But I've no idea why!
    (I've rebuilt the whole project)

    here's the code again:
    Qt Code:
    1. QList<QVariant> widths;
    2. for(int col=0; col<tableWidget->columnCount(); ++col){
    3. widths << 80;//some standard width
    4. }
    5. //this is the line that when commented in causes the crash on leaving the function
    6. widths = settings.value("column widths").toList();
    7. //replacing all the above with the following is no better
    8. QList <QVariant>widths(settings.value("column widths").toList());
    9. //widths is filled with the correct values - I can see that here... variable 'thing'
    10. QHeaderView* header = tableWidget->horizontalHeader();
    11. for(int col=0; col<tableWidget->columnCount(); ++col){
    12. int thing = widths.at(col).toInt();
    13. }
    To copy to clipboard, switch view to plain text mode 
    my feeling is that QSettings is working fine. But is there something going wrong with the copy constructor of QList<QVariant>. Maybe with deep copy?
    any ideas?

    thanks
    K

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QVariant, QList, QSettings

    Which exact version of Qt are you using? I somehow recall a relevant bug, QList destructor crash, being fixed in one of the recent past versions of Qt 4.[1-2].x.
    J-P Nurmi

  7. #7
    Join Date
    Jan 2006
    Location
    Munich, Germany.
    Posts
    111
    Thanks
    29
    Thanked 3 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QVariant, QList, QSettings

    I downloaded Qt4.2.3 today and installed it.

    K

Similar Threads

  1. using Qlist with a class
    By Havard in forum Qt Programming
    Replies: 10
    Last Post: 24th February 2007, 19:38
  2. QList crash in destructor
    By mclark in forum Newbie
    Replies: 7
    Last Post: 6th December 2006, 15:27
  3. Crash caused by QVariant (mis)use
    By mclark in forum Newbie
    Replies: 2
    Last Post: 31st October 2006, 15:05
  4. Accessing QList Objects
    By magikalpnoi in forum Qt Programming
    Replies: 7
    Last Post: 21st September 2006, 20:43
  5. Values not being appended in a QList
    By Kapil in forum Newbie
    Replies: 5
    Last Post: 21st April 2006, 10:20

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.