简体   繁体   English

菜单栏功能在 Qt 中不起作用

[英]menu bar functionalities aren't working in Qt

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: 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: cp:

    #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();
}

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....不在应该的位置,因为您正在将信号连接到 SLOT 实现的插槽 INSIDE....

try moving that to the constructor of dein videoWidget尝试将其移至 dein videoWidget 的构造函数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM