PDA

View Full Version : Connect ReadyRead-Signal with Slot



mikrocat
6th November 2015, 08:04
Hi,
I am working on a project another student has written.
I don't like the way he handled reading from the SerialPort:



settings->RS485port.write(dataToSend);
if(settings->RS485port.waitForReadyRead(1)){
QByteArray temp = settings->RS485port.readAll();

for(int charCount = 0; charCount < temp.count(); charCount++){
...... //handling the response
}
byteReceived = true;
}
}

waitForReadyRead let the GUI freeze and that's definitely not what i want to happen. So i read about connecting the readyRead Signal with a Slot.


connect(settings->RS485port, SIGNAL(readyRead()), this, SLOT(handlePortReadyRead()));

If I try to compile this, it says:

C:\Users\...\bootloaderdialog.cpp:207: Fehler: no matching function for call to 'BootloaderDialog::connect(QSerialPort&, const char [13], BootloaderDialog* const, const char [23])'
connect(settings->RS485port, SIGNAL(readyRead()), this, SLOT(handlePortReadyRead()));


Do you know why i can't connect the Signal to the Slot. Or do you know any better way to read Data from a Serialport?

Lesiok
6th November 2015, 09:19
The first parameter should be the object address.

mikrocat
6th November 2015, 10:35
Thank You. That was very obvious, couldn't see that.

mikrocat
10th November 2015, 13:56
Okay so I connected the Signal to the Slot

This is my handlePortReadyRead Slot:


QByteArray temp = RS485port.readAll();
for(int charCount = 0; charCount < temp.count(); charCount++){
char singleInChar = temp.at(charCount);
validationFlag = handleResponse(&response, deviceAddr, FID, singleInChar, false);
if(validationFlag){
if(response.at(0) != 0){ // device sent error code
displayErrorMessage(response.at(0));
}
emit readCompleteFrame();
break;
}
}
byteReceived = true;


I'm having a process, where I write many times to the port and then want to analyse the response. At the moment it looks like this:



RS485Port.write(dataToSend);
timer->start(100);
do{
QApplication::processEvents();
if(validationFlag){
...
//do something with the response
response.clear();
}
else if(timer->remainingTime() == 0){
... //check if no connection or no valid Frame
}
}
while(!validationFlag);


So this process is a very long process. Sometimes it get stucked in the middle of the code, I think it is because of the QApplication::processEvents().
Is there any better way?