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. Qsettings trouble
Forum Update on Monday, May 27th 2025

Qsettings trouble

Scheduled Pinned Locked Moved Unsolved General and Desktop
qsettings
2 Posts 2 Posters 777 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.
  • D Offline
    D Offline
    dijnr
    wrote on 7 May 2016, 13:30 last edited by
    #1

    Hi, I'm having some problem using Qsetting library..
    I have my application and I must save some variables , so that if you reopen the program you don't have to restart from zero.

    enum otherdata{YES,SURE,OK,OTHER,STUFF,NO};
    std::pair<QString,int> mydata[3];
    std::vector<MyClass*> myclass;

    I wasn't able to make it work with this kind of data. Any Hints or Solution?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on 7 May 2016, 14:31 last edited by Chris Kawa 5 Jul 2016, 22:38
      #2

      Hi, welcome to the forum.

      QSettings operates on QVariant to store/read the data. You need to make your types known to Qt's type system for them to be used as QVariant and they need to have a registered streaming operators to be serialized.
      See these docs for more info: Q_DECLARE_METATYPE, Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE, qRegisterMetaTypeStreamOperators.

      There's also a problem with your last type. Don't save pointers (MyClass*). After your app restart they would point to garbage. Your stream operator for that container should save the actual objects data and recreate the object from that data on load.

      1 Reply Last reply
      1

      2/2

      7 May 2016, 14:31

      • Login

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