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

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.
  • dijnrD Offline
    dijnrD Offline
    dijnr
    wrote on 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
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #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

      • Login

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