View Full Version : QVariant, QList, QSettings
TheKedge
6th March 2007, 13:46
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.
QList<QVariant> widths;
//fill the QList with some default value
for(int col=0; col<tableWidget->columnCount(); ++col){
widths << 80;//some standard width
}
//read a QVariant from QSettings and convert it to a QList<QVariant>
widths = settings.value("column widths").toList();
//or with a default value
widths = settings.value("column widths", QVariant(widths)).toList();
//then I use the widths variable and get a crash on leaving the function
thanks
K
wysota
6th March 2007, 14:11
Are you sure the variant is a list? How did you store the value in the settings object?
TheKedge
6th March 2007, 14:16
I did this
QList<QVariant> widths;
for(int col=0; col<tableWidget->columnCount(); ++col){
widths << header->sectionSize ( header->logicalIndex ( col ) ) ;
}
settings.setValue("column widths", widths);
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.
QHeaderView* header = tableWidget->horizontalHeader();
for(int col=0; col<tableWidget->columnCount(); ++col){
header->resizeSection ( col, 80);//widths.at(col).toInt() ) ;
int thing = widths.at(col).toInt();//have a look at what's in the list - everything ok
}
I have the feeling it's something to do with some allocation or other....
K
wysota
6th March 2007, 14:23
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.
TheKedge
6th March 2007, 14:42
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:
QList<QVariant> widths;
for(int col=0; col<tableWidget->columnCount(); ++col){
widths << 80;//some standard width
}
//this is the line that when commented in causes the crash on leaving the function
widths = settings.value("column widths").toList();
//replacing all the above with the following is no better
QList <QVariant>widths(settings.value("column widths").toList());
//widths is filled with the correct values - I can see that here... variable 'thing'
QHeaderView* header = tableWidget->horizontalHeader();
for(int col=0; col<tableWidget->columnCount(); ++col){
int thing = widths.at(col).toInt();
}
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
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.
TheKedge
6th March 2007, 15:50
I downloaded Qt4.2.3 today and installed it.
K
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.