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. Is there any way to recognize if a data is changed from outside?
Qt 6.11 is out! See what's new in the release blog

Is there any way to recognize if a data is changed from outside?

Scheduled Pinned Locked Moved Unsolved General and Desktop
20 Posts 5 Posters 2.1k 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.
  • D developer_61

    yes i tried like that:
    header:

        QFileSystemWatcher* watcher;
    

    cpp:

      watcher->addPath(file);
      connect(watcher, &QFileSystemWatcher::fileChanged, this, &MainWindow::showmessage);
    

    But i get an error on that connect point.

    mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #7

    @developer_61

    Hi
    at any given time,you get error, it should always be included in the posts.. :)

    did you make
    showmessage take
    const QString &path

    ?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      developer_61
      wrote on last edited by
      #8

      @mrjj yes the function take const QString &path.
      @JonB Exception thrown: Read Access Violation
      "this" was "0xFFFFFFFFFFFFFFF7". is the error. only getting it with the debugger.

      mrjjM JonBJ 2 Replies Last reply
      0
      • D developer_61

        @mrjj yes the function take const QString &path.
        @JonB Exception thrown: Read Access Violation
        "this" was "0xFFFFFFFFFFFFFFF7". is the error. only getting it with the debugger.

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #9

        @developer_61
        hi
        that is not a compile "connect" error !
        that is runtime error. huge difference.

        did you do
        watcher = new QFileSystemWatcher();

        1 Reply Last reply
        1
        • D developer_61

          @mrjj yes the function take const QString &path.
          @JonB Exception thrown: Read Access Violation
          "this" was "0xFFFFFFFFFFFFFFF7". is the error. only getting it with the debugger.

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by
          #10

          @developer_61 said in Is there any way to recognize if a data is changed from outside?:

          Exception thrown: Read Access Violation

          It helps if you tell us this in the first place, to save time....

          Are you sure this runtime error does not happen on the watcher->addPath(file); statement?

          1 Reply Last reply
          1
          • D Offline
            D Offline
            developer_61
            wrote on last edited by developer_61
            #11

            @JonB sure it was the error that @mrjj say.
            Thank you so much guys you saved my day !

            1 Reply Last reply
            1
            • D Offline
              D Offline
              developer_61
              wrote on last edited by developer_61
              #12

              I have another problem now:
              The function showmessage is called two times. Do you know why?
              @JonB @mrjj

              mrjjM 1 Reply Last reply
              0
              • D developer_61

                I have another problem now:
                The function showmessage is called two times. Do you know why?
                @JonB @mrjj

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by mrjj
                #13

                @developer_61

                Well it might be normal as it depends what you do to trigger it,
                Say first file is created and then closed. then open and written to.

                So it might be expected and how it should be :)

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  developer_61
                  wrote on last edited by
                  #14

                  @mrjj I open the file change a letter and save it. After that the function is called two times.
                  Really confusing. But what you mean the file is created and closed? I mean the file is already existing.

                  1 Reply Last reply
                  0
                  • D developer_61

                    Hi !

                    I have a QTComboBox and can choose datas there. The input of the data will shown on my UI.
                    So what i want is:
                    If i'm loading the data, and open the data outside from the UI (QT) i want to recognize if the data is changed from outside.
                    So for example:

                    1. example.docx is selected and loaded in the UI.
                    2. example.docx is opened outside,changed and saved.
                    3. The UI recognize that the data is changed and give a message for that.

                    The data is shown by a QTreeView.

                    Regards!

                    J.HilkJ Offline
                    J.HilkJ Offline
                    J.Hilk
                    Moderators
                    wrote on last edited by
                    #15

                    @developer_61 if you simply want to check on start of your own application, if the file was modified, than you could use
                    https://doc.qt.io/qt-5/qfileinfo.html#lastModified

                    and check if the lastModified date correlates with your own last modification on it


                    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                    Q: What's that?
                    A: It's blue light.
                    Q: What does it do?
                    A: It turns blue.

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      developer_61
                      wrote on last edited by
                      #16

                      @J-Hilk no i don't want to check it on start of my application. It has to been happen during the application. Evertything is working fine. Only the function showMessage is called two times.

                      mrjjM 1 Reply Last reply
                      0
                      • D developer_61

                        @J-Hilk no i don't want to check it on start of my application. It has to been happen during the application. Evertything is working fine. Only the function showMessage is called two times.

                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by mrjj
                        #17

                        @developer_61

                        Hi
                        well both the file content and "last modified" flag is changed so i dont think its an error but
                        simply how it works. QFileSystemWatcher sends 2 signals.

                        1 Reply Last reply
                        0
                        • D Offline
                          D Offline
                          developer_61
                          wrote on last edited by developer_61
                          #18

                          @mrjj and is there a way to avoid that?
                          maybe with a static or something like that ?

                          1 Reply Last reply
                          0
                          • D Offline
                            D Offline
                            developer_61
                            wrote on last edited by
                            #19

                            does anybody have an idea?

                            mrjjM 1 Reply Last reply
                            0
                            • D developer_61

                              does anybody have an idea?

                              mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by
                              #20

                              @developer_61

                              Hi
                              No there is no way to avoid that as far as i know as its correctly reported as
                              the file do change twice. So QFileSystemWatcher is correct for it report it.

                              If its a huge issue for you, you could just use a timer and check "last modified" on the file
                              from time to time instead of using QFileSystemWatcher

                              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