Thanks, it was exactly what I was needing 
Actually I solved my problem, but there's one more question: how can I know if there are pending data on stdin?
Actually, my parsing function is blocking:
cin >> p;
QPoint p;
cin >> p;
To copy to clipboard, switch view to plain text mode
Will block if the point isn't complete (it have a syntactic structure like "(x,y)" ).
It would be nice if I could read the partial data as they are notified, put them in a buffer and analyze the buffer with a regex: if full data are present, I can use the parsing function without blocking. The parsed data are consumed and the incomplete data will be added at the next notification (by QSocketNotifier of course).
This would allow me to read data like:
while (buffer.indexOf(regex) != -1) {
buffer >> p;
}
while (buffer.indexOf(regex) != -1) {
QPoint p;
buffer >> p;
}
To copy to clipboard, switch view to plain text mode
I was thinking to do this by keeping a QString buffer and QTextStream on it, but there is a problem: if I read all the data from the stream (like readAll()), it will block, because stdin is always open and waiting for new data:
...
void notification(int stream) {
buffer += input.readAll(); // Blocks here
// Check the buffer using QRegex and extract all the available data
}
QTextStream input(/* using stdin */);
static QString buffer;
...
void notification(int stream) {
buffer += input.readAll(); // Blocks here
// Check the buffer using QRegex and extract all the available data
}
To copy to clipboard, switch view to plain text mode
Do you have any advice on how to do this?
Thanks wysota, you're always helpful!
Bookmarks