summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDheerendra Purohit <[email protected]>2025-05-22 17:04:32 +0530
committerDheerendra Purohit <[email protected]>2025-05-30 10:16:03 +0530
commit303c85a782dcc952dd96d4de0eff73f878c0f09d (patch)
treece9669ae70b8c77279e17002038cca69f9f37ea1
parentfea28023bcd466b7117f103aeddd81f7239e1728 (diff)
Use QML_ELEMENT macro instead of qmlRegister* for mediaplayerHEADdev
Updated the MediaPlayer example to use compile-time QML registration via the QML_ELEMENT macros instead of qmlRegisterSingletonType. This aligns the example with modern Qt 6 best practices and improves startup performance and tooling integration. Pick-to: 6.9 6.8 Task-number: QTBUG-136712 Change-Id: Id34670f4d45200b9a1424612f5a05bebead0a60e Reviewed-by: Sze Howe Koh <[email protected]>
-rw-r--r--examples/demos/mediaplayer/CMakeLists.txt5
-rw-r--r--examples/demos/mediaplayer/MediaPlayer/PlaylistInfo.qml1
-rw-r--r--examples/demos/mediaplayer/filenameprovider.h4
-rw-r--r--examples/demos/mediaplayer/main.cpp10
4 files changed, 9 insertions, 11 deletions
diff --git a/examples/demos/mediaplayer/CMakeLists.txt b/examples/demos/mediaplayer/CMakeLists.txt
index dc1f1e204..123a26412 100644
--- a/examples/demos/mediaplayer/CMakeLists.txt
+++ b/examples/demos/mediaplayer/CMakeLists.txt
@@ -13,6 +13,11 @@ qt_add_executable(MediaPlayerApp
filenameprovider.h
)
+qt_add_qml_module(MediaPlayerApp
+ URI "io.qt.filenameprovider"
+ VERSION 1.0
+)
+
qt_add_ios_ffmpeg_libraries(MediaPlayerApp)
add_subdirectory(MediaPlayer)
diff --git a/examples/demos/mediaplayer/MediaPlayer/PlaylistInfo.qml b/examples/demos/mediaplayer/MediaPlayer/PlaylistInfo.qml
index d69278f38..914925540 100644
--- a/examples/demos/mediaplayer/MediaPlayer/PlaylistInfo.qml
+++ b/examples/demos/mediaplayer/MediaPlayer/PlaylistInfo.qml
@@ -10,7 +10,6 @@ import QtQuick.Layouts
import QtCore
import MediaControls
import Config
-
import io.qt.filenameprovider
Rectangle {
diff --git a/examples/demos/mediaplayer/filenameprovider.h b/examples/demos/mediaplayer/filenameprovider.h
index b4157cb78..4d7ca2645 100644
--- a/examples/demos/mediaplayer/filenameprovider.h
+++ b/examples/demos/mediaplayer/filenameprovider.h
@@ -6,11 +6,15 @@
#include <QObject>
#include <QFileInfo>
+#include <qqmlregistration.h>
// Helper class to retrieve the filename from the given path using QFileInfo
class FileNameProvider: public QObject
{
Q_OBJECT
+ QML_ELEMENT
+ QML_SINGLETON
+
public:
explicit FileNameProvider(QObject* parent = nullptr): QObject(parent) {}
Q_INVOKABLE static QString getFileName(const QString &p) { return QFileInfo(p).fileName(); }
diff --git a/examples/demos/mediaplayer/main.cpp b/examples/demos/mediaplayer/main.cpp
index a7561032d..79a8a67fc 100644
--- a/examples/demos/mediaplayer/main.cpp
+++ b/examples/demos/mediaplayer/main.cpp
@@ -7,9 +7,6 @@
#include <QDir>
#include <QMediaFormat>
#include <QMimeType>
-
-#include "filenameprovider.h"
-
#include <algorithm>
using namespace Qt::Literals::StringLiterals;
@@ -52,13 +49,6 @@ int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
- qmlRegisterSingletonType<FileNameProvider>("io.qt.filenameprovider", 1, 0, "FileNameProvider",
- [] (QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * {
- static auto * provider = new FileNameProvider();
- return provider;
- }
- );
-
QCoreApplication::setApplicationName("MediaPlayer Example");
QCoreApplication::setOrganizationName("QtProject");
QCoreApplication::setApplicationVersion(QT_VERSION_STR);