I also have the same issue...
-
Re: How to send data to Serial Port in Qt Test
I also have the same issue.
The code works outside the QTest project, but inside it fails !!
QDEBUG : TestKat500::test_3_Ant3() Sending "AN3;" QWARN : TestKat500::test_3_Ant3() QSocketNotifier: Can only be used with threads started with QThread QDEBUG : TestKat500::test_3_Ant3() Short Delay Start QDEBUG : TestKat500::test_3_Ant3() Short Delay End QINFO : TestKat500::test_3_Ant3() Read "" QWARN : TestKat500::test_3_Ant3() Wanted 4 only got 0 QDEBUG : TestKat500::test_3_Ant3() Kat Releasing Serial port
I have tried to see if by using QConcurrent I can force the test to run as a thread.
I suppose that often people Mock the output of Serial devices, and so - this is slightly against the common use-case. But as the test equipment (radio) is sitting on my desk next to the development machine - writing a MOCK seems a little like making work for myself.
Running Qt 6.2.3 on Mac M1 Silicon.
-
@Dwende said in I also have the same issue...:
I have tried to see if by using QConcurrent I can force the test to run as a thread
Why?
-
@Dwende like the op, you probably have the SerialPort member variable one the stack.
initialise it correctly in the initaliser list of your constructor so that it has the correct parent, than it should be moved correctly to any thread, the parent is moved to
class MySerialPort : public QObject { Q_OBJECT public: MySerialPort (QObject *parent = nullptr) : QObject(parent) , m_serialPort(this) { } private: QSerialPort m_serialPort; };