Originally Posted by
b1
G'Day,
If no data is seen on the serial port, the app just sits there until something comes in or I crash the app. My question is how can I implement a timer of, say 500ms, to break the loop. I have tried using a timer but they don't seem to trigger the slot.
Any suggestions would be greatly appreciated.
Thank, B1.
simple .. u have the answer in your code ...
declare the recFlag globally in your .h file
privare:
bool recFlag;
privare:
bool recFlag;
QTimer *timer;
To copy to clipboard, switch view to plain text mode
in .cpp
recFlag = false;
timer->setSingleShot(true);
connect(timer, SIGNAL(timeout()), this, SLOT(breakLoop()));
timer->start(500);
recFlag = false;
timer = new QTimer();
timer->setSingleShot(true);
connect(timer, SIGNAL(timeout()), this, SLOT(breakLoop()));
timer->start(500);
To copy to clipboard, switch view to plain text mode
void MyWidger:: breakLoop(){
recFlag = true;
}
void MyWidger:: breakLoop(){
recFlag = true;
}
To copy to clipboard, switch view to plain text mode
see the blocking fortune client example :
http://doc.trolltech.com/4.5/network...hread-cpp.html
they are using your method only ...
i missed that ... dont forget to call your function again in breakLoop()
while ( recflag )
{
serialPort->read( retdata, 60 );
}
Bookmarks