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. "Cannot queue arguments of type" even after call qRegisterMetaType()
QtWS25 Last Chance

"Cannot queue arguments of type" even after call qRegisterMetaType()

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 10.2k 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.
  • chuanlauC Offline
    chuanlauC Offline
    chuanlau
    wrote on last edited by
    #1

    I need to use signal/slot to transmit data from a QThread to the main thread, the data is of type QMap<int, QVector<MyType>>.
    I use a typedef to describe the data structure:

    typedef QMap<int, QVector<MyType>> CompType;
    

    And I try to register it almost everywhere, including in the constructor of the QThread

    MyThread::MyThread()
    {
        qRegisterMetaType<CompType>("CompType");
    }
    

    and in the constructor of the class in which start the thread

    ThreadStarter::ThreadStarter()
    {
        qRegisterMetaType<CompType>("CompType");
    }
    

    even in the main() function

    int main(int argc, char *argv[])
    {
    	qRegisterMetaType<CompType>("CompType");
    	QCoreApplication::addLibraryPath("./");
    	QApplication a(argc, argv);
    	PointAnalysis w;
    	w.show();
    	return a.exec();
    }
    

    But when I emit a signal at the end of thread run()

    CompType data;
    /* Fill in the data */
    emit threadDone(data);
    

    There is a such line in the Debug log:
    QObject::connect: Cannot queue arguments of type 'Part_Candidates'
    (Make sure 'Part_Candidates' is registered using qRegisterMetaType().)

    The signal and the slot are connect just below the thread is created, and I'm sure the parameters of them are definately the same as CompType.

    Anyone can tell me what to do?

    beeckscheB 1 Reply Last reply
    1
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      @chuanlau said:

      Hi

      MyType

      Is that type also registered?

      Also Part_Candidates is
      QMap<int, QVector<MyType>> Part_Candidates ?

      chuanlauC 1 Reply Last reply
      0
      • mrjjM mrjj

        @chuanlau said:

        Hi

        MyType

        Is that type also registered?

        Also Part_Candidates is
        QMap<int, QVector<MyType>> Part_Candidates ?

        chuanlauC Offline
        chuanlauC Offline
        chuanlau
        wrote on last edited by
        #3

        @mrjj Sorry, Part_Candidates is just CompType. It is the name in my original code. I change its name to CompType in the post. I didn't register MyType. I will try and let you know the result.

        mrjjM 1 Reply Last reply
        0
        • chuanlauC chuanlau

          @mrjj Sorry, Part_Candidates is just CompType. It is the name in my original code. I change its name to CompType in the post. I didn't register MyType. I will try and let you know the result.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @chuanlau
          np.
          I think i recall something about a post with QList and same issue and answer was to register the
          type in the list, not the list itself.

          chuanlauC 1 Reply Last reply
          0
          • chuanlauC chuanlau

            I need to use signal/slot to transmit data from a QThread to the main thread, the data is of type QMap<int, QVector<MyType>>.
            I use a typedef to describe the data structure:

            typedef QMap<int, QVector<MyType>> CompType;
            

            And I try to register it almost everywhere, including in the constructor of the QThread

            MyThread::MyThread()
            {
                qRegisterMetaType<CompType>("CompType");
            }
            

            and in the constructor of the class in which start the thread

            ThreadStarter::ThreadStarter()
            {
                qRegisterMetaType<CompType>("CompType");
            }
            

            even in the main() function

            int main(int argc, char *argv[])
            {
            	qRegisterMetaType<CompType>("CompType");
            	QCoreApplication::addLibraryPath("./");
            	QApplication a(argc, argv);
            	PointAnalysis w;
            	w.show();
            	return a.exec();
            }
            

            But when I emit a signal at the end of thread run()

            CompType data;
            /* Fill in the data */
            emit threadDone(data);
            

            There is a such line in the Debug log:
            QObject::connect: Cannot queue arguments of type 'Part_Candidates'
            (Make sure 'Part_Candidates' is registered using qRegisterMetaType().)

            The signal and the slot are connect just below the thread is created, and I'm sure the parameters of them are definately the same as CompType.

            Anyone can tell me what to do?

            beeckscheB Offline
            beeckscheB Offline
            beecksche
            wrote on last edited by
            #5

            @chuanlau

            In my case i had to call: Q_DECLARE_METATYPE(Type) see http://doc.qt.io/qt-5/qmetatype.html#Q_DECLARE_METATYPE

            chuanlauC 1 Reply Last reply
            2
            • mrjjM mrjj

              @chuanlau
              np.
              I think i recall something about a post with QList and same issue and answer was to register the
              type in the list, not the list itself.

              chuanlauC Offline
              chuanlauC Offline
              chuanlau
              wrote on last edited by
              #6

              @mrjj Only registering MyType doesn't help. beecksche is right, I should call Q_DECLARE_METATYPE. Thank you all the same.

              1 Reply Last reply
              1
              • beeckscheB beecksche

                @chuanlau

                In my case i had to call: Q_DECLARE_METATYPE(Type) see http://doc.qt.io/qt-5/qmetatype.html#Q_DECLARE_METATYPE

                chuanlauC Offline
                chuanlauC Offline
                chuanlau
                wrote on last edited by
                #7

                @beecksche Yes! You are right! This time it works. Thank you!

                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