Setting a webelement in a thread using signal-slot doesn't behave as expected
-
Hi experts,
It's very simple question actually but I couldn't figure out why it is behaving like this.
I have a QWebElement variable in a thread and I set its value from the main thread using signal-slot.
The variable in the thread is:
@QWebElement currentElement;@I set the value of this element using signal-slot like the following:
@
//In thread called 'insExtractor'
...
public slots:
void setCurrentElement(QWebElement aElement);...
//In main thread:
signals:
void sgSetElement(QWebElement aElement);//The connection between the signal and slot:
connect(this, SIGNAL(sgSetElement(QWebElement)), insExtractor, SLOT(setCurrentElement(QWebElement)));
@The problem is that, when I call, for example,
@QWebElement myElement = currentElement.findFirst("form[id='submitForm']");@After this call, I see that myElement comes as NULL in the slot function in the thread.
However, if I do it where I emit the signal in the main thread, I see that 'submitForm' is found in the WebElement, threrefore myElement doesn't return NULL.So basically, before emitting the signal I get what I want (a form in the webelement) but the same call doesn't return the the form called'submitForm' if I call it in the slot function. I printed the toPlainText() of the QWebElements before emitting the signal and after emitting the signal and they look exactly the same. So, the slot receives something.
Could anyone give me some ideas what could be wrong?Actually I am pretty sure that it is QWebElement related since I do the same thing with the current url and it works ok. I see that QWebElement has clone function. I have tried it but the result is the same.
-
So weird,
I have now called the
@QWebElement myElement = currentElement.findFirst("form[id='submitForm']");@in the slot function where I set the QWebElement declared in the thread class and I received NOT NULL, which is good. But the issue now is that if I call the same line in somewhere another function again in the thread class, it returns NULL. So weird.