How modbus runs in other threads
-
The current method used is to have classes that use 'QModbusRtuSerialMaster' inherit QObject, which is referred to as' A 'here. Declare 'QThread * t1;' in 'class MainWindow', and then use 't1=new QThread; A.moveToThread (t1);' in the construction method. This is feasible, but if 't1' is not a pointer, using 'A.moveToThread (&t1);' will not run properly and no data will be visible on the serial port
If 'A' inherits' QRunnable 'and runs QModbusRtuSerialMaster in' run() override ', it is also abnormal.
Using QtConcurrent:: run is also abnormal, why is this
-
The current method used is to have classes that use 'QModbusRtuSerialMaster' inherit QObject, which is referred to as' A 'here. Declare 'QThread * t1;' in 'class MainWindow', and then use 't1=new QThread; A.moveToThread (t1);' in the construction method. This is feasible, but if 't1' is not a pointer, using 'A.moveToThread (&t1);' will not run properly and no data will be visible on the serial port
If 'A' inherits' QRunnable 'and runs QModbusRtuSerialMaster in' run() override ', it is also abnormal.
Using QtConcurrent:: run is also abnormal, why is this
@xiaguangbo
It's a bit difficult to figure out what you really mean. Before you post, it helps to imagine what if reader without any contextual knowledge of your problem will understand it.Generally it doesn't make any difference if the
QThreadis heap or stack allocated.will not run properly
What do you mean by "properly"? What exactly do you expect?
Probably theQThreadgoes out of scope before the operation is finished.
Hast1.start();been called at all?Maybe post your entire code and use code block quotation for better readability.