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] QVariant and custom types
Forum Updated to NodeBB v4.3 + New Features

[Solved] QVariant and custom types

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 5.3k Views 1 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.
  • D Offline
    D Offline
    DSav
    wrote on last edited by
    #1

    I’ve got a class (pubic default and copy constructors and destructor are implemented) named, say, SomeClass and SomeClassList that is a typedef for QList<SomeClass>. Stream operators are implemented for SomeClass and both SomeClass and SomeClassList are registered using Q_DECLARE_METATYPE and qRegisterMetaTypeStreamOperators.

    QSettings instance is used to store SomeClassList instances. I faced the following issue:
    @
    SomeClassList defaultList;

    // ....

    // assuming that defaultList contains N SomeClass instances:
    QVariant variantList = QVariant::fromValue(defaultList);
    // here list will contain N SomeClass instances, everything’s fine:
    SomeClassList list = variantList.value<SomeClassList>();

    // But, if there’s nothing to read from "somelist", anotherList gets empty,
    // nothing’s copied from variantList
    SomeClassList anotherList = settings->value("somelist", variantList).value<SomeClassList>();
    @

    What can be the reason for such a behaviour?

    1 Reply Last reply
    0
    • L Offline
      L Offline
      loladiro
      wrote on last edited by
      #2

      Very odd. Here are some hints as to what you can investigate:

      Try QSettings::contains() to see whether or nor QSettings thinks the value is set

      Try comparing the return value from settings->value() with you original list (i.e. don't use the conversion back to you original class, yet.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DSav
        wrote on last edited by
        #3

        Actually value "somelist" was set to nothing in settings, that’s why default value wasn’t loaded. So the problem is where value is saved, not read; steps to reproduce the problem were simply incorrect.

        So, nomore questions from my side, thanks.

        1 Reply Last reply
        0
        • L Offline
          L Offline
          loladiro
          wrote on last edited by
          #4

          Ok, that's what I suspected.

          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