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 += multimediaThen 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.
-
Hi and welcome to devnet,
You are missing
QT += multimediawidgets
in your .pro file. -
Did you re-run qmake after modifying the
QT
variable ? -
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.
-
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\playerYou 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?
-
You should start by testing with your distribution provided Qt to ensure that everything is working correctly.
-
How to ensure the multimedia backend is available or not? I try 2 methods before:
- Use default application of Qt(qmlvideo, player, ...)
-> If one of them can run well, we can conclude it's OK - 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.0For set up Gstreamer on Linux, please refer to:
https://gstreamer.freedesktop.org/documentation/installing/on-linux.htmlBest regards,
Khoa - Use default application of Qt(qmlvideo, player, ...)
-
@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 insudo 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?
-
@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
withsudo 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)