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. SIGNAL/SLOT using 'uint16_t' parameter
Forum Updated to NodeBB v4.3 + New Features

SIGNAL/SLOT using 'uint16_t' parameter

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 4.5k 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.
  • A Offline
    A Offline
    Alan B
    wrote on last edited by
    #1

    When I declare a SIGNAL/SLOT pair with a single uint16_t parameter I get the following error message :-

    QObject::connect: Cannot queue arguments of type 'uint16_t'.

    Using an int parameter works fine.

    It looks like I need to register the uint16_t type somewhere but I'm unsure where to do this. I tried putting a Q_DECLARE_METATYPE() in mainwindow.h as shown below but this didn't work.

    namespace Ui {
    class MainWindow;
    }

    Q_DECLARE_METATYPE(uint16_t)

    class MainWindow : public QMainWindow
    {
    Q_OBJECT
    .
    .
    .

    Where should I place the Q_DECLARE_METATYPE() or am I barking up the wrong tree altogether ?

    Thanks

    Alan

    kshegunovK 1 Reply Last reply
    0
    • BjornWB Offline
      BjornWB Offline
      BjornW
      wrote on last edited by BjornW
      #2

      http://doc.qt.io/qt-5/qmetatype.html#details

      try calling

      qRegisterMetaType<uint16_t>();
      
      1 Reply Last reply
      1
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by VRonin
        #3

        _t is normally used for typedefs, if it was a typedef for unsigned short as the name suggests then it would work out of the box. this behaviour makes me think there's more behind it. what's the underlying type of uint16_t?

        "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

        kshegunovK 1 Reply Last reply
        2
        • VRoninV VRonin

          _t is normally used for typedefs, if it was a typedef for unsigned short as the name suggests then it would work out of the box. this behaviour makes me think there's more behind it. what's the underlying type of uint16_t?

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #4

          http://en.cppreference.com/w/cpp/header/cstdint

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          0
          • A Alan B

            When I declare a SIGNAL/SLOT pair with a single uint16_t parameter I get the following error message :-

            QObject::connect: Cannot queue arguments of type 'uint16_t'.

            Using an int parameter works fine.

            It looks like I need to register the uint16_t type somewhere but I'm unsure where to do this. I tried putting a Q_DECLARE_METATYPE() in mainwindow.h as shown below but this didn't work.

            namespace Ui {
            class MainWindow;
            }

            Q_DECLARE_METATYPE(uint16_t)

            class MainWindow : public QMainWindow
            {
            Q_OBJECT
            .
            .
            .

            Where should I place the Q_DECLARE_METATYPE() or am I barking up the wrong tree altogether ?

            Thanks

            Alan

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by kshegunov
            #5

            @Alan-B said in SIGNAL/SLOT using 'uint16_t' parameter:

            Where should I place the Q_DECLARE_METATYPE() or am I barking up the wrong tree altogether ?

            Nope, it's the correct tree.
            You need to put the metatype declaration in one of the header files, then you need to call qRegisterMetaType at runtime (for example in main()), just as @BjornW wrote.

            Read and abide by the Qt Code of Conduct

            VRoninV 1 Reply Last reply
            1
            • kshegunovK kshegunov

              @Alan-B said in SIGNAL/SLOT using 'uint16_t' parameter:

              Where should I place the Q_DECLARE_METATYPE() or am I barking up the wrong tree altogether ?

              Nope, it's the correct tree.
              You need to put the metatype declaration in one of the header files, then you need to call qRegisterMetaType at runtime (for example in main()), just as @BjornW wrote.

              VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by VRonin
              #6

              Tested this:

              #include <QObject>
              #include <QDebug>
              #include <cstdint>
              
              class TestObj : public QObject{
                  Q_OBJECT
                  Q_DISABLE_COPY(TestObj)
              public:
                  explicit TestObj(QObject* parent=Q_NULLPTR)
                      :QObject(parent)
                  {
                      connect(this, &TestObj::testSig,this, &TestObj::testSlo,Qt::QueuedConnection);
                      connect(this, SIGNAL(testSig(std::uint16_t)),this,SLOT(testSlo2(std::uint16_t)),Qt::QueuedConnection);
                      testSig(0);
                  }
                  Q_SIGNAL void testSig(std::uint16_t val);
                  Q_SLOT void testSlo(std::uint16_t val){qDebug() << "testSlo " << val;}
                  Q_SLOT void testSlo2(std::uint16_t val){qDebug() << "testSlo2 " << val;}
              
              };
              

              basically the solution is either use the New Signal Slot Syntax or register the metatype (I did not realise the metatype was required before as I was always testing using the pointer to method connect

              "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

              kshegunovK 1 Reply Last reply
              0
              • VRoninV VRonin

                Tested this:

                #include <QObject>
                #include <QDebug>
                #include <cstdint>
                
                class TestObj : public QObject{
                    Q_OBJECT
                    Q_DISABLE_COPY(TestObj)
                public:
                    explicit TestObj(QObject* parent=Q_NULLPTR)
                        :QObject(parent)
                    {
                        connect(this, &TestObj::testSig,this, &TestObj::testSlo,Qt::QueuedConnection);
                        connect(this, SIGNAL(testSig(std::uint16_t)),this,SLOT(testSlo2(std::uint16_t)),Qt::QueuedConnection);
                        testSig(0);
                    }
                    Q_SIGNAL void testSig(std::uint16_t val);
                    Q_SLOT void testSlo(std::uint16_t val){qDebug() << "testSlo " << val;}
                    Q_SLOT void testSlo2(std::uint16_t val){qDebug() << "testSlo2 " << val;}
                
                };
                

                basically the solution is either use the New Signal Slot Syntax or register the metatype (I did not realise the metatype was required before as I was always testing using the pointer to method connect

                kshegunovK Offline
                kshegunovK Offline
                kshegunov
                Moderators
                wrote on last edited by
                #7

                @VRonin said in SIGNAL/SLOT using 'uint16_t' parameter:

                I did not realise the metatype was required before as I was always testing using the pointer to method connect

                It's required for queued connections regardless of the connection syntax.

                Read and abide by the Qt Code of Conduct

                VRoninV 1 Reply Last reply
                0
                • kshegunovK kshegunov

                  @VRonin said in SIGNAL/SLOT using 'uint16_t' parameter:

                  I did not realise the metatype was required before as I was always testing using the pointer to method connect

                  It's required for queued connections regardless of the connection syntax.

                  VRoninV Offline
                  VRoninV Offline
                  VRonin
                  wrote on last edited by VRonin
                  #8

                  @kshegunov said in SIGNAL/SLOT using 'uint16_t' parameter:

                  It's required for queued connections regardless of the connection syntax.

                  Sorry, had to specify.

                  • connect(this, &TestObj::testSig,this, &TestObj::testSlo,Qt::QueuedConnection); works correctly
                  • connect(this, SIGNAL(testSig(std::uint16_t)),this,SLOT(testSlo2(std::uint16_t)),Qt::QueuedConnection); does not

                  so you don't need to register the typedef of a known metatype if you use the new connection. in general, of course, if you have a custom class you have to register it to work in queued connection

                  "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
                  0

                  • Login

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