I am starting out in C++ and I am trying to play an mp3 file with Qt. I wrote this code but it is not working for some reason. I have searched the internet but was unable to find something that would help.
Here's my code:
#include <iostream>
#include <QMediaPlayer>
#include <QMediaPlaylist>
#include <QFileInfo>
#include <QUrl>
int main()
{
QMediaPlaylist *list = new QMediaPlaylist;
list->addMedia(QUrl::fromLocalFile(QFileInfo("Filename.mp3").absoluteFilePath()));
QMediaPlayer *music;
music = new QMediaPlayer();
music->setPlaylist(list);
music->play();
return 0;
}
There is no music playing and the output of this program is:
QObject::startTimer: Timers can only be used with threads started with QThread
QObject::startTimer: Timers can only be used with threads started with QThread
Here's my .pro
file:
TEMPLATE = app
TARGET = MediaPlayer
QT += core multimedia
SOURCES += main.cpp
Environment:
Fedora 29
Qt 5.11.3-1
I tried to run this program on Qt creator and on terminal.