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. [Solved] How to store QList<QSharedPointer<Phase>> in QSettings
Forum Updated to NodeBB v4.3 + New Features

[Solved] How to store QList<QSharedPointer<Phase>> in QSettings

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.2k Views 2 Watching
  • 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.
  • S Offline
    S Offline
    sharethl
    wrote on last edited by sharethl
    #1

    Object only has 2 int properties.
    One way I tried is convert QList<> to QVariant, but got this error
    QVariant::save: unable to save type 'QList<QSharedPointer<Phase>>' (type id: 1060).
    I do have Registered the class and implemented QDataStream

    Q_DECLARE_METATYPE( QSharedPointer<Phase>)
    QDataStream & operator << (QDataStream &out, const QSharedPointer<Phase> &phase);
    QDataStream & operator >> (QDataStream &in, QSharedPointer<Phase> &phase);
    
    setting.setValue("Phase", QVariant::fromValue(QSharedPointer<Phase>(phase));
    

    Second way should work, convert Phase properties to QStringList, and save this QStringList, later decode it back.

    Any one know why first way doesn't work?

    Thanks

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      You also need to register the type and its stream operators, as described in the docs:

      qRegisterMetaType<QSharedPointer<Phase>>("Phase");
      qRegisterMetaTypeStreamOperators<QSharedPointer<Phase>>("Phase");
      
      S 1 Reply Last reply
      0
      • Chris KawaC Chris Kawa

        You also need to register the type and its stream operators, as described in the docs:

        qRegisterMetaType<QSharedPointer<Phase>>("Phase");
        qRegisterMetaTypeStreamOperators<QSharedPointer<Phase>>("Phase");
        
        S Offline
        S Offline
        sharethl
        wrote on last edited by
        #3

        @Chris-Kawa Thanks, That works!

        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