Dundar
Dundar

Reputation: 1249

Qt signal from thread causes error

I have a thread from which I need to send a signal with a parameter to a pointer like the following:

connect(insThread, SIGNAL(sgGetCurrentElement(QWebElement&)), this, SIGNAL(sgGetCurrentElement(QWebElement&)));

where insThread is the thred. However I got error:

QObject::connect: Cannot queue arguments of type ‘QWebElement&’ (Make sure ‘QWebElement&’ is registered using qRegisterMetaType().)

I already know that I need to use qRegisterMetaType but I couldn't figure out how I can construct it. I tried

qRegisterMetaType<QWebElement&>("myElement");

but failed. How can I solve this?

Thanks.

Upvotes: 1

Views: 82

Answers (2)

1337user
1337user

Reputation: 56

I assume you are trying to register the QWebElement with a reference (&) because have prototyped the slot to take QWebElement as a reference, but this is not a very good idea if you're posting the signal from one thread to another, see here. Anyway, as Laszlo pointed out, you have to register the base type, it is meaningless to register the type with the reference tag (&).

Upvotes: 1

L&#225;szl&#243; Papp
L&#225;szl&#243; Papp

Reputation: 53215

I am not sure why you are trying to register it with &, but do it without that as follows:

qRegisterMetaType<QWebElement>("myElement");

Upvotes: 0

Related Questions