Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QFileSystemWatcher problem
Forum Updated to NodeBB v4.3 + New Features

QFileSystemWatcher problem

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    YDYD
    wrote on last edited by
    #1

    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:

    @Dialog::Dialog(QWidget parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
    {
    ui->setupUi(this);
    /
    timer = new QTimer(this);
    timer->start(100);*/

    QFileSystemWatcher watcher;
    watcher.addPath("/mnt/rd/frame.jpg");
    hsvSaveConnect();
    checkBox();
    connect(ui->save,SIGNAL(clicked()),this,SLOT(saveValueToSD()));
    connect(ui->load,SIGNAL(clicked()),this,SLOT(loadInitValue()));
    connect(&watcher,SIGNAL(fileChanged(const QString &)),this,SLOT(loadImage()));
    connect(&watcher,SIGNAL(directoryChanged(const QString &)),this,SLOT(loadImage()));
    qDebug() << watcher.files() << watcher.directories();
    

    }

    void Dialog::loadImage()

    {

    qDebug() << "img loaded";
    
    
    QPixmap original("/mnt/rd/frame.jpg");
    
    
    if(original.isNull())
    
    
    {
    
        qDebug()<<"Failed to load image.";
    
    
    }
    
    ui->original->setPixmap(original);
    

    }@

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      It may be because you are using the QFileSystemWatcher as local variable inside the constructor. Try changing the same to

      QFileSystemWatcher *watch = new QFileSystemWatcher

      It should work.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved