QMediaPlayer and QMediaPlaylist - problem with next
-
Crashes, I just click on the "Next"
-
What does a run with the debugger tell you ?
-
http://imageshack.com/a/img199/3483/1ljx.png
Console : Rozpoczęto debugowanie
QEventLoop: Cannot be used without QApplication
QObject::connect: Cannot connect (null)::aboutToQuit() to QNativeWifiEngine::closeHandle() -
How does your main.cpp look like ?
Also, why make player and playlist static ?
-
main.cpp
@#include "mainwindow.h"
#include <QApplication>int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();return a.exec();
}
@mainwindow.h
@#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>
namespace Ui {
class MainWindow;
}class MainWindow : public QMainWindow
{
Q_OBJECTpublic:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();private slots:
void on_pushButton_clicked();void on_pushButton_2_clicked(); void on_horizontalSlider_sliderMoved(int position); void aktualna_pozycja(qint64 position); void on_pushButton_3_clicked(); void run_file(QString file); void on_pause_clicked(); void on_next_file_clicked(); void on_pushButton_4_clicked();
private:
Ui::MainWindow *ui;
};#endif // MAINWINDOW_H
@test_sound.pro
@#-------------------------------------------------Project created by QtCreator 2014-02-04T19:08:13
#-------------------------------------------------
QT += core gui
QT += widgets multimedia
QT += multimedia
QT += core gui multimediagreaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = test_sound
TEMPLATE = appSOURCES += main.cpp
mainwindow.cppHEADERS += mainwindow.h
FORMS += mainwindow.ui
@ -
Looks right.
Please move both player and playlist has non static member variable of MainWindow and try again
-
I do not understand. I could explain it somehow differently?
-
@QMediaPlayer *player = new QMediaPlayer();
QMediaPlaylist *playlist = new QMediaPlaylist;@These are static, remove them. And add two member variable in MainWindow to replace them.
@mainwindow.h
class MainWindow : public QMainWindow {
…private:
QMediaPlayer *_player;
QMediaPlaylist *_playlist;}
mainwindow.cpp
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
_player(new QMediaPlayer),
_playlist(new QMediaPlayList)
{
ui->setupUi(this);QObject::connect(_player, SIGNAL(positionChanged(qint64)), this, SLOT(aktualna_pozycja(qint64)));
}
@Something like that
-
@mainwindow.h
...
private:
Ui::MainWindow *ui;
QMediaPlayer *player;
QMediaPlayer *playlist;
};@@mainwindow.cpp
...
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
player(new QMediaPlayer),
playlist(new QMediaPlaylist)
{
ui->setupUi(this);QObject::connect(player, SIGNAL(positionChanged(qint64)), this, SLOT(aktualna_pozycja(qint64)));
}
...
@błąd: cannot convert 'QMediaPlaylist*' to 'QMediaPlayer*' in initialization
playlist(new QMediaPlaylist)błąd: 'class QMediaPlayer' has no member named 'addMedia' playlist->addMedia(QUrl::fromLocalFile(file));
-
The error is pretty clear, you declared playlist list as a QMediaPlayer and not QMediaPlayList.
-
Okay, thank you. Now the program compiles correctly, but it is still the same problem.
After pressing the "Next" button shows up is:
-
Run your program using the debugger, that should catch the problem
-