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. Can I get the real type of QVariant params?

Can I get the real type of QVariant params?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 409 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.
  • MihanM Offline
    MihanM Offline
    Mihan
    wrote on last edited by
    #1

    I want to send a QVariant param (event it's a struct) by a signal, also when it is sent to a slot by a signal, the slot can get the type from this param. How can I achieve.
    I have a fool idea that I add a QString to descript the type, or use an enum of type.
    Could you give me some suggestions?

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      Register your cutom type with the Meta-Object system using https://doc.qt.io/qt-5/qmetatype.html#qRegisterMetaType-1, save the return integer then you can use QVariant::userType() to check if the variant contains your custom type or not

      "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
      4
      • MihanM Offline
        MihanM Offline
        Mihan
        wrote on last edited by
        #3

        Oh, thank you so much !
        BTW, can I connect a normal signal of a widget and a slot with a QVariant param?

        Pl45m4P 1 Reply Last reply
        0
        • MihanM Mihan

          Oh, thank you so much !
          BTW, can I connect a normal signal of a widget and a slot with a QVariant param?

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by Pl45m4
          #4

          @Mihan said in Can I get the real type of QVariant params?:

          BTW, can I connect a normal signal of a widget and a slot with a QVariant param?

          Sure you can.

          connect(myclass, &MyClass::mySignal, this, &QMainWindow::DoSomething);
          

          where mySignal

          void mySignal(QVariant val);
          

          and DoSomething slot:

          void QMainWindow::DoSomething(QVariant val)
          {
                // Do something with Variant val
          }
          

          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          1 Reply Last reply
          1

          • Login

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