I’m building a program that performs some users tests and needs to record data on what they are doing at very small intervals (every 10ms). Most of the data can be found from QT, but unfortunately I need to use a separate program to calculate mouse movement (I need to get movement even when the mouse has already hit the edge of the screen, but QT just ignores off-screen movement).
Therefore I’ve built a windows program that deals with the low level mouse input and outputs the changes in coordinates detected. The problem however, is that I can’t get the data from the windows program to line up with the output from the main program.
In my main program, I use the follow code.
mouseTracker = new QProcess();
mouseTracker->start("C:\\WindowsFun.exe",QIODevice::ReadWrite|QIODevice::Unbuffered);
mouseTracker->setProcessChannelMode(QProcess::MergedChannels);
connect(mouseTracker,SIGNAL(readyRead()), this, SLOT(readMouseData()),Qt::DirectConnection);
and the readMouseData function looks like this.
void HideWindow::readMouseData(){
QByteArray data = mouseTracker->readAll();
QString text = QString(data);
saveFileStream << text.toStdString();
}
Some of this stuff might be unnecessary. I added in the “MergedChannels” mode and the “DirectConnection” bit in an attempt to solve the problem.
The result I’m getting is that the output from the windows program shows up in large blocks every 100ms or so, rather than being inserted into the filestream right when it occurs. It seems like there is a buffer somewhere that needs to fill, or a delay before the readyRead() signal is processed. Does anyone have any suggestions for how I can get the output from both the main program and the QProcess in real time? (Well, at least with a delay less than 10ms).
Also, if it is important, I am running Windows 7 and using MinGW for compilation of the main program and Visual Studio 2008 for the windows program that detects mouse movement. The output in windows look like this:
int xPosRelative = raw->data.mouse.lLastX;
int yPosRelative = raw->data.mouse.lLastY;
char output[100];
int n;
n = std::sprintf(output,"%d %d",xPosRelative,yPosRelative);
std::printf("%s\n",output,n);
std::fflush(0);
Let me know if anymore information is needed.
Thanks,
-Keilan
Unfortunately, the Windows implementation of QProcess is hard-coded to check once every 100 milliseconds for stdout/stderr from the external process. Looking through the Qt code, you may be able to get around this by calling waitForReadyRead frequently (with a small timeout value).