Problem with Qt Multimedia



  • I have a very strange issue with QMediaPlayer. I created a new Qt Widgets Application project. In the MainWindow class (in mainwindow.h) I wrote this: QMediaPlayer *player = new QMediaPlayer(this);

    In mainwindow.h I also wrote #include <QMultimedia/QMediaPlayer>
    Since building gave me an undefined reference error to QMediaPlayer, in project-name.pro I added QT += multimedia

    Then building my project went smoothly. This is the really strange part: when I ran the executable generated, it logged me out of my laptop! As in I had to log into my laptop again!

    Any idea why this happens? How to fix?

    P.S. I am using Qt 5.8.0 on Debian 8



  • Hi 6EQUJ5,

    Could you please show up more detail about your error?

    I've had times for working with Qt Multimedia for Embedded Linux, my experience is that Qt uses Gstreamer framework as the backend layer for Multimedia function. So maybe you must install Gstreamer on your Linux firstly.

    Best regards,
    Khoa



  • @KhoaTran-Programmer The errors are here:

    path/mainwindow.o In function `MainWindow::MainWindow(QWidget*)':

    path/mainwindow.cpp:-1: error: undefined reference to `QMediaPlayer::QMediaPlayer(QObject*, QFlagsQMediaPlayer::Flag)'

    :-1: error: collect2: error: ld returned 1 exit status

    Adding QT += multimedia in project_name.pro solved it. But, as I stated it logs me off for some reason when I run it.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You are missing QT += multimediawidgets in your .pro file.



  • @SGaist The same problem happens. I tried adding just QT += multimedia, just QT += multimediawidgets, and both of them in my .pro file.


  • Lifetime Qt Champion

    Did you re-run qmake after modifying the QT variable ?



  • @SGaist Yes I did. I cleaned, ran qmake, then rebuilded.


  • Lifetime Qt Champion

    Ok, can you show how you create your QMediaPlayer object ?

    Re-reading the error message, it seems that you are trying to give it a QObject based parent rather than a QWidget based parent.



  • @SGaist I created my QMediaPlayer object like this:

    ___QMediaPlayer *player = new QMediaPlayer(this);


  • Lifetime Qt Champion

    What is this ?



  • @SGaist this is MainWindow.

    mainwindow.h

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    #include <QtMultimedia/QMediaPlayer>
    
    namespace Ui
    {
        class MainWindow;
    }
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        explicit MainWindow(QWidget *parent = 0);
        ~MainWindow();
    
    private:
        QMediaPlayer *player = new QMediaPlayer(this);
        Ui::MainWindow *ui;
    };
    
    #endif // MAINWINDOW_H
    


  • @6EQUJ5 ,

    Could you please try to run some media player that has already had in Qt package

    Qt5.8.0\Examples\Qt-5.8\multimedia\video\qmlvideo
    Qt5.8.0\Examples\Qt-5.8\multimediawidgets\player

    You should ensure that the Multimedia backend is available on your system or not?

    Best regards,
    Khoa



  • @KhoaTran-Programmer With qmlvideo when I tried to play a video it logged me out again. With player it logged me out the moment I ran it.

    Why do I get logged out when I try to run multimedia based Qt programs? And how do I ensure the multimedia back end is available on my system and install the multimedia backend?


  • Lifetime Qt Champion

    You should start by testing with your distribution provided Qt to ensure that everything is working correctly.



  • @6EQUJ5

    How to ensure the multimedia backend is available or not? I try 2 methods before:

    1. Use default application of Qt(qmlvideo, player, ...)
      -> If one of them can run well, we can conclude it's OK
    2. Download Qt everywhere package and install(I try on Linux Embedded)
      -> When building Qt Multimedia component, qmake will automatically detect the backend, if it's not available some error info will display

    For your information, multimedia backend is not same for each OS

    • Windows: Directshow -> it's always available in Windows
    • Linux: Gstreamer -> Most, if not all, Linux distributions provide packages of GStreamer. You should find these in your distribution's package repository.
    • QNX: ???
    • Android: StageFight(maybe)

    Since your OS is Linux(Debian 8), so please confirm Gstreamer firstly. The fastest way, open termial and run some Gstreamer command line tools:
    $ gst-inspect-1.0
    $ gst-launch-1.0

    For set up Gstreamer on Linux, please refer to:
    https://gstreamer.freedesktop.org/documentation/installing/on-linux.html

    Best regards,
    Khoa


  • Moderators

    @6EQUJ5 Sounds like an issue with your graphics driver. Does any media player work?



  • @KhoaTran-Programmer On https://gstreamer.freedesktop.org/documentation/installing/on-linux.html the instructions for Debian installation is this:

    Install GStreamre on Ubuntu or Debian
    Run the following command:
    
    apt-get install ....
    

    Which I'm not sure about. I tried running sudo aptitude install gstreamer which didn't work. Then after typing in sudo aptitude install gstreamer and pressing TAB a bunch of packages came up which I don't know which to install.

    Can you clarify how to install on Debian?


  • Moderators

    @6EQUJ5 You should install all the GStreamer plug-in packages.
    But I don't think it is related to the installed GStreamer packages: if something needed is missing you will not be able to play a media file, but you should not be logged off.



  • @KhoaTran-Programmer The Gstreamer command line tools doesn't work (no such command exists according to terminal even with sudo). But, trying to install the Gstreamer plugins such as gstreamer1.0-plugins-base with sudo apt-get install gstreamer1.0-plugins-base tells me it's already installed.

    @jsulm What do you mean "any" media player? The examples on Qt or any media player that is installed? If you mean any old media player GNOME MPlayer works.

    @SGaist Aren't I doing that already? By using this version: Qt 5.8.0 for Linux 64-bit (766 MB)


  • Moderators

    @6EQUJ5 Qt 5.8 is for sure not what Debian provides (maybe Unstable?), I guess you installed Qt 5.8 by yourself, right? What @SGaist means is: try with Qt provided by Debian.



  • @jsulm Where can I get that? And yes I download the offline installer for Qt 5.8.0 for Linux 64-bit (766 MB) and installed Qt.


  • Moderators

    @6EQUJ5 From Debian? Use apt-get to install it as any other packages.
    What you downloaded is not what Debian provides.



  • @jsulm What packages do I install? Do I have to install them all separately like qtcreator, qtbase5-dev, etc. or is there a way to install it with one package? If not what are all the packages needed?


  • Moderators

    @6EQUJ5 I don't have Debian here. But you should be able to find out what is needed. No need to install QtCreator from Debian as you already have it. On Ubuntu you can install qt5-default, don't know whether it is same on Debian.



  • @jsulm I uninstalled Qt with the maintenance tool. Then installed with sudo aptitude install qt5-default and qtcreator with sudo aptitude install qtcreator .

    But, now I get this error Project ERROR: Unknown module(s) in QT: multimedia. In the .pro file I have QT += multimedia. I used the same code to test as way above.


  • Moderators

    @6EQUJ5 Then install libqt5multimedia5



  • @jsulm After running sudo aptitude install libqtmultimedia5 the same problem happens.


  • Moderators

    @6EQUJ5 qtmultimedia5-dev



  • @jsulm I can now compile successfully and run it. But, in the application output I get this:

    defaultServiceProvider::requestService(): no service found for - "org.qt-project.qt.mediaplayer"


  • Moderators

    @6EQUJ5 Can you set QT_DEBUG_PLUGINS environment variable to 1 and then start your app? Post then the output.



  • @jsulm How do get to the place where I can do that?


  • Moderators

    @6EQUJ5 You can do it in QtCreator: "Projects/Run Settings" in "Run Environment" add that variable.



  • @jsulm Output:

    Starting /home/user/Documents/Qt Projects/Media-Player/build-Media-Player-Desktop-Release/Media-Player...
    defaultServiceProvider::requestService(): no service found for - "org.qt-project.qt.mediaplayer"
    /home/user/Documents/Qt Projects/Media-Player/build-Media-Player-Desktop-Release/Media-Player exited with code 0
    
    Starting /home/user/Documents/Qt Projects/Media-Player/build-Media-Player-Desktop-Release/Media-Player...
    QFactoryLoader::QFactoryLoader() checking directory path "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms" ...
    QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqeglfs.so"
    Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqeglfs.so, metadata=
    {
        "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.2",
        "MetaData": {
            "Keys": [
                "eglfs"
            ]
        },
        "className": "QEglFSIntegrationPlugin",
        "debug": false,
        "version": 328450
    }
    
    
    Got keys from plugin meta data ("eglfs")
    QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqkms.so"
    Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqkms.so, metadata=
    {
        "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.2",
        "MetaData": {
            "Keys": [
                "kms"
            ]
        },
        "className": "QKmsIntegrationPlugin",
        "debug": false,
        "version": 328450
    }
    
    
    Got keys from plugin meta data ("kms")
    QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqlinuxfb.so"
    Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqlinuxfb.so, metadata=
    {
        "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.2",
        "MetaData": {
            "Keys": [
                "linuxfb"
            ]
        },
        "className": "QLinuxFbIntegrationPlugin",
        "debug": false,
        "version": 328450
    }
    
    
    Got keys from plugin meta data ("linuxfb")
    QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqminimal.so"
    Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqminimal.so, metadata=
    {
        "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.2",
        "MetaData": {
            "Keys": [
                "minimal"
            ]
        },
        "className": "QMinimalIntegrationPlugin",
        "debug": false,
        "version": 328450
    }
    
    
    Got keys from plugin meta data ("minimal")
    QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqminimalegl.so"
    Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqminimalegl.so, metadata=
    {
        "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.2",
        "MetaData": {
            "Keys": [
                "minimalegl"
            ]
        },
        "className": "QMinimalEglIntegrationPlugin",
        "debug": false,
        "version": 328450
    }
    
    
    Got keys from plugin meta data ("minimalegl")
    QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqoffscreen.so"
    Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqoffscreen.so, metadata=
    {
        "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.2",
        "MetaData": {
            "Keys": [
                "offscreen"
            ]
        },
        "className": "QOffscreenIntegrationPlugin",
        "debug": false,
        "version": 328450
    }
    
    
    Got keys from plugin meta data ("offscreen")
    QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqxcb.so"
    Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqxcb.so, metadata=
    {
        "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.2",
        "MetaData": {
            "Keys": [
                "xcb"
            ]
        },
        "className": "QXcbIntegrationPlugin",
        "debug": false,
        "version": 328450
    }
    
    
    Got keys from plugin meta data ("xcb")
    QFactoryLoader::QFactoryLoader() checking directory path "/home/user/Documents/Qt Projects/Media-Player/build-Media-Player-Desktop-Release/platforms" ...
    loaded library "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqxcb.so"
    loaded library "Xcursor"
    QFactoryLoader::QFactoryLoader() checking directory path "/usr/lib/x86_64-linux-gnu/qt5/plugins/platformthemes" ...
    QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/platformthemes/libqgtk2.so"
    Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/platformthemes/libqgtk2.so, metadata=
    {
        "IID": "org.qt-project.Qt.QPA.QPlatformThemeFactoryInterface.5.1",
        "MetaData": {
            "Keys": [
                "gtk2"
            ]
        },
        "className": "QGtk2ThemePlugin",
        "debug": false,
        "version": 328450
    }
    
    
    Got keys from plugin meta data ("gtk2")
    QFactoryLoader::QFactoryLoader() checking directory path "/home/user/Documents/Qt Projects/Media-Player/build-Media-Player-Desktop-Release/platformthemes" ...
    loaded library "/usr/lib/x86_64-linux-gnu/qt5/plugins/platformthemes/libqgtk2.so"
    QFactoryLoader::QFactoryLoader() checking directory path "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforminputcontexts" ...
    QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforminputcontexts/libcomposeplatforminputcontextplugin.so"
    Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/platforminputcontexts/libcomposeplatforminputcontextplugin.so, metadata=
    {
        "IID": "org.qt-project.Qt.QPlatformInputContextFactoryInterface",
        "MetaData": {
            "Keys": [
                "compose"
            ]
        },
        "className": "QComposePlatformInputContextPlugin",
        "debug": false,
        "version": 328450
    }
    
    
    Got keys from plugin meta data ("compose")
    QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforminputcontexts/libibusplatforminputcontextplugin.so"
    Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/platforminputcontexts/libibusplatforminputcontextplugin.so, metadata=
    {
        "IID": "org.qt-project.Qt.QPlatformInputContextFactoryInterface",
        "MetaData": {
            "Keys": [
                "ibus"
            ]
        },
        "className": "QIbusPlatformInputContextPlugin",
        "debug": false,
        "version": 328450
    }
    
    
    Got keys from plugin meta data ("ibus")
    QFactoryLoader::QFactoryLoader() checking directory path "/home/user/Documents/Qt Projects/Media-Player/build-Media-Player-Desktop-Release/platforminputcontexts" ...
    loaded library "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforminputcontexts/libcomposeplatforminputcontextplugin.so"
    QFactoryLoader::QFactoryLoader() checking directory path "/usr/lib/x86_64-linux-gnu/qt5/plugins/generic" ...
    QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/generic/libqevdevkeyboardplugin.so"
    Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/generic/libqevdevkeyboardplugin.so, metadata=
    {
        "IID": "org.qt-project.Qt.QGenericPluginFactoryInterface",
        "MetaData": {
            "Keys": [
                "EvdevKeyboard"
            ]
        },
        "className": "QEvdevKeyboardPlugin",
        "debug": false,
        "version": 328450
    }
    
    
    Got keys from plugin meta data ("evdevkeyboard")
    QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/generic/libqevdevmouseplugin.so"
    Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/generic/libqevdevmouseplugin.so, metadata=
    {
        "IID": "org.qt-project.Qt.QGenericPluginFactoryInterface",
        "MetaData": {
            "Keys": [
                "EvdevMouse"
            ]
        },
        "className": "QEvdevMousePlugin",
        "debug": false,
        "version": 328450
    }
    
    
    Got keys from plugin meta data ("evdevmouse")
    QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/generic/libqevdevtabletplugin.so"
    Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/generic/libqevdevtabletplugin.so, metadata=
    {
        "IID": "org.qt-project.Qt.QGenericPluginFactoryInterface",
        "MetaData": {
            "Keys": [
                "EvdevTablet"
            ]
        },
        "className": "QEvdevTabletPlugin",
        "debug": false,
        "version": 328450
    }
    
    
    Got keys from plugin meta data ("evdevtablet")
    QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/generic/libqevdevtouchplugin.so"
    Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/generic/libqevdevtouchplugin.so, metadata=
    {
        "IID": "org.qt-project.Qt.QGenericPluginFactoryInterface",
        "MetaData": {
            "Keys": [
                "EvdevTouch"
            ]
        },
        "className": "QEvdevTouchScreenPlugin",
        "debug": false,
        "version": 328450
    }
    
    
    Got keys from plugin meta data ("evdevtouch")
    QFactoryLoader::QFactoryLoader() checking directory path "/home/user/Documents/Qt Projects/Media-Player/build-Media-Player-Desktop-Release/generic" ...
    QFactoryLoader::QFactoryLoader() checking directory path "/usr/lib/x86_64-linux-gnu/qt5/plugins/styles" ...
    QFactoryLoader::QFactoryLoader() checking directory path "/home/user/Documents/Qt Projects/Media-Player/build-Media-Player-Desktop-Release/styles" ...
    loaded library "gtk-x11-2.0"
    loaded library "gnomeui-2"
    loaded library "gnomevfs-2"
    QFactoryLoader::QFactoryLoader() checking directory path "/usr/lib/x86_64-linux-gnu/qt5/plugins/mediaservice" ...
    QFactoryLoader::QFactoryLoader() checking directory path "/home/user/Documents/Qt Projects/Media-Player/build-Media-Player-Desktop-Release/mediaservice" ...
    defaultServiceProvider::requestService(): no service found for - "org.qt-project.qt.mediaplayer"
    QFactoryLoader::QFactoryLoader() checking directory path "/usr/lib/x86_64-linux-gnu/qt5/plugins/accessiblebridge" ...
    QFactoryLoader::QFactoryLoader() checking directory path "/home/user/Documents/Qt Projects/Media-Player/build-Media-Player-Desktop-Release/accessiblebridge" ...
    QLibraryPrivate::unload succeeded on "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforminputcontexts/libcomposeplatforminputcontextplugin.so" 
    QLibraryPrivate::unload succeeded on "/usr/lib/x86_64-linux-gnu/qt5/plugins/platformthemes/libqgtk2.so" 
    QLibraryPrivate::unload succeeded on "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqxcb.so" 
    QLibraryPrivate::unload succeeded on "Xcursor" (faked)
    QLibraryPrivate::unload succeeded on "gnomevfs-2" (faked)
    QLibraryPrivate::unload succeeded on "gtk-x11-2.0" (faked)
    /home/user/Documents/Qt Projects/Media-Player/build-Media-Player-Desktop-Release/Media-Player exited with code 0
    

  • Moderators

    @6EQUJ5 Is there something in /usr/lib/x86_64-linux-gnu/qt5/plugins/mediaservice ?



  • @jsulm The folder mediaservice in /usr/lib/x86_64-linux-gnu/qt5/plugins/ doesn't exist.


  • Moderators

    @6EQUJ5 Looks like media plug-ins are missing.


  • Moderators

    @6EQUJ5 Install libqt5multimedia5-plugins package



  • @jsulm I got this now:

    (Media-Player:7076): GStreamer-CRITICAL **: gst_object_ref_sink: assertion 'GST_IS_OBJECT (object)' failed


  • Moderators

    @6EQUJ5 Can you post the output with QT_DEBUG_PLUGINS again?


  • Moderators

    @6EQUJ5 Also: can you play a media file now?



Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.