Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Error: Cannot assign [undefined] to QUrl
Forum Updated to NodeBB v4.3 + New Features

Error: Cannot assign [undefined] to QUrl

Scheduled Pinned Locked Moved Solved QML and Qt Quick
17 Posts 2 Posters 7.8k Views 2 Watching
  • 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.
  • sierdzioS Offline
    sierdzioS Offline
    sierdzio
    Moderators
    wrote on last edited by
    #4

    No, I mean print the items.

                   console.log("Items:" + items)
                    mediaplayer.source=items.get(index,"filePath");
                    console.log("before playing the song")
                    mediaplayer.play();
    

    Looks like something is bad in your env, too, see these lines: libva info: va_openDriver() returns -1 seems like the audio driver is not working?

    (Z(:^

    Naveen_DN 1 Reply Last reply
    0
    • sierdzioS sierdzio

      No, I mean print the items.

                     console.log("Items:" + items)
                      mediaplayer.source=items.get(index,"filePath");
                      console.log("before playing the song")
                      mediaplayer.play();
      

      Looks like something is bad in your env, too, see these lines: libva info: va_openDriver() returns -1 seems like the audio driver is not working?

      Naveen_DN Offline
      Naveen_DN Offline
      Naveen_D
      wrote on last edited by
      #5

      @sierdzio When i print the items, i get the following output:
      qml: items are: QQuickFolderListModel(0xf12ac0)

      Naveen_D

      1 Reply Last reply
      0
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #6

        Ah, not very helpful. Try printing out all items in a loop, then.

        (Z(:^

        Naveen_DN 1 Reply Last reply
        0
        • sierdzioS sierdzio

          Ah, not very helpful. Try printing out all items in a loop, then.

          Naveen_DN Offline
          Naveen_DN Offline
          Naveen_D
          wrote on last edited by
          #7

          @sierdzio i am not getting how to print the items in foldermodellist i tried with the following code but didn't get output:

          for (var j=0; j<items.count;j++){
                              console.log("items"+ items(j))
                          }
          

          is this the correct way ?

          Naveen_D

          1 Reply Last reply
          0
          • sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #8

            Almost :-)

            for (var j=0; j<items.count;j++){
                console.log("item:"+ items.get(index,"filePath"))
            }
            

            Maybe that will help us pinpoint the issue.

            (Z(:^

            Naveen_DN 1 Reply Last reply
            0
            • sierdzioS sierdzio

              Almost :-)

              for (var j=0; j<items.count;j++){
                  console.log("item:"+ items.get(index,"filePath"))
              }
              

              Maybe that will help us pinpoint the issue.

              Naveen_DN Offline
              Naveen_DN Offline
              Naveen_D
              wrote on last edited by Naveen_D
              #9

              @sierdzio Hi, i tried printing those items, but i am getting the same error again (Error: Cannot assign [undefined] to QUrl), also when i try to print those items, i am not able to find the auto get method for items(i.e items.get() method) and it is not entering the for loop.
              what can be the possible solution? thanks

              Naveen_D

              1 Reply Last reply
              0
              • sierdzioS Offline
                sierdzioS Offline
                sierdzio
                Moderators
                wrote on last edited by
                #10

                Please try:

                • print items.count and items.get(0, "filePath")
                • rewrite items to be a normal QML component and not a property (see example code in the docs) and see if it works
                • make sure the path is OK :-)

                (Z(:^

                Naveen_DN 1 Reply Last reply
                0
                • sierdzioS sierdzio

                  Please try:

                  • print items.count and items.get(0, "filePath")
                  • rewrite items to be a normal QML component and not a property (see example code in the docs) and see if it works
                  • make sure the path is OK :-)
                  Naveen_DN Offline
                  Naveen_DN Offline
                  Naveen_D
                  wrote on last edited by
                  #11

                  @sierdzio

                  print items.count and items.get(0, "filePath")

                  output:
                  qml: items count >> 0
                  qml: items at 0 position >> undefined

                  rewrite items to be a normal QML component and not a property (see example code in the docs) and see if it works

                  i made the following changes, pls rectify if there is any mistake

                  FolderListModel{
                              id: items
                              folder: "/home/ubuntu/Documents/Sample_Examples_Qt_Qml/DummyMusicPlayer/Songs"
                              nameFilters: ["*.mp3"]
                          }
                  

                  after making changes i am getting the following output:

                  qml: Entered init function
                  qml: calling index function
                  qml: entered setindex function
                  qml: else part
                  qml: items count >> 0
                  qml: items at 0 position >> undefined
                  qrc:/main.qml:58: Error: Cannot assign [undefined] to QUrl

                  Naveen_D

                  1 Reply Last reply
                  0
                  • sierdzioS Offline
                    sierdzioS Offline
                    sierdzio
                    Moderators
                    wrote on last edited by
                    #12

                    OK, so now at least we know this:

                    • issue is not related to QtMultimedia
                    • issue is with FolderListModel
                    • "Cannot assign [undefined]" is there, because items is empty (no .mp3 files are detected in Songs folder)

                    Try using URL instead of path:

                    folder: "file:///home/ubuntu/Documents/Sample_Examples_Qt_Qml/DummyMusicPlayer/Songs"
                    

                    Relative and absolute paths should work, but apparently something fails here. Also, of course, please make sure there are some MP3s in that dir.

                    (Z(:^

                    Naveen_DN 1 Reply Last reply
                    0
                    • sierdzioS sierdzio

                      OK, so now at least we know this:

                      • issue is not related to QtMultimedia
                      • issue is with FolderListModel
                      • "Cannot assign [undefined]" is there, because items is empty (no .mp3 files are detected in Songs folder)

                      Try using URL instead of path:

                      folder: "file:///home/ubuntu/Documents/Sample_Examples_Qt_Qml/DummyMusicPlayer/Songs"
                      

                      Relative and absolute paths should work, but apparently something fails here. Also, of course, please make sure there are some MP3s in that dir.

                      Naveen_DN Offline
                      Naveen_DN Offline
                      Naveen_D
                      wrote on last edited by
                      #13

                      @sierdzio yup, now its detecting the mp3 files, i am getting the following output,

                      qml: Entered init function
                      qml: calling index function
                      qml: entered setindex function
                      qml: else part
                      qml: items count >> 5
                      qml: items at 0>> /home/ubuntu/Documents/Sample_Examples_Qt_Qml/DummyMusicPlayer/Songs/Cinema_Choopista-StarMusiQ.Com.mp3
                      qml: before playing the song

                      But i am not sure the song is playing or not, because i am not getting sound. Does it require anything else for this?

                      Naveen_D

                      sierdzioS 1 Reply Last reply
                      0
                      • Naveen_DN Naveen_D

                        @sierdzio yup, now its detecting the mp3 files, i am getting the following output,

                        qml: Entered init function
                        qml: calling index function
                        qml: entered setindex function
                        qml: else part
                        qml: items count >> 5
                        qml: items at 0>> /home/ubuntu/Documents/Sample_Examples_Qt_Qml/DummyMusicPlayer/Songs/Cinema_Choopista-StarMusiQ.Com.mp3
                        qml: before playing the song

                        But i am not sure the song is playing or not, because i am not getting sound. Does it require anything else for this?

                        sierdzioS Offline
                        sierdzioS Offline
                        sierdzio
                        Moderators
                        wrote on last edited by
                        #14

                        Nice, I'm glad to hear that problem is solved.

                        @Naveen_D said in Error: Cannot assign [undefined] to QUrl:

                        But i am not sure the song is playing or not, because i am not getting sound. Does it require anything else for this?

                        I'm not familiar with QtMultimedia, I can't help here unfortunately. My first guesses are:

                        • check if you have gstreamer 0.1 installed
                        • check if you have mp3 codecs installed (mp3lame or something)
                        • check some QtMultimedia examples in Qt Creator - does the sound work there?

                        (Z(:^

                        Naveen_DN 1 Reply Last reply
                        1
                        • sierdzioS sierdzio

                          Nice, I'm glad to hear that problem is solved.

                          @Naveen_D said in Error: Cannot assign [undefined] to QUrl:

                          But i am not sure the song is playing or not, because i am not getting sound. Does it require anything else for this?

                          I'm not familiar with QtMultimedia, I can't help here unfortunately. My first guesses are:

                          • check if you have gstreamer 0.1 installed
                          • check if you have mp3 codecs installed (mp3lame or something)
                          • check some QtMultimedia examples in Qt Creator - does the sound work there?
                          Naveen_DN Offline
                          Naveen_DN Offline
                          Naveen_D
                          wrote on last edited by Naveen_D
                          #15

                          Thanks for the information,
                          But previously i had tried to play songs using this and it was working fine, i found out that when i directly give source in the media player and play it is working fine the song is playing, but when i give the folderlistmodel path using the get method it is not working.
                          also i tried to print the path, when i give the direct source path, the path printed is the URL path but when it takes through the folderlistmodel, it is the normal path

                          i.e Direct source path with song if i give, the path set is :
                          "file:///home/ubuntu/Documents/Sample_Examples_Qt_Qml/DummyMusicPlayer/Songs/David Guetta - Love Don't Let Me Go (Memorax Remix) [FREE].mp3"

                          and through folderlistmodel with the index, the path set is :
                          "/home/ubuntu/Documents/Sample_Examples_Qt_Qml/DummyMusicPlayer/Songs/David Guetta - Love Don't Let Me Go (Memorax Remix) [FREE].mp3"

                          Can anyone please suggest the possible solution.
                          Thanks

                          Naveen_D

                          1 Reply Last reply
                          1
                          • Naveen_DN Offline
                            Naveen_DN Offline
                            Naveen_D
                            wrote on last edited by
                            #16

                            I have solved the issue,

                            mediaplayer.source=items.get(index,"filePath");
                            

                            I was using filePath, instead of this i used fileURL, the issue got resolved.

                            @sierdzio thanks alot for your help.

                            Thanks

                            Naveen_D

                            1 Reply Last reply
                            3
                            • sierdzioS Offline
                              sierdzioS Offline
                              sierdzio
                              Moderators
                              wrote on last edited by
                              #17

                              Cool, good to hear that :) Please mark the topic as solved, too.

                              (Z(:^

                              1 Reply Last reply
                              1

                              • Login

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