Results 1 to 4 of 4

Thread: Saving a single value QVariantlist to QSettings(ini format)

  1. #1
    Join Date
    Aug 2011
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Saving a single value QVariantlist to QSettings(ini format)

    Good day.

    I have an application that has its own settings file, which I generate with Qt and load with Qt. I am using QSettings::IniFormat, because i want to be able to change these settings by hand if needed.
    Qt Code:
    1. new QSettings("myconfig.cfg", QSettings::IniFormat);
    To copy to clipboard, switch view to plain text mode 
    It works like a charm, the only problem is when i do a setValue() with a QVariantList that only has one value.
    My QVariantLists QVariants are all QRects.

    e.g: When the list contains two rectangles,
    Qt Code:
    1. QList<QRect> testList;
    2. testList.append(QRect(0,0,1,1));
    3. testList.append(QRect(1,1,1,1));
    4.  
    5. QList<QVariant> variantList;
    6. foreach(QRect rect, testList)
    7. {
    8. variantList.append(rect);
    9. }
    10.  
    11. m_settings->setValue(QString("rememberRectList"), variantList);
    To copy to clipboard, switch view to plain text mode 

    the configuration file's entry looks ok:
    rememberRectList=@Rect(0 0 1 1), @Rect(1 1 1 1)
    But, when the list contains only a single entry:
    Qt Code:
    1. ...
    2. QList<QRect> testList;
    3. testList.append(QRect(0,0,1,1));
    4.  
    5. QList<QVariant> variantList;
    6. foreach(QRect rect, testList)
    7. {
    8. variantList.append(rect);
    9. }
    10.  
    11. m_settings->setValue(QString("rememberRectList"), variantList);
    12. ...
    To copy to clipboard, switch view to plain text mode 

    I get this:
    rememberRectList=@Variant(\0\0\0\t\0\0\0\x1\0\0\0\ x13\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0)
    I am wondering if this is a bug or am I doing something wrong.

    Thank you.

  2. #2
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Saving a single value QVariantlist to QSettings(ini format)

    Are you saying that you are not able to retrieve the QVariantList if there is just one value in it. Or you are just intrigued by the way it looks in the file?

  3. #3
    Join Date
    Aug 2011
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Saving a single value QVariantlist to QSettings(ini format)

    No, no, the list retrieves fine, the only problem is the way it looks in the file - it's not human readable which makes it not human writable. Typing a couple of @Rect(x y w h) is easy and it would be nice if a single value also looked the same way.

    I'm probably going to check for single values and just save them as a single QRect, which looks right in the file, or just implement a QStringList with custom syntax to generate these rects.

  4. #4
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Saving a single value QVariantlist to QSettings(ini format)

    Don't you need to keep the xml format if to be made user readable?
    Besides as soon as a stream operator of any class not hand crafted by you is used, it is bound to put in all kind of things including like QByteArray. That definitely is not human readable.
    So you cannot rely upon datastream operators out of the box. Going into datastream function of QVariantList might be a good idea to know exactly what happens. But whatever happens is its behaviour and you will have to find your way around it by handcrafting your own operator overload function.

Similar Threads

  1. OSX QSettings IniFormat SystemScope saving inside the bundle
    By JoZCaVaLLo in forum Qt Programming
    Replies: 1
    Last Post: 27th April 2012, 10:21
  2. Replies: 0
    Last Post: 20th April 2012, 16:16
  3. Replies: 1
    Last Post: 25th May 2011, 19:25
  4. Replies: 1
    Last Post: 14th January 2011, 11:57
  5. Saving image in jpeg format failed
    By febil in forum Qt Programming
    Replies: 5
    Last Post: 23rd April 2009, 11:33

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.