【问题标题】:Phonon::VideoPlayer Qt 4.8.6Phonon::VideoPlayer Qt 4.8.6
【发布时间】:2014-05-26 09:41:45
【问题描述】:

您好,我对 Phonon 和插槽有疑问,这是我第一次尝试,希望您能帮助我,

#include <QMainWindow>
#include <QWidget>
#include <phonon/VideoPlayer>
#include <phonon/VideoWidget>
#include <phonon/MediaObject>
#include <phonon/MediaSource>
#include <phonon>
#include <QVBoxLayout>
#include <QFileDialog>
#include <QPushButton>
#include <QUrl>

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
MainWindow(QWidget *parent = 0);
~MainWindow();
QPushButton *quit;
QPushButton *addFile;
QWidget *Main;
Phonon::VideoPlayer *player;
public slots:

    void startVideo();

};

我的标题 ^

#include "mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
Main = new QWidget;
addFile = new QPushButton("Dodaj Plik");
quit = new QPushButton("Zamknij");
player = new Phonon::VideoPlayer(Phonon::VideoCategory, Main);
QVBoxLayout *layout = new QVBoxLayout;
    layout->addWidget(addFile);
    layout->addWidget(quit);
    layout->addWidget(player);
Main->setWindowTitle("Phonon");
Main->setLayout(layout);
Main->setGeometry(550, 312, 640, 480);
Main->show();
QObject::connect(addFile, SIGNAL(clicked()), player, SLOT(startVideo()));
QObject::connect(quit, SIGNAL(clicked()), Main, SLOT(close()));
}

MainWindow::~MainWindow()
{

}
void MainWindow::startVideo()
{
QString file = QFileDialog::getOpenFileName(this, tr("odtworz film"));
player->play(file);
}

来源^

现在应用程序运行没有问题,但是当我点击“dodaj plik”时没有任何反应,调试器说它没有像startVideo()这样的插槽

你能帮我弄清楚吗?

【问题讨论】:

    标签: qt video video-player phonon


    【解决方案1】:

    问题是你建立这样的连接:

    QObject::connect(addFile, SIGNAL(clicked()), player, SLOT(startVideo()));
    

    但是您的 startVideo() 插槽在 MainWindow 类中定义。因此,正确的连接应该如下所示:

    connect(addFile, SIGNAL(clicked()), this, SLOT(startVideo()));
    

    不需要QObject:: 前缀,因为QMainWindow - 基类,已经是QObject

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多