Qt signals/slot QThread > GUI with lambdas functions
-
Hello,
I use Qt6.4 on Windows and I have a mistake from a signal/slot error.I have a QThread send a signal to my main GUI to show an error message :
connect(m_uploaderServer, &PortalUploader::error, [this](const QString & message) { m_labelError->setText(message); m_labelError->show(); });But when the signals is emitted, I have this error :
[09/01/2023-13:46:33.439] QBasicTimer::start: Timers cannot be started from another thread [09/01/2023-13:46:33.439] QObject::setParent: Cannot set parent, new parent is in a different threadI don't have this error if my QLabel is always visible (not use show() function).
I don't understand this error. If I call directly from my thead the show() function, I understand why it is not correct, but in this case ?? Do I not use correctly signal/slot mechanism ? Somebody knows why ?
Thanks
[EDIT] : it seems that the lambda function that makes problem. When I use a member slot function, it's OK. Somebody knows why ?
[EDIT2] I found the answer. In documentation, it says:
the lambda will be called in the thread of the event loop of the object used as context).I keep my post, it can help someone else ...
-
Hello,
I use Qt6.4 on Windows and I have a mistake from a signal/slot error.I have a QThread send a signal to my main GUI to show an error message :
connect(m_uploaderServer, &PortalUploader::error, [this](const QString & message) { m_labelError->setText(message); m_labelError->show(); });But when the signals is emitted, I have this error :
[09/01/2023-13:46:33.439] QBasicTimer::start: Timers cannot be started from another thread [09/01/2023-13:46:33.439] QObject::setParent: Cannot set parent, new parent is in a different threadI don't have this error if my QLabel is always visible (not use show() function).
I don't understand this error. If I call directly from my thead the show() function, I understand why it is not correct, but in this case ?? Do I not use correctly signal/slot mechanism ? Somebody knows why ?
Thanks
[EDIT] : it seems that the lambda function that makes problem. When I use a member slot function, it's OK. Somebody knows why ?
[EDIT2] I found the answer. In documentation, it says:
the lambda will be called in the thread of the event loop of the object used as context).I keep my post, it can help someone else ...
@OPit said:
the lambda will be called in the thread of the event loop of the object used as context
A simple fix is to add that context i.e.
connect(m_uploaderServer, &PortalUploader::error, m_labelError, [this](... ^ here