Skip to content

Commit bb9e277

Browse files
authored
Do not use communicators from other threads (#1909)
1 parent dc110b6 commit bb9e277

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

plugins/robots/utils/src/robotCommunication/robotCommunicator.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,20 @@ RobotCommunicator::~RobotCommunicator()
3737

3838
void RobotCommunicator::send(QObject *addressee, const QByteArray &buffer, const unsigned responseSize)
3939
{
40-
mRobotCommunicationThreadObject->send(addressee, buffer, responseSize);
40+
auto blockingConnectionType = mRobotCommunicationThreadObject->thread() == QThread::currentThread()
41+
? Qt::DirectConnection : Qt::BlockingQueuedConnection;
42+
QMetaObject::invokeMethod(mRobotCommunicationThreadObject.get(), [&](){
43+
mRobotCommunicationThreadObject->send(addressee, buffer, responseSize);},
44+
blockingConnectionType);
4145
}
4246

4347
void RobotCommunicator::send(const QByteArray &buffer, const unsigned responseSize, QByteArray &outputBuffer)
4448
{
45-
mRobotCommunicationThreadObject->send(buffer, responseSize, outputBuffer);
49+
auto blockingConnectionType = mRobotCommunicationThreadObject->thread() == QThread::currentThread()
50+
? Qt::DirectConnection : Qt::BlockingQueuedConnection;
51+
QMetaObject::invokeMethod(mRobotCommunicationThreadObject.get(), [&](){
52+
mRobotCommunicationThreadObject->send(buffer, responseSize, outputBuffer);},
53+
blockingConnectionType);
4654
}
4755

4856
void RobotCommunicator::connect()

0 commit comments

Comments
 (0)