Connect ReadyRead-Signal with Slot
Hi,
I am working on a project another student has written.
I don't like the way he handled reading from the SerialPort:
Code:
settings->RS485port.write(dataToSend);
if(settings->RS485port.waitForReadyRead(1)){
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.
Code:
connect(settings->RS485port, SIGNAL(readyRead()), this, SLOT(handlePortReadyRead()));
If I try to compile this, it says:
Quote:
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?
Re: Connect ReadyRead-Signal with Slot
The first parameter should be the object address.
Re: Connect ReadyRead-Signal with Slot
Thank You. That was very obvious, couldn't see that.
Re: Connect ReadyRead-Signal with Slot
Okay so I connected the Signal to the Slot
This is my handlePortReadyRead Slot:
Code:
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:
Code:
RS485Port.write(dataToSend);
timer->start(100);
do{
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?