Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 655
John Smith Avatar asked Jan 26 '13 20:01

John Smith


2 Answers

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.

like image 152
Jacob Robbins Avatar answered Nov 05 '22 06:11

Jacob Robbins


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.

like image 2
mike rodent Avatar answered Nov 05 '22 05:11

mike rodent