Results 1 to 7 of 7

Thread: QFileSystemWatcher fileChanged signal doubling

  1. #1
    Join Date
    Apr 2008
    Posts
    104
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QFileSystemWatcher fileChanged signal doubling

    There is something wrong with a "fileChanged" signal at QFileSystemWatcher. I'm working on the text editor. The opened file is added to the monitoring files list using the QFileSystemWatcher::addPath. When the other program changes this file, I get TWO "fileChanged" signals instead of a one. What's wrong? I've tested it, edited the monitoring file in different editors, but the result is the same - two signals are emmited after the changes was done.

  2. #2
    Join Date
    Jan 2006
    Posts
    371
    Thanks
    14
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFileSystemWatcher fileChanged signal doubling

    you are using a single QFileSystemWatcher for several editor? or one per editor?

  3. #3
    Join Date
    Apr 2008
    Posts
    104
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFileSystemWatcher fileChanged signal doubling

    Sure, I use a single QFileSystemWatcher instance. My editor is multy-tabbed. When it opens a file, it add a file path to QFileSystemWatcher:

    watcher.addPath (file_name);

    When an editor closes a file, I remove the file path from QFileSystemWatcher.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QFileSystemWatcher fileChanged signal doubling

    What does
    Qt Code:
    1. qDebug() << watcher.files() << watcher.directories();
    To copy to clipboard, switch view to plain text mode 
    output?
    J-P Nurmi

  5. #5
    Join Date
    Apr 2008
    Posts
    104
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFileSystemWatcher fileChanged signal doubling

    If I call it from my fileChanged-slot, I get this:
    -----------
    ("/home/rox/devel/test/test.txt") ()
    ("/home/rox/devel/test/test.txt") ()
    -----------
    It's after saving test.txt once from the another, external editor.

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QFileSystemWatcher fileChanged signal doubling

    Ok. What's the name of the slot? Perhaps you used the naming convention of automatic connections by accident?
    on_objectName_signalName(...)
    J-P Nurmi

  7. #7
    Join Date
    Apr 2008
    Posts
    104
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFileSystemWatcher fileChanged signal doubling

    My slot is named as "watcher_fileChanged". I have a class that manage text documets - document_holder. Withing that class I have a public slot document_holder::watcher_fileChanged (const QString & path).
    At the document_holder constructor I call the "connect" method to connect a slot with a watcher:

    connect(&watcher, SIGNAL(fileChanged(const QString &)), this, SLOT(watcher_fileChanged (const QString &)));

    All that compiles under Linux. And Qt is 4.3.4

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.