Results 1 to 4 of 4

Thread: QColor vector in QSettings

  1. #1
    Join Date
    Nov 2011
    Posts
    14
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4 Qt Jambi
    Platforms
    MacOS X Windows

    Default QColor vector in QSettings

    Hi everyone!

    I want to save std::vector<QColor> ColorVector in QSettings. Tried a simple way:

    Qt Code:
    1. QSettings settings;
    2. settings.beginGroup("ColorConfigurationWidget");
    3. settings.setValue("currentColorVector", ColorVector);
    4. settings.endGroup();
    To copy to clipboard, switch view to plain text mode 

    But QSettings doesn't work with vectors, I guess.. The size of ColorVector is not fixed.
    Does anyone know how to handle this problem?

    Thank you!

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QColor vector in QSettings

    You should user Array not Group, see example
    Qt Code:
    1. std::vector<QColor> ColorVector;
    2. QSettings settings;
    3.  
    4. settings.beginWriteArray("ColorVector");
    5. for(unsigned int i = 0; i < ColorVector.size(); i++)
    6. {
    7. settings.setArrayIndex(i);
    8. settings.setValue("QColor", ColorVector.at(i));
    9. }
    10. settings.endArray();
    11. settings.sync();
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. The following user says thank you to Santosh Reddy for this useful post:

    Mint87 (24th January 2013)

  4. #3
    Join Date
    Nov 2011
    Posts
    14
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4 Qt Jambi
    Platforms
    MacOS X Windows

    Default Re: QColor vector in QSettings

    Thanks a lot, Santosh!

  5. #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: QColor vector in QSettings

    Since QColor can fit into QVariant, you should (not sure, didn't test) be able to just use QVariantList for your color settings and save the list directly:

    Qt Code:
    1. QSettings settings;
    2. QVariantList colorList = myColorList();
    3. settings.setValue("currentColorVector", colorList);
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Copying vector of pointers to another vector
    By Momergil in forum Newbie
    Replies: 12
    Last Post: 24th September 2011, 22:09
  2. Replies: 1
    Last Post: 14th January 2011, 11:57
  3. vector of vector and computes
    By mickey in forum General Programming
    Replies: 1
    Last Post: 15th May 2008, 12:47
  4. insert in a vector of vector
    By mickey in forum General Programming
    Replies: 3
    Last Post: 6th March 2007, 08:45
  5. vector of vector size
    By mickey in forum General Programming
    Replies: 5
    Last Post: 13th February 2007, 15:59

Tags for this Thread

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.