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. Implement QFileSystemModel in CLi
QtWS25 Last Chance

Implement QFileSystemModel in CLi

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 551 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.
  • M Offline
    M Offline
    MihEdd
    wrote on last edited by
    #1

    Hello.

    I am trying to use QFileSystemModel in a applciation that has both GUI and CLI in order to monitor if files are created in a directory. I have the following code:

    For CLI part I have tried to run the following code (in a separate project).

    int main(int argc, char *argv[])
    {
        QCoreApplication app(argc, argv);
        // create the main class
        QFileSystemModel model;
        model.setRootPath("D:/");
        return app.exec();
    }
    

    When the root path is set the app throws a Access violation reading.

    Is there any chance that QFileSystemModel cannot be used under CLI? If I am using the class in a GUI application that has QApplication on main everything works.

    Any suggestions?
    Thank you

    Pablo J. RoginaP 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Can you show the stack trace ?
      Which version of Qt are you using ?
      How are you starting your application ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      M 1 Reply Last reply
      0
      • M MihEdd

        Hello.

        I am trying to use QFileSystemModel in a applciation that has both GUI and CLI in order to monitor if files are created in a directory. I have the following code:

        For CLI part I have tried to run the following code (in a separate project).

        int main(int argc, char *argv[])
        {
            QCoreApplication app(argc, argv);
            // create the main class
            QFileSystemModel model;
            model.setRootPath("D:/");
            return app.exec();
        }
        

        When the root path is set the app throws a Access violation reading.

        Is there any chance that QFileSystemModel cannot be used under CLI? If I am using the class in a GUI application that has QApplication on main everything works.

        Any suggestions?
        Thank you

        Pablo J. RoginaP Offline
        Pablo J. RoginaP Offline
        Pablo J. Rogina
        wrote on last edited by
        #3

        @MihEdd said in Implement QFileSystemModel in CLi:

        Is there any chance that QFileSystemModel cannot be used under CLI?

        Documentation is your friend:

        Note: QFileSystemModel requires an instance of QApplication.

        Upvote the answer(s) that helped you solve the issue
        Use "Topic Tools" button to mark your post as Solved
        Add screenshots via postimage.org
        Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        4
        • SGaistS SGaist

          Hi and welcome to devnet,

          Can you show the stack trace ?
          Which version of Qt are you using ?
          How are you starting your application ?

          M Offline
          M Offline
          MihEdd
          wrote on last edited by
          #4

          @SGaist
          Here is my stack. I am using Qt 5.14.1.
          ```
          [Inline Frame] Qt5Widgets.dll!QFileIconProviderPrivate::getIcon(const QFileInfo &) Line 236
          at c:\users\qt\work\qt\qtbase\src\widgets\itemviews\qfileiconprovider.cpp(236)
          Qt5Widgets.dll!QFileIconProvider::icon(const QFileInfo & info) Line 247
          at c:\users\qt\work\qt\qtbase\src\widgets\itemviews\qfileiconprovider.cpp(247)
          Qt5Widgets.dll!QFileInfoGatherer::getInfo(const QFileInfo & fileInfo) Line 331
          at c:\users\qt\work\qt\qtbase\src\widgets\dialogs\qfileinfogatherer.cpp(331)
          Qt5Widgets.dll!QFileSystemModelPrivate::node(const QString & path, bool fetch) Line 478
          at c:\users\qt\work\qt\qtbase\src\widgets\dialogs\qfilesystemmodel.cpp(478)
          [Inline Frame] Qt5Widgets.dll!QFileSystemModelPrivate::index(const QString & path, int) Line 229
          at c:\users\qt\work\qt\qtbase\src\widgets\dialogs\qfilesystemmodel_p.h(229)
          Qt5Widgets.dll!QFileSystemModel::setRootPath(const QString & newPath) Line 1517
          at c:\users\qt\work\qt\qtbase\src\widgets\dialogs\qfilesystemmodel.cpp(1517)
          Synoptes-CLI.exe!main(int argc, char * * argv) Line 33
          at D:\Projects RISE\Synoptes\Qt Repo\Synoptes-GUI\Synoptes-CLI\main.cpp(33)
          [External Code]

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            It's because of what @Pablo-J-Rogina wrote: you shall use a QApplication in order to use QFileSystemModel.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • M Offline
              M Offline
              MihEdd
              wrote on last edited by
              #6

              Thank you for the help.

              If I am using QApplication instead of QCoreApplication the CLI is not working. I tried to move the QFileSystemModel in a separate thread, and in the separate thread I created a instance of QApplication. The QFileSystemModel works, but on main() the application fails when returning app->exec(). It seems that in cannot use QApplication beacuse is related with the GUI. Is QFileSystemModel available only for GUI applications?

              JonBJ 1 Reply Last reply
              0
              • M MihEdd

                Thank you for the help.

                If I am using QApplication instead of QCoreApplication the CLI is not working. I tried to move the QFileSystemModel in a separate thread, and in the separate thread I created a instance of QApplication. The QFileSystemModel works, but on main() the application fails when returning app->exec(). It seems that in cannot use QApplication beacuse is related with the GUI. Is QFileSystemModel available only for GUI applications?

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

                @MihEdd said in Implement QFileSystemModel in CLi:

                Is QFileSystemModel available only for GUI applications?

                I only know that QFileSystemModel uses a separate thread to populate itself so it will not cause the main thread to hang as the file system is being queried. Since @Pablo-J-Rogina has drawn your attention to

                Note: QFileSystemModel requires an instance of QApplication.

                one presumes that is indeed the case.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  What do you mean by "CLI is not working" now ? The code you posted just created the model and starts the event loop. What are you expecting it to do ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  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