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.7k 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.
  • JonBJ Offline
    JonBJ Offline
    JonB
    wrote on 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
    0
    • JonBJ JonB

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

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

      JonBJ 1 Reply Last reply
      0
      • N Nick Shapper

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

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on 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
        0
        • JonBJ JonB

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

          JoeCFDJ JonBJ 2 Replies Last reply
          0
          • N Nick Shapper

            @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

            JoeCFDJ Offline
            JoeCFDJ Offline
            JoeCFD
            wrote on last edited by JoeCFD
            #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 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

                @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

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #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
                0
                • JonBJ JonB

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

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

                  JonBJ 1 Reply Last reply
                  0
                  • N Nick Shapper

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

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #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
                    1
                    • JonBJ JonB

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

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

                      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