Results 1 to 4 of 4

Thread: QFileSystemWatcher problem

  1. #1
    Join Date
    Jun 2014
    Posts
    33
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question QFileSystemWatcher problem

    Hi all,

    I am using a QFileSystemWatcher to keep an eye on a Picture on RAM disk.
    When the picture is replace by another, which mean it is "modified".
    and i would like to emit a signal and get the image to display on a QLabel.

    It works when i use QTimer to replace the QFileSystemWatcher.

    It seems QFileSystemWatcher is not emitting any signal.

    my code ask following:

    Qt Code:
    1. Dialog::Dialog(QWidget *parent) :
    2. QDialog(parent),
    3. ui(new Ui::Dialog)
    4. {
    5. ui->setupUi(this);
    6. /* timer = new QTimer(this);
    7.   timer->start(100);*/
    8.  
    9. watcher.addPath("/mnt/rd/frame.jpg");
    10. hsvSaveConnect();
    11. checkBox();
    12. connect(ui->save,SIGNAL(clicked()),this,SLOT(saveValueToSD()));
    13. connect(ui->load,SIGNAL(clicked()),this,SLOT(loadInitValue()));
    14. connect(&watcher,SIGNAL(fileChanged(const QString &)),this,SLOT(loadImage()));
    15. connect(&watcher,SIGNAL(directoryChanged(const QString &)),this,SLOT(loadImage()));
    16. qDebug() << watcher.files() << watcher.directories();
    17. }
    18.  
    19.  
    20. void Dialog::loadImage()
    21.  
    22.  
    23. {
    24.  
    25. qDebug() << "img loaded";
    26.  
    27.  
    28. QPixmap original("/mnt/rd/frame.jpg");
    29.  
    30.  
    31. if(original.isNull())
    32.  
    33.  
    34. {
    35.  
    36. qDebug()<<"Failed to load image.";
    37.  
    38.  
    39. }
    40.  
    41. ui->original->setPixmap(original);
    42.  
    43.  
    44. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,391
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QFileSystemWatcher problem

    "watcher" goes out of scope when the constructor completes, allocate it on the heap or make it a class member.

  3. The following user says thank you to stampede for this useful post:

    YDYD (30th July 2014)

  4. #3
    Join Date
    Jun 2014
    Posts
    33
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QFileSystemWatcher problem

    Hi stampede,

    when i declared
    QFileSystemWatcher *watcher=new QFileSystemWatcher;

    it works,

    but i declared in .h file "private",it is not working.

    "The program has unexpectedly finished."

  5. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,391
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QFileSystemWatcher problem

    it is not working
    It is impossible to help without seeing relevant code.

Similar Threads

  1. QFileSystemWatcher Problem
    By Dongxd in forum Qt Programming
    Replies: 2
    Last Post: 10th May 2014, 11:18
  2. Problem with QFileSystemWatcher?
    By arbi in forum Qt Programming
    Replies: 3
    Last Post: 29th March 2012, 07:57
  3. QFileSystemWatcher problem... yes, again..
    By nateriver in forum Qt Programming
    Replies: 0
    Last Post: 31st December 2009, 16:47
  4. QFIleSystemWatcher
    By jayreddy in forum Qt Programming
    Replies: 1
    Last Post: 15th December 2009, 08:21
  5. QFileSystemWatcher problem!!
    By Raajesh in forum Qt Programming
    Replies: 0
    Last Post: 23rd June 2008, 17:46

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.