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. Register QMetaType with specific ID?
Qt 6.11 is out! See what's new in the release blog

Register QMetaType with specific ID?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 545 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.
  • A Offline
    A Offline
    angela2016
    wrote on last edited by
    #1

    Hi all,

    I have a custom struct that I want to use as a QVariant, convert to a string which gets saved in a database, from which it should be restored from the saved string. In order to restore the QVariant with the correct type, I also save the type id in the database.

    Right now I register it with

    int vVariantRangeID = qRegisterMetaType<AFilterItem::VariantRange>();
    

    and supposedly the ID will always be the same as long as I have the same number and order of qRegisterMetaTypes starting with 65536, but I'd like to be sure and define a specific ID, so that for example it will always be 65600. Is that possible?

    Thanks.

    Best wishes,
    Angela

    1 Reply Last reply
    0
    • GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #2

      If you have a QVariant you can use a QDataStream on a QByteArray to serialize/deserialize it.

      Note that internally it uses the type name and not the type id to differentiate between types (for user types).

      A 1 Reply Last reply
      0
      • GrecKoG GrecKo

        If you have a QVariant you can use a QDataStream on a QByteArray to serialize/deserialize it.

        Note that internally it uses the type name and not the type id to differentiate between types (for user types).

        A Offline
        A Offline
        angela2016
        wrote on last edited by
        #3

        @GrecKo Yes, but I'd like it to be somewhat readable and manually editable.

        But I suppose I could save the type name instead of the id. Thanks.

        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