Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to append different struct types to a QList?
Forum Updated to NodeBB v4.3 + New Features

How to append different struct types to a QList?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
2 Posts 2 Posters 577 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.
  • S Offline
    S Offline
    Sriu1
    wrote on last edited by
    #1

    I have different structures I want to append them to a QList can this be done using QVarient?Please suggest

    raven-worxR 1 Reply Last reply
    0
    • S Sriu1

      I have different structures I want to append them to a QList can this be done using QVarient?Please suggest

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @Sriu1

      register your custom types using Q_DECLARE_METATYPE

      struct MyStruct1 {
         ...
      };
      Q_DECLARE_METATYPE(MyStruct1)
      
      struct MyStruct2 {
         ...
      };
      Q_DECLARE_METATYPE(MyStruct2)
      
      QVariantList list;
          list << QVariant::fromValue<MyStruct1>( MyStruct1() );
          list << QVariant::fromValue<MyStruct2>( MyStruct2() )
      

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      3

      • Login

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