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 #include +#include // 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 #include #include - -#include "filenameprovider.h" - #include using namespace Qt::Literals::StringLiterals; @@ -52,13 +49,6 @@ int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); - qmlRegisterSingletonType("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);