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.7k 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
    #2

    Perhaps items really is empty or undefined? Try printing it with console.log().

    (Z(:^

    Naveen_DN 1 Reply Last reply
    1
    • sierdzioS sierdzio

      Perhaps items really is empty or undefined? Try printing it with console.log().

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

      @sierdzio i tried this with a small example, what i am doing is on a click of button i am trying to play the song. here i am not getting any error but i didn't get output also, on click of button nothing happens.. i tried printing using console, here is the minimal code which i am trying...

      import QtQuick 2.6
      import QtQuick.Controls 1.5
      import QtQuick.Controls.Styles 1.4
      import QtQuick.Layouts 1.1
      import QtMultimedia 5.0
      import Qt.labs.folderlistmodel 1.0
      
      ApplicationWindow {
          visible: true
          width: 640
          height: 480
      
          MediaPlayer {
              id: player
          }
      
          Item {
              id: playerLogic
      
              property int index: -1
              property MediaPlayer mediaplayer: player
              property FolderListModel items: FolderListModel{
                  folder: "Songs"
                  nameFilters: ["*.mp3"]
              }
      
              function init(){
                  console.log("Entered init function")
                  if(mediaplayer.PlayingState===1)
                  {
                      console.log("playing state is 1")
                      mediaplayer.pause();
                  }else if(mediaplayer.PlayingState===2){
                      console.log("playing state is 2")
                      mediaplayer.play();
                  } else {
                      console.log("calling index function")
                      setIndex(0);
                  }
              }
      
              function setIndex(i){
                  console.log("entered setindex function")
                  index= i
                  if(index<0 || index> items.count){
                      console.log("checking if condition")
                      index=-1;
                      mediaplayer.source="";
                  }else {
                      console.log("else part")
                      mediaplayer.source=items.get(index,"filePath");
                      console.log("before playing the song")
                      mediaplayer.play();
                  }
              }
          }
      
          Button{
              id: playpausebutton
              anchors.centerIn: parent
              width: 100
              height: 80
              text: "PlayMusic"
              state: "none"
              style: ButtonStyle{
                  background: Rectangle{
                      id: buttonbackground
                      implicitHeight: parent.height
                      implicitWidth: parent.width
                      color: "#00bcd4"
                      opacity: playpausebutton.pressed ? 0.5: 1.0
                      radius: 5
                  }
              }
              MouseArea {
                  id: buttonmousearea
                  anchors.fill: parent
                  onClicked: playerLogic.init()
              }
          }
      
      }
      
      

      output :
      QML debugging is enabled. Only use this in a safe environment.
      libva info: VA-API version 0.37.0
      libva info: va_getDriverName() returns 0
      libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/fglrx_drv_video.so
      libva info: va_openDriver() returns -1
      libva info: VA-API version 0.37.0
      libva info: va_getDriverName() returns 0
      libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/fglrx_drv_video.so
      libva info: va_openDriver() returns -1
      libva info: VA-API version 0.37.0
      libva info: va_getDriverName() returns 0
      libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/fglrx_drv_video.so
      libva info: va_openDriver() returns -1
      libva info: VA-API version 0.37.0
      libva info: va_getDriverName() returns 0
      libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/fglrx_drv_video.so
      libva info: va_openDriver() returns -1
      qml: Entered init function
      qml: calling index function
      qml: entered setindex function
      qml: else part
      qml: before playing the song
      qml: Entered init function
      qml: calling index function
      qml: entered setindex function
      qml: else part
      qml: before playing the song

      Naveen_D

      1 Reply Last reply
      0
      • 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