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. Set path of setRootIndex using a directory of project

Set path of setRootIndex using a directory of project

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 4 Posters 886 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.
  • G Offline
    G Offline
    giusirux
    wrote on 7 Sept 2020, 13:41 last edited by
    #1

    Hi everyone
    I would like to set the index of a QTreeView with the path of a directory that is included in my project written in C ++.
    So, using a folder on my desktop as path, I have:

    model = new QFileSystemModel();
    model->setRootPath("C:/Users/Giusi/Desktop/Utils");
    directory = new QTreeView(widget);
    directory->setModel(model);
    directory->setRootIndex(model->index("C:/Users/Giusi/Desktop/Utils"));
    

    And everything is fine.
    The problem arises when I want to use a folder present in my project because it no longer stops doing Build, as if it went in a loop.
    To include the folder, I use Qt Resource System.
    I also use this mechanism for some icons and everything works perfectly when I use QPixmap like this

    QPixmap pixmapWheelX (":/qres/icons/wheel.png");
    

    Any suggestions?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 7 Sept 2020, 13:56 last edited by
      #2

      Hi
      Im not sure when issue comes ?

      Do you do something like
      directory->setRootIndex(model->index(":/qres/icons/"));

      Or what you mean ?

      1 Reply Last reply
      0
      • G Offline
        G Offline
        giusirux
        wrote on 7 Sept 2020, 14:19 last edited by
        #3

        @mrjj sorry, I think I didn't explain myself well.
        My goal is set setRootIndex with the path of a folder which is included in my project.
        So, I included the folder using Qt Resource System, and when I use it in
        model->index("path")
        and I build the project, compilation does not end.

        QPixmap pixmapWheelX (":/qres/icons/wheel.png") was an example to explain another point where I use Qt Resource System -and this works.

        M 1 Reply Last reply 7 Sept 2020, 14:23
        0
        • G giusirux
          7 Sept 2020, 14:19

          @mrjj sorry, I think I didn't explain myself well.
          My goal is set setRootIndex with the path of a folder which is included in my project.
          So, I included the folder using Qt Resource System, and when I use it in
          model->index("path")
          and I build the project, compilation does not end.

          QPixmap pixmapWheelX (":/qres/icons/wheel.png") was an example to explain another point where I use Qt Resource System -and this works.

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 7 Sept 2020, 14:23 last edited by
          #4

          @giusirux
          Hi
          So when you say "included in my project.", you mean its added to a resource file that is compiled into the project ?

          and if you then use this resource file for the model, it will then compile for ever ??

          1 Reply Last reply
          0
          • G Offline
            G Offline
            giusirux
            wrote on 7 Sept 2020, 14:44 last edited by
            #5

            @mrjj said in Set path of setRootIndex using a directory of project:

            So when you say "included in my project.", you mean its added to a resource file that is compiled into the project ?
            and if you then use this resource file for the model, it will then compile for ever ??

            yes, that's right

            M 1 Reply Last reply 8 Sept 2020, 05:10
            0
            • G giusirux
              7 Sept 2020, 14:44

              @mrjj said in Set path of setRootIndex using a directory of project:

              So when you say "included in my project.", you mean its added to a resource file that is compiled into the project ?
              and if you then use this resource file for the model, it will then compile for ever ??

              yes, that's right

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 8 Sept 2020, 05:10 last edited by
              #6

              @giusirux

              Hi
              I tried to reproduce this by
              1: add a sub folder to the project folder
              2: add this folder to a resource file (included in the project)
              3: use QFileSystemModel with this sub folder
              however, nothing bad happened.
              (it just compiled)

              SO did I miss a step ?

              What Qt version are you using ?

              G 1 Reply Last reply 9 Sept 2020, 15:59
              0
              • M mrjj
                8 Sept 2020, 05:10

                @giusirux

                Hi
                I tried to reproduce this by
                1: add a sub folder to the project folder
                2: add this folder to a resource file (included in the project)
                3: use QFileSystemModel with this sub folder
                however, nothing bad happened.
                (it just compiled)

                SO did I miss a step ?

                What Qt version are you using ?

                G Offline
                G Offline
                giusirux
                wrote on 9 Sept 2020, 15:59 last edited by
                #7

                @mrjj Hi
                The steps are right
                My version is: Qt Creator 4.12.4
                Based on Qt 5.14.2 (MSVC 2017, 32 bit)

                C 1 Reply Last reply 9 Sept 2020, 16:02
                0
                • G giusirux
                  9 Sept 2020, 15:59

                  @mrjj Hi
                  The steps are right
                  My version is: Qt Creator 4.12.4
                  Based on Qt 5.14.2 (MSVC 2017, 32 bit)

                  C Offline
                  C Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on 9 Sept 2020, 16:02 last edited by
                  #8

                  @giusirux Not the version which QtCreator was build with, we need the version of Qt you're compiling your apps with.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  G 1 Reply Last reply 9 Sept 2020, 16:26
                  1
                  • C Christian Ehrlicher
                    9 Sept 2020, 16:02

                    @giusirux Not the version which QtCreator was build with, we need the version of Qt you're compiling your apps with.

                    G Offline
                    G Offline
                    giusirux
                    wrote on 9 Sept 2020, 16:26 last edited by
                    #9

                    @Christian-Ehrlicher yes, sorry
                    Qt 5.13.2

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      giusirux
                      wrote on 10 Sept 2020, 14:51 last edited by
                      #10

                      ok, the Build problem is solved, but the path is not correct when the application runs.
                      The folder, which I included in the project, has three subfolders.
                      So, after I added the folder to a resource file, I copied and pasted the path in setRootPath and setRootIndex, but the folder which I see when the application runs is "C:"
                      Any suggestions?

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 10 Sept 2020, 18:47 last edited by
                        #11

                        Hi,

                        AFAIK, qrc files shall contain a list of file paths. Putting a folder in there will not recursively add the files and subfolders in there.

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

                        G 1 Reply Last reply 10 Sept 2020, 20:55
                        0
                        • S SGaist
                          10 Sept 2020, 18:47

                          Hi,

                          AFAIK, qrc files shall contain a list of file paths. Putting a folder in there will not recursively add the files and subfolders in there.

                          G Offline
                          G Offline
                          giusirux
                          wrote on 10 Sept 2020, 20:55 last edited by
                          #12

                          @SGaist hi
                          oh, ok... I didn't know it. So, how can i get this TreeView including the folder "Utils" in the project?
                          e2e0c23d-1a1c-4f29-97f0-6c82f9a728fc-image.png

                          P.S. these are Utils' subfolders

                          1 Reply Last reply
                          0

                          2/12

                          7 Sept 2020, 13:56

                          topic:navigator.unread, 10
                          • Login

                          • Login or register to search.
                          2 out of 12
                          • First post
                            2/12
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved