Cannot assign to non-existent property "source"
Unsolved
QML and Qt Quick
-
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.15ApplicationWindow
{
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(); }}
-
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; } } } } } }