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.

有帮助吗?

解决方案

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 (&).

其他提示

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

qRegisterMetaType<QWebElement>("myElement");
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top