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. Cannot assign to non-existent property "source"
Forum Updated to NodeBB v4.3 + New Features

Cannot assign to non-existent property "source"

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 377 Views 1 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.
  • C Offline
    C Offline
    Caroline26
    wrote on last edited by Caroline26
    #1

    This is my code to create a video player but i am met with the error: Cannot assign to non-existent property "source"

    import QtQuick 2.15
    import QtQuick.Controls 2.15
    import QtMultimedia 5.15

    ApplicationWindow
    {
    visible: true
    width: 800
    height: 600
    title: "Simple Video Player"

    MediaPlayer {
        id: mediaPlayer
    }
    
    VideoOutput {
        anchors.fill: parent
        source: mediaPlayer
    }
    
    Rectangle {
        anchors.bottom: parent.bottom
        width: parent.width
        height: 50
        color: "black"
    
        Row {
            anchors.centerIn: parent
            spacing: 10
    
            Button {
                text: mediaPlayer.playbackState === MediaPlayer.PlayingState ? "Pause" : "Play"
                onClicked: {
                    if (mediaPlayer.playbackState === MediaPlayer.PlayingState) {
                        mediaPlayer.pause();
                    } else {
                        mediaPlayer.play();
                    }
                }
            }
    
            Slider {
                id: progressSlider
                value: mediaPlayer.position
                maximumValue: mediaPlayer.duration
                onValueChanged: {
                    if (progressSlider.pressed) {
                        mediaPlayer.position = progressSlider.value;
                    }
                }
            }
        }
    }
    
    Component.onCompleted: {
        // Show a File Picker dialog to select the video file
        var fileDialog = Qt.createQmlObject('import QtQuick.Dialogs; FileDialog {}', parent);
        fileDialog.title = "Select a Video File";
        fileDialog.selectExisting = true;
        fileDialog.accepted.connect(function() {
            mediaPlayer.source = fileDialog.fileUrl;
            mediaPlayer.play();
        });
        fileDialog.open();
    }}
    
    1 Reply Last reply
    0
    • oria66O Offline
      oria66O Offline
      oria66
      wrote on last edited by
      #2

      Hi @Caroline26. I can make it work using Qt6. Compare your code and make your own conclusions.

      import QtQuick
      import QtQuick.Window
      import QtQuick.Controls
      import QtMultimedia
      
      ApplicationWindow {
          id: root
          width: 640
          height: 480
          visible: true
          title: qsTr("Hello World")
      
          MediaPlayer {
              id: mediaPlayer
              videoOutput: vidOut
          }
      
          VideoOutput {
              id: vidOut
              anchors.fill: parent
          }
      
          Rectangle {
              anchors.bottom: parent.bottom
              width: parent.width
              height: 50
              color: "black"
      
              Row {
                  anchors.centerIn: parent
                  spacing: 10
      
                  Button{
                      text: "Open"
                      onClicked: {
                          // Show a File Picker dialog to select the video file
                          var fileDialog = Qt.createQmlObject('import QtQuick.Dialogs; FileDialog {}', root);
                          fileDialog.title = "Select a Video File";
                          //fileDialog.selectExisting = true;
                          fileDialog.accepted.connect(function() {
                              mediaPlayer.source = fileDialog.selectedFile;
                              mediaPlayer.play();
                          });
                          fileDialog.open();
      
      
                      }
                  }
      
                  Button {
                      text: mediaPlayer.playbackState === MediaPlayer.PlayingState ? "Pause" : "Play"
                      onClicked: {
                          if (mediaPlayer.playbackState === MediaPlayer.PlayingState) {
                              mediaPlayer.pause();
                          } else {
                              mediaPlayer.play();
                          }
                      }
                  }
      
                  Slider {
                      id: progressSlider
                      value: mediaPlayer.position
                      to: mediaPlayer.duration
                      onValueChanged: {
                          if (progressSlider.pressed) {
                              mediaPlayer.position = progressSlider.value;
                          }
                      }
                  }
              }
          }
      }
      

      The truth is out there

      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