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
QtWS25 Last Chance

Set path of setRootIndex using a directory of project

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 4 Posters 864 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 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
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on 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 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.

        mrjjM 1 Reply Last reply
        0
        • G giusirux

          @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.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on 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 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

            mrjjM 1 Reply Last reply
            0
            • G giusirux

              @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

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on 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
              0
              • mrjjM mrjj

                @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 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)

                Christian EhrlicherC 1 Reply Last reply
                0
                • G giusirux

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

                  Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on 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
                  1
                  • Christian EhrlicherC Christian Ehrlicher

                    @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 last edited by
                    #9

                    @Christian-Ehrlicher yes, sorry
                    Qt 5.13.2

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      giusirux
                      wrote on 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
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 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
                        0
                        • SGaistS SGaist

                          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 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

                          • Login

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