Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Unsolved Set path of setRootIndex using a directory of project

    General and Desktop
    4
    12
    293
    Loading More Posts
    • 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
      giusirux last edited by

      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 Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • G
          giusirux last edited by

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

          mrjj 1 Reply Last reply Reply Quote 0
          • mrjj
            mrjj Lifetime Qt Champion @giusirux last edited by

            @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 Reply Quote 0
            • G
              giusirux last edited by

              @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

              mrjj 1 Reply Last reply Reply Quote 0
              • mrjj
                mrjj Lifetime Qt Champion @giusirux last edited by

                @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 Reply Quote 0
                • G
                  giusirux @mrjj last edited by

                  @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 Ehrlicher 1 Reply Last reply Reply Quote 0
                  • Christian Ehrlicher
                    Christian Ehrlicher Lifetime Qt Champion @giusirux last edited by

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

                    Qt has to stay free or it will die.

                    G 1 Reply Last reply Reply Quote 1
                    • G
                      giusirux @Christian Ehrlicher last edited by

                      @Christian-Ehrlicher yes, sorry
                      Qt 5.13.2

                      1 Reply Last reply Reply Quote 0
                      • G
                        giusirux last edited by

                        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 Reply Quote 0
                        • SGaist
                          SGaist Lifetime Qt Champion last edited by

                          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 Reply Quote 0
                          • G
                            giusirux @SGaist last edited by

                            @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 Reply Quote 0
                            • First post
                              Last post