PDA

View Full Version : QFileSystemWatcher bug?



ROCKSTAR
3rd April 2014, 11:40
Could you help me please, guys?
I have an external application which my Qt program launch on button click. This external program write some data to the file "RES1.dat" (with FLUSH on each iteration) while it's not finished, and my program track "RES1.dat" file changes to increment progressBar:


QFileSystemWatcher *watcher = new QFileSystemWatcher(this);
watcher->addPath("RES1.dat");
connect(watcher,SIGNAL(fileChanged(QString)),this, SLOT(progressBarIncrement(QString)));

void MainWindow::progressBarIncrement(QString unused) {
counter += 1; // global parameter
ui->progressBar->setValue( counter );
}

ProgressBar and external application declaration:


counter=0; // global parameter
ui->progressBar->setMinimum(0);
ui->progressBar->setMaximum((int((datMain[5]-datMain[4])/datMain[6])+1));
ui->progressBar->setValue(0);

QProcess* proc = new QProcess(this);

/* Search for .exe file */
QStringList nameFilter("*.exe");
QDir directory("");
QStringList exeFile = directory.entryList(nameFilter);
/*****************/

proc->start(exeFile[0]);
connect(proc,SIGNAL(finished(int)),this,SLOT(fillP lots(int)));

The problem is that everything works fine on a computer where i build a programm (i have 1%,2%,...,100% progress fast and smoothly), but when i transfer my program (static build) to another computer, or even change the user on my own computer this progress goes slow and incorrect (it goes 1%,2%,...~31% and then suddenly 100%). BUT if i rebuild my programm under this user (not tested on other computers) then it goes as it should - fast and smoothly to 100%.
So I want universal static build with correct progress, but it seems that it is correct only after rebuilding on a specific computer. What is wrong with my code, and what can I do?

anda_skoa
3rd April 2014, 12:40
Maybe you could handle the progress value differently.

For example if you could precalculate the final file size, you could use the current size to calculate how far you have progressed.

Cheers,
_

ROCKSTAR
3rd April 2014, 12:47
Maybe you could handle the progress value differently.

For example if you could precalculate the final file size, you could use the current size to calculate how far you have progressed.

Cheers,
_

Do you mean to use QFile bytesWritten signal?

anda_skoa
3rd April 2014, 14:56
QFileInfo::size()

Cheers,
_

ROCKSTAR
4th April 2014, 11:08
QFileInfo::size()

Cheers,
_

Realisation with QTimer timeout signal, where every 1msec compares QFileInfo::lastModified() with file previos lastModified date (cause i can precisely know how many times file has been changed, but not the size) to show ext. app. progress perfectly works! Thank you for the idea! :)

But anyway that strange QFileSystemWatcher behaviour...