Results 1 to 5 of 5

Thread: QFileSystemWatcher bug?

  1. #1
    Join Date
    Dec 2013
    Posts
    15
    Thanks
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default QFileSystemWatcher bug?

    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:
    Qt Code:
    1. watcher->addPath("RES1.dat");
    2. connect(watcher,SIGNAL(fileChanged(QString)),this,SLOT(progressBarIncrement(QString)));
    3.  
    4. void MainWindow::progressBarIncrement(QString unused) {
    5. counter += 1; // global parameter
    6. ui->progressBar->setValue( counter );
    7. }
    To copy to clipboard, switch view to plain text mode 
    ProgressBar and external application declaration:
    Qt Code:
    1. counter=0; // global parameter
    2. ui->progressBar->setMinimum(0);
    3. ui->progressBar->setMaximum((int((datMain[5]-datMain[4])/datMain[6])+1));
    4. ui->progressBar->setValue(0);
    5.  
    6. QProcess* proc = new QProcess(this);
    7.  
    8. /* Search for .exe file */
    9. QStringList nameFilter("*.exe");
    10. QDir directory("");
    11. QStringList exeFile = directory.entryList(nameFilter);
    12. /*****************/
    13.  
    14. proc->start(exeFile[0]);
    15. connect(proc,SIGNAL(finished(int)),this,SLOT(fillPlots(int)));
    To copy to clipboard, switch view to plain text mode 
    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?
    Last edited by ROCKSTAR; 3rd April 2014 at 11:51.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QFileSystemWatcher bug?

    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,
    _

  3. #3
    Join Date
    Dec 2013
    Posts
    15
    Thanks
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QFileSystemWatcher bug?

    Quote Originally Posted by anda_skoa View Post
    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?

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QFileSystemWatcher bug?

    QFileInfo::size()

    Cheers,
    _

  5. The following user says thank you to anda_skoa for this useful post:

    ROCKSTAR (4th April 2014)

  6. #5
    Join Date
    Dec 2013
    Posts
    15
    Thanks
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QFileSystemWatcher bug?

    Quote Originally Posted by anda_skoa View Post
    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...
    Last edited by ROCKSTAR; 4th April 2014 at 11:40.

Similar Threads

  1. QFIleSystemWatcher
    By jayreddy in forum Qt Programming
    Replies: 1
    Last Post: 15th December 2009, 08:21
  2. QFileSystemWatcher
    By Kumosan in forum Qt Programming
    Replies: 2
    Last Post: 18th March 2008, 20:52
  3. QFileSystemWatcher
    By minty in forum Qt Programming
    Replies: 13
    Last Post: 22nd May 2007, 15:39
  4. Need help with QFileSystemWatcher
    By L.Marvell in forum Qt Programming
    Replies: 1
    Last Post: 18th August 2006, 13:19
  5. QFileSystemWatcher Question (Qt 4.1.2tp)
    By momesana in forum Qt Programming
    Replies: 8
    Last Post: 25th July 2006, 14:01

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.