Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    How find my log file is changed ?

    General and Desktop
    3
    10
    2096
    Loading More Posts
    • 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.
    • T
      tmtt66 last edited by

      Hi .
      How find my log file is changed ?
      similar too tail -f on linux.

      Thanks.

      1 Reply Last reply Reply Quote 0
      • raven-worx
        raven-worx Moderators last edited by

        are you looking for something like "this":http://qt-project.org/doc/qt-4.8/qfilesystemwatcher.html#fileChanged?

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply Reply Quote 0
        • T
          tmtt66 last edited by

          how i can use this method on background my program.
          please help me.

          thanks.

          1 Reply Last reply Reply Quote 0
          • raven-worx
            raven-worx Moderators last edited by

            @
            QFileSystemWatcher* watcher = new QFileSystemWatcher;
            watcher->addPath( <path-to-file> );
            connect(watcher, SIGNAL(fileChanged(const QString &)), this, SLOT(onFileChanged(const QString &)));

            ...

            void onFileChanged(const QString &)
            {
            ... //do whatever you want on file change
            }
            @

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply Reply Quote 0
            • T
              tmtt66 last edited by

              I try this code but when change this file not response any thing.

              @
              void MainWindow::initiallize()
              {
              QFileSystemWatcher* watcher = new QFileSystemWatcher;
              watcher->addPath("D:/a.txt");
              connect(watcher, SIGNAL(fileChanged(const QString &)), this, SLOT(onFileChange(const QString &)));
              }

              ....

              void MainWindow::onFileChanged(const QString &)
              {
              qDebug()<<"ok-";
              }

              @

              1 Reply Last reply Reply Quote 0
              • raven-worx
                raven-worx Moderators last edited by

                did you specify onFileChanged() as slot?
                what did connect() return?
                are you sure that the contents of the file have changed after the connect statement?

                --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                If you have a question please use the forum so others can benefit from the solution in the future

                1 Reply Last reply Reply Quote 0
                • T
                  tmtt66 last edited by

                  every thing is ok. and connect() return true.

                  problem is when file changed manually Correctly work this code.

                  but when changed file with other program and logs created not any event happen.

                  ???

                  1 Reply Last reply Reply Quote 0
                  • T
                    tobias.hunger last edited by

                    Good apps store their data into a temporary file, delete the existing one and then rename the temporary to the (now no longer) existing name. Such a sequence does not trigger a filechanged since -- you guessed it -- the file never changes.

                    So go for the directoryChanged signal instead and validate that the file you care about has changed in that slot.

                    1 Reply Last reply Reply Quote 0
                    • T
                      tmtt66 last edited by

                      not any solution?

                      1 Reply Last reply Reply Quote 0
                      • T
                        tobias.hunger last edited by

                        I told you what goes wrong already... now go and implement that:)

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post