Unable to read from QSerialPort using MSVC compiler
-
@Turi said in Unable to read from QSerialPort using MSVC compiler:
if (pBytesWritten == dataToSend.length()) {
qDebug().nospace().noquote() << "Write ok";
QThread::msleep(50);
if (readMsg() == E_OK) {This is not how you should use QSerialPort.
You should read from the port as soon as there is actually something to read.
To do so connect a slot to https://doc.qt.io/qt-5/qiodevice.html#readyRead signal and do the reading there.If, for some reason, you want to do it in sequence, then call https://doc.qt.io/qt-5/qiodevice.html#waitForReadyRead after writing and read afterwards.
@jsulm said in Unable to read from QSerialPort using MSVC compiler:
afterwards
I need to do it in sequence. I already use waitForReadyRead function to read from serial but this not work if I compile my application with MSVC.
-
@jsulm said in Unable to read from QSerialPort using MSVC compiler:
afterwards
I need to do it in sequence. I already use waitForReadyRead function to read from serial but this not work if I compile my application with MSVC.
@Turi said in Unable to read from QSerialPort using MSVC compiler:
I already use waitForReadyRead
Then QThread::msleep(50); is completely useless.
Why do you need to do it in sequence?
Qt is an event driven framework and you should use it as such instead of trying to force it to behave in a way it was not designed to work? -
@Turi said in Unable to read from QSerialPort using MSVC compiler:
I already use waitForReadyRead
Then QThread::msleep(50); is completely useless.
Why do you need to do it in sequence?
Qt is an event driven framework and you should use it as such instead of trying to force it to behave in a way it was not designed to work? -
@jsulm
I removed QThread::msleep(50) and added a connect to the readyRead signal but I'm still unable to read the serial, the connect is never called. Also with the connect, it is solicited if I use MinGW compiler but not with MSVC.@Turi said in Unable to read from QSerialPort using MSVC compiler:
the connect is never called. Also with the connect, it is solicited if I use MinGW compiler but not with MSVC.
I don't understand this.
Do you mean the connect(...) is never called? Then fix that.
Or do you mean the slot is not called?
Please show your connect call and also check its return value. -
@jsulm
I removed QThread::msleep(50) and added a connect to the readyRead signal but I'm still unable to read the serial, the connect is never called. Also with the connect, it is solicited if I use MinGW compiler but not with MSVC. -
@jsulm
I have already followed the suggestions of @J-Hilk .
This is my connect:bool ok = connect(serial, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
After that the value of' ok' is true, but the SLOT is never called.
@Turi said in Unable to read from QSerialPort using MSVC compiler:
I have already followed the suggestions of @J-Hilk
No, I was refering to this:
"also connect to the error signal errorOccured
https://doc.qt.io/qt-5/qserialport.html#errorOccurred"And you should use the Qt5 connect syntax: https://doc.qt.io/qt-5/signalsandslots.html
-
@Turi said in Unable to read from QSerialPort using MSVC compiler:
I have already followed the suggestions of @J-Hilk
No, I was refering to this:
"also connect to the error signal errorOccured
https://doc.qt.io/qt-5/qserialport.html#errorOccurred"And you should use the Qt5 connect syntax: https://doc.qt.io/qt-5/signalsandslots.html
-
@jsulm
I have already tried all this and all seem work fine, without any error. But my application still does not read from the serial only if I use the MSVC compiler. -
@jsulm
I have already tried all this and all seem work fine, without any error. But my application still does not read from the serial only if I use the MSVC compiler. -
@Turi what versions are we actually talking here ?
Qt(from the kit), msvc, windows etc.
and can you show more of your actually class that does the serial communication?
-
@J-Hilk
I'm using:- Qt Creator 4.9.0
- Based on Qt 5.12.2 (MSVC 2017, 32 bit)
- Windows 10 Enterprise
Unfortunately I can't show more of my actually class due to the fact that is reserved code.
@Turi said in Unable to read from QSerialPort using MSVC compiler:
Based on Qt 5.12.2 (MSVC 2017, 32 bit)
This is the Qt version which was used to build QtCreator.
What Qt version do you use? -
@Turi said in Unable to read from QSerialPort using MSVC compiler:
Can you pass me a link where I can download this version?
Use the Qt Maintenance Tool to add that Qt version to your installation.
-
@Turi said in Unable to read from QSerialPort using MSVC compiler:
I tried with Qt 5.12.2 but not work.
I seggested 5.15.2, not 5.12.2
-
@Turi said in Unable to read from QSerialPort using MSVC compiler:
I tried with Qt 5.12.2 but not work.
I seggested 5.15.2, not 5.12.2