menu bar functionalities aren't working in Qt

Viewed 35

so i am writing a simple video player program and i did the same steps as the lesson i am taking but when i run the program and click on functionalities like end (which is close()) and open (open file) they dont work, i used the slot triggering as per the lesson although i saw different ways of using the menubar here but i must follow this format, here is my code:

header:

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QPushButton>
#include <QVideoWidget>
#include <QStyle>
#include <QMediaPlayer>
#include <QFileDialog >

namespace Ui {
class videoWidget;
}
class videoWidget : public QMainWindow
{
    Q_OBJECT
    QMediaPlayer *meinPlayer;

    QPushButton *playButton;
    QPushButton *stopButton;
public:
    explicit videoWidget(QWidget *parent = 0);
~videoWidget();
private slots:
  void  listeUndTitelAktualisieren();
  void on_action_End_triggered();

  void on_action_ffnen_triggered();

  void on_action_Stop_triggered();

  void on_action_PlayBack_triggered();

  void on_action_Pause_triggered();

private:
    Ui::videoWidget *ui;
};

#endif // MAINWINDOW_H

cpp:

    #include "mainwindow.h"
#include "ui_mainwindow.h"

videoWidget::videoWidget(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::videoWidget)
{
    ui->setupUi(this);
    meinPlayer = new QMediaPlayer(this);
    meinPlayer->setMedia(QUrl::fromLocalFile("/beispiele/topologien.wmv"));
    meinPlayer->play();
}

void videoWidget::listeUndTitelAktualisieren()
{
    QString titel = meinPlayer->media().canonicalUrl().toLocalFile();
    ui->listWidget->addItem(titel);
    this->setWindowTitle("Multimedia-Player – " + titel);

    connect(meinPlayer, SIGNAL(mediaChanged(QMediaContent)), this, SLOT(listeUndTitelAktualisieren()));
}

void videoWidget::on_action_End_triggered()
{
    this->close();
}

void videoWidget::on_action_ffnen_triggered()
{
    QFileDialog *meinDialog = new QFileDialog(this);
    meinDialog->setAcceptMode(QFileDialog::AcceptOpen);
    meinDialog->setWindowTitle("Datei öffnen");
    meinDialog->setNameFilters(QStringList() << "Videos (*.mp4 *.wmv)" << "Audios (*.mp3)" << "Alle Dateien (*.*)");
    meinDialog->setDirectory(QDir::currentPath());
    meinDialog->setFileMode(QFileDialog::ExistingFile);
    if (meinDialog->exec() == QDialog::Accepted) {
        QString datei = meinDialog->selectedFiles().first();
        meinPlayer->setMedia(QUrl::fromLocalFile(datei));
      /*QString  fileName = QFileDialog::getOpenFileName(this,
              tr("Open Image"), "/home/jana", tr("Video & Audio Files (*.mp3 *.mp4 *.wmv)"));
*/
        meinPlayer->play();
    }
}

    void videoWidget::on_action_Stop_triggered()
{
meinPlayer->pause();
}

    void videoWidget::on_action_PlayBack_triggered()
{
    meinPlayer->play();
}

    void videoWidget::on_action_Pause_triggered()
{
    meinPlayer->pause();
}
1 Answers

am pretty sure this instruction here:

 connect(meinPlayer, SIGNAL(mediaChanged(QMediaContent)), this, SLOT(listeUndTitelAktualisieren()));

is not located where it should coz you are connecting the signal toa slot INSIDE of the SLOT implementation....

try moving that to the constructor of dein videoWidget

Related