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()
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 10.2k 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.
  • C Offline
    C Offline
    chuanlau
    wrote on 14 Jun 2016, 08:15 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?

    B 1 Reply Last reply 14 Jun 2016, 08:33
    1
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 14 Jun 2016, 08:21 last edited by mrjj
      #2

      @chuanlau said:

      Hi

      MyType

      Is that type also registered?

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

      C 1 Reply Last reply 14 Jun 2016, 08:23
      0
      • M mrjj
        14 Jun 2016, 08:21

        @chuanlau said:

        Hi

        MyType

        Is that type also registered?

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

        C Offline
        C Offline
        chuanlau
        wrote on 14 Jun 2016, 08:23 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.

        M 1 Reply Last reply 14 Jun 2016, 08:27
        0
        • C chuanlau
          14 Jun 2016, 08:23

          @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.

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 14 Jun 2016, 08:27 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.

          C 1 Reply Last reply 14 Jun 2016, 08:58
          0
          • C chuanlau
            14 Jun 2016, 08:15

            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?

            B Offline
            B Offline
            beecksche
            wrote on 14 Jun 2016, 08:33 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

            C 1 Reply Last reply 14 Jun 2016, 10:34
            2
            • M mrjj
              14 Jun 2016, 08:27

              @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.

              C Offline
              C Offline
              chuanlau
              wrote on 14 Jun 2016, 08:58 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
              • B beecksche
                14 Jun 2016, 08:33

                @chuanlau

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

                C Offline
                C Offline
                chuanlau
                wrote on 14 Jun 2016, 10:34 last edited by
                #7

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

                1 Reply Last reply
                0

                1/7

                14 Jun 2016, 08:15

                • Login

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