agarny
25th February 2014, 17:14
Hi,
I am trying, using QSettings, to serialise various settings, which are of type QList<int>. Now, it all works fine on Windows and OS X, but for some reasons it doesn't on Linux. Here is how I do it to load (https://github.com/opencor/opencor/blob/653bf65ea4bbd4e9819f4d5d43cabf8867c59f42/src/plugins/editing/CellMLAnnotationView/src/cellmlannotationviewwidget.cpp#L77) and save (https://github.com/opencor/opencor/blob/653bf65ea4bbd4e9819f4d5d43cabf8867c59f42/src/plugins/editing/CellMLAnnotationView/src/cellmlannotationviewwidget.cpp#L99) some of those settings. Notice that I register QList<int> as a meta-type (using qRegisterMetaTypeStreamOperators), so I believe I should be all fine and, indeed, it all works as I would expect on Windows and OS X, but not on Linux. On Linux, I get a bunch of warnings like:
QVariant::load: unable to load type 1038.
QVariant::load: unable to load type 1038.
QVariant::save: unable to save type 'QList<int>' (type id: 1038).
QVariant::save: unable to save type 'QList<int>' (type id: 1038).
QVariant::load: unable to load type 1038.
QVariant::load: unable to load type 1038.
QVariant::save: unable to save type 'QList<int>' (type id: 1038).
QVariant::save: unable to save type 'QList<int>' (type id: 1038).
QVariant::load: unable to load type 1038.
QVariant::load: unable to load type 1038.
QVariant::save: unable to save type 'QList<int>' (type id: 1038).
QVariant::save: unable to save type 'QList<int>' (type id: 1038).
QVariant::load: unable to load type 1038.
QVariant::load: unable to load type 1038.
QVariant::save: unable to save type 'QList<int>' (type id: 1038).
QVariant::save: unable to save type 'QList<int>' (type id: 1038).
QVariant::load: unable to load type 1038.
QVariant::load: unable to load type 1038.
QVariant::save: unable to save type 'QList<int>' (type id: 1038).
QVariant::save: unable to save type 'QList<int>' (type id: 1038).
QVariant::load: unable to load type 1038.
QVariant::load: unable to load type 1038.
QVariant::save: unable to save type 'QList<int>' (type id: 1038).
QVariant::save: unable to save type 'QList<int>' (type id: 1038).
QVariant::load: unable to load type 1038.
QVariant::load: unable to load type 1038.
Just out of curiosity, I thought I would try loading/saving my settings in a different way by using QVariantList. Thus, for loading my settings, I have something like:
void CellmlAnnotationViewWidget::loadSettings(QSettings *pSettings)
{
// Retrieve the sizes of our editing widget and of its metadata details
// Note: we would normally do this in CellmlAnnotationViewEditingWidget, but
// we have one instance of it per CellML file and we want to share
// some information between the different instances, so we have to do
// it here instead...
QVariantList defaultEditingWidgetSizes = QVariantList() << 0.25*qApp->desktop()->screenGeometry().width()
<< 0.75*qApp->desktop()->screenGeometry().width();
QVariantList defaultMetadataDetailsWidgetSizes = QVariantList() << 0.25*qApp->desktop()->screenGeometry().height()
<< 0.25*qApp->desktop()->screenGeometry().height()
<< 0.50*qApp->desktop()->screenGeometry().height();
QVariantList editingWidgetSizes = pSettings->value(SettingsCellmlAnnotationViewEditingWidgetSiz es, defaultEditingWidgetSizes).toList();
QVariantList metadataDetailsWidgetSizes = pSettings->value(SettingsCellmlAnnotationViewMetadataDetailsW idgetSizes, defaultMetadataDetailsWidgetSizes).toList();
foreach (const QVariant &editingWidgetSize, editingWidgetSizes)
mEditingWidgetSizes << editingWidgetSize.toInt();
foreach (const QVariant &metadataDetailsWidgetSize, metadataDetailsWidgetSizes)
mMetadataDetailsWidgetSizes << metadataDetailsWidgetSize.toInt();
}
while for saving them, I have something like:
void CellmlAnnotationViewWidget::saveSettings(QSettings *pSettings) const
{
// Keep track of the sizes of our editing widget and of its metadata details
QVariantList editingWidgetSizes = QVariantList();
QVariantList metadataDetailsWidgetSizes = QVariantList();
foreach (const int &editingWidgetSize, mEditingWidgetSizes)
editingWidgetSizes << editingWidgetSize;
foreach (const int &metadataDetailsWidgetSize, mMetadataDetailsWidgetSizes)
metadataDetailsWidgetSizes << metadataDetailsWidgetSize;
pSettings->setValue(SettingsCellmlAnnotationViewEditingWidget Sizes, editingWidgetSizes);
pSettings->setValue(SettingsCellmlAnnotationViewMetadataDetai lsWidgetSizes, metadataDetailsWidgetSizes);
}
Now, the interesting bit is that... it works on Windows, OS X and... also Linux! So, could it be that I have just come across a bug with Qt (5.2.1) on Linux?...
Whatever the case, even though using QVariantList does indeed 'fixes' my problem, I would rather use my original approach, if possible (I find 'cleaner'). This aside, I am curious as what I have done wrong, if anything, in my original approach. Anyone?
Cheers, Alan.
I am trying, using QSettings, to serialise various settings, which are of type QList<int>. Now, it all works fine on Windows and OS X, but for some reasons it doesn't on Linux. Here is how I do it to load (https://github.com/opencor/opencor/blob/653bf65ea4bbd4e9819f4d5d43cabf8867c59f42/src/plugins/editing/CellMLAnnotationView/src/cellmlannotationviewwidget.cpp#L77) and save (https://github.com/opencor/opencor/blob/653bf65ea4bbd4e9819f4d5d43cabf8867c59f42/src/plugins/editing/CellMLAnnotationView/src/cellmlannotationviewwidget.cpp#L99) some of those settings. Notice that I register QList<int> as a meta-type (using qRegisterMetaTypeStreamOperators), so I believe I should be all fine and, indeed, it all works as I would expect on Windows and OS X, but not on Linux. On Linux, I get a bunch of warnings like:
QVariant::load: unable to load type 1038.
QVariant::load: unable to load type 1038.
QVariant::save: unable to save type 'QList<int>' (type id: 1038).
QVariant::save: unable to save type 'QList<int>' (type id: 1038).
QVariant::load: unable to load type 1038.
QVariant::load: unable to load type 1038.
QVariant::save: unable to save type 'QList<int>' (type id: 1038).
QVariant::save: unable to save type 'QList<int>' (type id: 1038).
QVariant::load: unable to load type 1038.
QVariant::load: unable to load type 1038.
QVariant::save: unable to save type 'QList<int>' (type id: 1038).
QVariant::save: unable to save type 'QList<int>' (type id: 1038).
QVariant::load: unable to load type 1038.
QVariant::load: unable to load type 1038.
QVariant::save: unable to save type 'QList<int>' (type id: 1038).
QVariant::save: unable to save type 'QList<int>' (type id: 1038).
QVariant::load: unable to load type 1038.
QVariant::load: unable to load type 1038.
QVariant::save: unable to save type 'QList<int>' (type id: 1038).
QVariant::save: unable to save type 'QList<int>' (type id: 1038).
QVariant::load: unable to load type 1038.
QVariant::load: unable to load type 1038.
QVariant::save: unable to save type 'QList<int>' (type id: 1038).
QVariant::save: unable to save type 'QList<int>' (type id: 1038).
QVariant::load: unable to load type 1038.
QVariant::load: unable to load type 1038.
Just out of curiosity, I thought I would try loading/saving my settings in a different way by using QVariantList. Thus, for loading my settings, I have something like:
void CellmlAnnotationViewWidget::loadSettings(QSettings *pSettings)
{
// Retrieve the sizes of our editing widget and of its metadata details
// Note: we would normally do this in CellmlAnnotationViewEditingWidget, but
// we have one instance of it per CellML file and we want to share
// some information between the different instances, so we have to do
// it here instead...
QVariantList defaultEditingWidgetSizes = QVariantList() << 0.25*qApp->desktop()->screenGeometry().width()
<< 0.75*qApp->desktop()->screenGeometry().width();
QVariantList defaultMetadataDetailsWidgetSizes = QVariantList() << 0.25*qApp->desktop()->screenGeometry().height()
<< 0.25*qApp->desktop()->screenGeometry().height()
<< 0.50*qApp->desktop()->screenGeometry().height();
QVariantList editingWidgetSizes = pSettings->value(SettingsCellmlAnnotationViewEditingWidgetSiz es, defaultEditingWidgetSizes).toList();
QVariantList metadataDetailsWidgetSizes = pSettings->value(SettingsCellmlAnnotationViewMetadataDetailsW idgetSizes, defaultMetadataDetailsWidgetSizes).toList();
foreach (const QVariant &editingWidgetSize, editingWidgetSizes)
mEditingWidgetSizes << editingWidgetSize.toInt();
foreach (const QVariant &metadataDetailsWidgetSize, metadataDetailsWidgetSizes)
mMetadataDetailsWidgetSizes << metadataDetailsWidgetSize.toInt();
}
while for saving them, I have something like:
void CellmlAnnotationViewWidget::saveSettings(QSettings *pSettings) const
{
// Keep track of the sizes of our editing widget and of its metadata details
QVariantList editingWidgetSizes = QVariantList();
QVariantList metadataDetailsWidgetSizes = QVariantList();
foreach (const int &editingWidgetSize, mEditingWidgetSizes)
editingWidgetSizes << editingWidgetSize;
foreach (const int &metadataDetailsWidgetSize, mMetadataDetailsWidgetSizes)
metadataDetailsWidgetSizes << metadataDetailsWidgetSize;
pSettings->setValue(SettingsCellmlAnnotationViewEditingWidget Sizes, editingWidgetSizes);
pSettings->setValue(SettingsCellmlAnnotationViewMetadataDetai lsWidgetSizes, metadataDetailsWidgetSizes);
}
Now, the interesting bit is that... it works on Windows, OS X and... also Linux! So, could it be that I have just come across a bug with Qt (5.2.1) on Linux?...
Whatever the case, even though using QVariantList does indeed 'fixes' my problem, I would rather use my original approach, if possible (I find 'cleaner'). This aside, I am curious as what I have done wrong, if anything, in my original approach. Anyone?
Cheers, Alan.