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. Problem with QDir path to the folders
Forum Updated to NodeBB v4.3 + New Features

Problem with QDir path to the folders

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 3 Posters 1.8k 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.
  • J Offline
    J Offline
    JonB
    wrote on 7 May 2021, 14:32 last edited by
    #2

    Not sure I understand all of your explanation. But I think

    QStringList files = directory.entryList();
    

    will be getting the file names as relative to the directory you set in directory.setCurrent(path);, i.e. plain names with no leading directory path (print them out to see this)? But your media player won't know that. Pass absolute paths to it, not plain file names?

    N 1 Reply Last reply 7 May 2021, 14:35
    0
    • J JonB
      7 May 2021, 14:32

      Not sure I understand all of your explanation. But I think

      QStringList files = directory.entryList();
      

      will be getting the file names as relative to the directory you set in directory.setCurrent(path);, i.e. plain names with no leading directory path (print them out to see this)? But your media player won't know that. Pass absolute paths to it, not plain file names?

      N Offline
      N Offline
      Nick Shapper
      wrote on 7 May 2021, 14:35 last edited by
      #3

      @JonB Yes, you right, it's prints only file names without directory path

      J 1 Reply Last reply 7 May 2021, 14:40
      0
      • N Nick Shapper
        7 May 2021, 14:35

        @JonB Yes, you right, it's prints only file names without directory path

        J Offline
        J Offline
        JonB
        wrote on 7 May 2021, 14:40 last edited by
        #4

        @Nick-Shapper
        So there are many ways of making the path absolute. If you can't find a better one, you can always prepend path to each filepath in your foreach loop.

        N 1 Reply Last reply 7 May 2021, 14:51
        0
        • J JonB
          7 May 2021, 14:40

          @Nick-Shapper
          So there are many ways of making the path absolute. If you can't find a better one, you can always prepend path to each filepath in your foreach loop.

          N Offline
          N Offline
          Nick Shapper
          wrote on 7 May 2021, 14:51 last edited by Nick Shapper 5 Jul 2021, 14:51
          #5

          @JonB Ok, i guess i did something wrong. I changed

          mediaPlaylist->addMedia(QUrl(filepath));
          

          to

          mediaPlaylist->addMedia(QUrl(filepath.prepend(path)));
          

          Now it can't even start to play any file.
          Also i printed out my filepath and it says this:
          "C:/Users/Archivarius-cat/MusicMick Gordon - Bfg Division.mp3"
          "C:/Users/Archivarius-cat/MusicMick Gordon - Damnation.mp3"
          "C:/Users/Archivarius-cat/MusicMick Gordon - Uac Report File Shto36u3.mp3"

          from what i can see there's no / after Music folder, and it's weird. I'm gonna remove prepend function and see what it's gonna print without it

          J J 2 Replies Last reply 7 May 2021, 14:54
          0
          • N Nick Shapper
            7 May 2021, 14:51

            @JonB Ok, i guess i did something wrong. I changed

            mediaPlaylist->addMedia(QUrl(filepath));
            

            to

            mediaPlaylist->addMedia(QUrl(filepath.prepend(path)));
            

            Now it can't even start to play any file.
            Also i printed out my filepath and it says this:
            "C:/Users/Archivarius-cat/MusicMick Gordon - Bfg Division.mp3"
            "C:/Users/Archivarius-cat/MusicMick Gordon - Damnation.mp3"
            "C:/Users/Archivarius-cat/MusicMick Gordon - Uac Report File Shto36u3.mp3"

            from what i can see there's no / after Music folder, and it's weird. I'm gonna remove prepend function and see what it's gonna print without it

            J Offline
            J Offline
            JoeCFD
            wrote on 7 May 2021, 14:54 last edited by JoeCFD 5 Jul 2021, 14:56
            #6

            @Nick-Shapper addMedia( QUrl::fromLocalFile( m_fileName ) ) <==add them one after another with full path. Normally you need a filter to extract all files which can be played.

            1 Reply Last reply
            0
            • N Offline
              N Offline
              Nick Shapper
              wrote on 7 May 2021, 15:01 last edited by
              #7

              No, when i removed it it printed:
              "Mick Gordon - Bfg Division.mp3"
              "Mick Gordon - Damnation.mp3"
              "Mick Gordon - Uac Report File Shto36u3.mp3
              So i guess it was working

              1 Reply Last reply
              0
              • N Nick Shapper
                7 May 2021, 14:51

                @JonB Ok, i guess i did something wrong. I changed

                mediaPlaylist->addMedia(QUrl(filepath));
                

                to

                mediaPlaylist->addMedia(QUrl(filepath.prepend(path)));
                

                Now it can't even start to play any file.
                Also i printed out my filepath and it says this:
                "C:/Users/Archivarius-cat/MusicMick Gordon - Bfg Division.mp3"
                "C:/Users/Archivarius-cat/MusicMick Gordon - Damnation.mp3"
                "C:/Users/Archivarius-cat/MusicMick Gordon - Uac Report File Shto36u3.mp3"

                from what i can see there's no / after Music folder, and it's weird. I'm gonna remove prepend function and see what it's gonna print without it

                J Offline
                J Offline
                JonB
                wrote on 7 May 2021, 15:19 last edited by JonB 5 Jul 2021, 15:20
                #8

                @Nick-Shapper said in Problem with QDir path to the folders:

                from what i can see there's no / after Music folder, and it's weird. I'm gonna remove prepend function and see what it's gonna print without it

                When I said "prepend", I meant metaphorically! I didn't even know there was a QString::prepend() method. Yes you have to put the directory-separator-slash in. There are many ways to do path manipulation in Qt, sorry I don't have time to look them up for you.

                N 1 Reply Last reply 7 May 2021, 15:23
                0
                • J JonB
                  7 May 2021, 15:19

                  @Nick-Shapper said in Problem with QDir path to the folders:

                  from what i can see there's no / after Music folder, and it's weird. I'm gonna remove prepend function and see what it's gonna print without it

                  When I said "prepend", I meant metaphorically! I didn't even know there was a QString::prepend() method. Yes you have to put the directory-separator-slash in. There are many ways to do path manipulation in Qt, sorry I don't have time to look them up for you.

                  N Offline
                  N Offline
                  Nick Shapper
                  wrote on 7 May 2021, 15:23 last edited by
                  #9

                  @JonB Ok, thanks anyway, at least you gave me a direction :)

                  J 1 Reply Last reply 7 May 2021, 15:27
                  0
                  • N Nick Shapper
                    7 May 2021, 15:23

                    @JonB Ok, thanks anyway, at least you gave me a direction :)

                    J Offline
                    J Offline
                    JonB
                    wrote on 7 May 2021, 15:27 last edited by JonB 5 Jul 2021, 15:30
                    #10

                    @Nick-Shapper
                    This isn't the best, but kludged:

                    mediaPlaylist->addMedia(QUrl(filepath.prepend("/").prepend(path)));
                    // or
                    mediaPlaylist->addMedia(QUrl(path + QString("/") + filepath));
                    // or
                    mediaPlaylist->addMedia(QUrl(QString("%1/%2").arg(path).arg(filepath)));
                    

                    ?

                    N 1 Reply Last reply 7 May 2021, 15:34
                    1
                    • J JonB
                      7 May 2021, 15:27

                      @Nick-Shapper
                      This isn't the best, but kludged:

                      mediaPlaylist->addMedia(QUrl(filepath.prepend("/").prepend(path)));
                      // or
                      mediaPlaylist->addMedia(QUrl(path + QString("/") + filepath));
                      // or
                      mediaPlaylist->addMedia(QUrl(QString("%1/%2").arg(path).arg(filepath)));
                      

                      ?

                      N Offline
                      N Offline
                      Nick Shapper
                      wrote on 7 May 2021, 15:34 last edited by
                      #11

                      @JonB I got it working, Thanks a lot you man, really appreciate your help!

                      1 Reply Last reply
                      0

                      11/11

                      7 May 2021, 15:34

                      • Login

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