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. Comparing QVariant::Type with custom registered types
Forum Updated to NodeBB v4.3 + New Features

Comparing QVariant::Type with custom registered types

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 1.1k 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
    sykac
    wrote on 24 Jul 2018, 10:20 last edited by
    #1

    Hello,

    I'm trying to implement a conversion function which looks like this:

    CustomDataType conversionFunc(QVariant::Type type)
    {
        switch (type) {
        case QVariant::Int: return CustomDataType::C_INT;
        case QVariant::Double: return CustomDataType::C_DOUBLE;
        .
        .
        .
        default: return CustomDataType::C_INVALID;
        }
    }
    

    This works fine if I don't use non Qt data types in QVariant. I would like to add a new case e.g.:

    case QVariant::Eigen::Vector3d: return CustomDataType::C_VEC3D;
    

    This won't build although I registered the type with Q_DECLARE_METATYPE(Eigen::Vector3d). Is something like this possible? If so, how? I can still compare QVariant::typeName(), but isn't there some way of doing this using enums like in the code above?

    K 1 Reply Last reply 24 Jul 2018, 10:29
    0
    • V Offline
      V Offline
      VRonin
      wrote on 24 Jul 2018, 10:25 last edited by
      #2

      https://doc.qt.io/qt-5/qvariant.html#userType

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      1
      • S sykac
        24 Jul 2018, 10:20

        Hello,

        I'm trying to implement a conversion function which looks like this:

        CustomDataType conversionFunc(QVariant::Type type)
        {
            switch (type) {
            case QVariant::Int: return CustomDataType::C_INT;
            case QVariant::Double: return CustomDataType::C_DOUBLE;
            .
            .
            .
            default: return CustomDataType::C_INVALID;
            }
        }
        

        This works fine if I don't use non Qt data types in QVariant. I would like to add a new case e.g.:

        case QVariant::Eigen::Vector3d: return CustomDataType::C_VEC3D;
        

        This won't build although I registered the type with Q_DECLARE_METATYPE(Eigen::Vector3d). Is something like this possible? If so, how? I can still compare QVariant::typeName(), but isn't there some way of doing this using enums like in the code above?

        K Offline
        K Offline
        kshegunov
        Moderators
        wrote on 24 Jul 2018, 10:29 last edited by kshegunov
        #3

        @sykac said in Comparing QVariant::Type with custom registered types:

        I registered the type with Q_DECLARE_METATYPE(Eigen::Vector3d).

        Why do you want to do that in the first place? What's the point of having an eigen vector in a QVariant?

        Read and abide by the Qt Code of Conduct

        1 Reply Last reply
        2
        • S Offline
          S Offline
          sykac
          wrote on 24 Jul 2018, 12:43 last edited by
          #4

          @kshegunov I'm using it in a generic interface - one method for passing multiple datatypes in one argument.

          @VRonin Thanks, that's what I needed.

          V 1 Reply Last reply 24 Jul 2018, 13:03
          0
          • S sykac
            24 Jul 2018, 12:43

            @kshegunov I'm using it in a generic interface - one method for passing multiple datatypes in one argument.

            @VRonin Thanks, that's what I needed.

            V Offline
            V Offline
            VRonin
            wrote on 24 Jul 2018, 13:03 last edited by
            #5

            @sykac said in Comparing QVariant::Type with custom registered types:

            one method for passing multiple datatypes in one argument

            Looks like you really want a template method instead

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            1 Reply Last reply
            1

            1/5

            24 Jul 2018, 10:20

            • Login

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