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. How find my log file is changed ?

How find my log file is changed ?

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 2.5k Views
  • 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 Offline
    T Offline
    tmtt66
    wrote on last edited by
    #1

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

    Thanks.

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      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
      0
      • T Offline
        T Offline
        tmtt66
        wrote on last edited by
        #3

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

        thanks.

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @
          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
          0
          • T Offline
            T Offline
            tmtt66
            wrote on last edited by
            #5

            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
            0
            • raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

              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
              0
              • T Offline
                T Offline
                tmtt66
                wrote on last edited by
                #7

                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
                0
                • T Offline
                  T Offline
                  tobias.hunger
                  wrote on last edited by
                  #8

                  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
                  0
                  • T Offline
                    T Offline
                    tmtt66
                    wrote on last edited by
                    #9

                    not any solution?

                    1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      tobias.hunger
                      wrote on last edited by
                      #10

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

                      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