QObject::connect: Cannot queue arguments of type 'QVector<int>'

25,498

Solution 1

When you register the QVector, does your call look like this?

qRegisterMetaType<QVector<int> >("QVector<int>");

Once you make this call, you should be able to emit the QVector type over queued connections.

If I register QVector I can't dissconnect this signal and the signal is emited.

Registering a metatype shouldn't prevent you from disconnecting a signal. It just allows you to queue types that aren't already registered with the meta system.

Solution 2

Most of the time, errors which look like this seem to be a result of mixing up threads, and specifically with this one, in my (limited) experience, a result of attempting to manipulate GUI elements "held" in the GUI thread using commands run a worker QThread.

I say "held" because quite often you get a complaint/error/crash saying something like "QObject: Cannot create children for a parent that is in a different thread." (i.e. the GUI thread).

The solution: from a non-GUI QThread ALWAYS communicate with GUI elements using signals and slots.

Share:
25,498
John Smith
Author by

John Smith

Updated on August 30, 2021

Comments

  • John Smith
    John Smith over 2 years

    I have some problems with Qt. I have a class with a signal who's parameters are strings, and a slot. I'm connecting the signal to the slot in the class constructor. Also, I'm creating a thread in the class constructor. The thread reads data from a server and updates the UI(emits the UpdateMe signal). This is how I connect the signal to the slot:

                 QObject::connect(this, SIGNAL(UpdateMe(string, string)), this, SLOT(ModifyUI(string, string))); 
    

    I have a QTreeWidget with some file names. When I rename a file I notify the server and the server notifies the other clients. When I connect a single client there is no problem, but when I connect more than one client a problem appears: when I notify the server from the second client(when I write into the socket) the following error appears:

                 QObject::connect: Cannot queue arguments of type 'QVector<int>'
    

    I tried to register QVector with qRegisterMetaType but I also have a signal that is emited when I modify an QTreeWidgetItem(when I rename the item, for example) and I need to dissconnect this signal when I want to change the item's text. If I register QVector I can't dissconnect this signal and the signal is emited.

  • John Smith
    John Smith over 11 years
    Yes, but I don't emit QVector type. I emit string type. threadData->GetMainUI()->EmitUpdateMe(option, message);
  • John Smith
    John Smith over 11 years
    And that is what I'm doing in the ModifyUI slot: QObject::disconnect(this->filesTreeWidget, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(OnItemChanged_filesTreeWidget(QTreeWidgetItem*,int))); item->setText(0, QString::fromStdString(newFilename)); QObject:: connect(this->filesTreeWidget, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(OnItemChanged_filesTreeWidget(QTreeWidgetItem*,int)), Qt::QueuedConnection);
  • John Smith
    John Smith over 11 years
    I register QVector<int> like you said but if I register it the dissconect don't work. When I change item's text the itemChanged signal is emited and the OnItemChanged_filesTreeWidget slot is called.
  • John Smith
    John Smith over 11 years
    I couldn't answer to my question because I have less than 10 reputation points. That's why I wrote the code in comments.
  • Jacob Robbins
    Jacob Robbins over 11 years
    I'm having a hard time following what's going on. If you expand your question with more code, maybe I can help. It isn't at all clear what's going on. You should be able to edit your own question, right?
  • John Smith
    John Smith over 11 years
    It's working. The signal was not emited in the thread handler. Thank you for help!
  • Jacob Robbins
    Jacob Robbins over 11 years
    Where did you expand the code? The question looks exactly the same as it did when I made the comment. You have one line of actual code, and it doesn't seem to have anything to do with emitting a signal in a handler thread (none of that was shown in the question). The lines you added as a comment don't add anything at all on their own. Basically, the question needs more context. It seems you've found your problem, so it doesn't matter now.
  • ulatekh
    ulatekh over 2 years
    So strange...I got this error trying to emit a completely stock QAbstractItemModel::dataChanged. Wonder why qRegisterMetaType wasn't called for QVector<int> if Qt (5.15.2) is using that internally?