Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Serialising QList<int> with QSettings

Serialising QList<int> with QSettings

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    agarny
    wrote on last edited by
    #1

    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:

    bq. 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(SettingsCellmlAnnotationViewEditingWidgetSizes, defaultEditingWidgetSizes).toList();
    QVariantList metadataDetailsWidgetSizes = pSettings->value(SettingsCellmlAnnotationViewMetadataDetailsWidgetSizes, defaultMetadataDetailsWidgetSizes).toList();
    
    foreach (const QVariant &editingWidgetSize, editingWidgetSizes)
        mEditingWidgetSizes << editingWidgetSize.toInt();
    
    foreach (const QVariant &metadataDetailsWidgetSize, metadataDetailsWidgetSizes)
        mMetadataDetailsWidgetSizes <&lt; 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 &lt;&lt; editingWidgetSize;
    
    foreach (const int &metadataDetailsWidgetSize, mMetadataDetailsWidgetSizes)
        metadataDetailsWidgetSizes <&lt; metadataDetailsWidgetSize;
    
    pSettings-&gt;setValue(SettingsCellmlAnnotationViewEditingWidgetSizes, editingWidgetSizes);
    pSettings->setValue(SettingsCellmlAnnotationViewMetadataDetailsWidgetSizes, 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.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved