Domanda

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.

È stato utile?

Soluzione

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

Altri suggerimenti

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

qRegisterMetaType<QWebElement>("myElement");
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top