嗨我有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);
}
来源^
现在应用程序运行没有问题但是当我点击&#34; dodaj plik&#34;没有任何反应,调试器说没有像startVideo()
你能帮我解决一下吗?
答案 0 :(得分:0)
问题是你建立了这样的连接:
QObject::connect(addFile, SIGNAL(clicked()), player, SLOT(startVideo()));
但是startVideo()
类中定义了MainWindow
个广告位。因此,正确的连接应如下所示:
connect(addFile, SIGNAL(clicked()), this, SLOT(startVideo()));
不需要QObject::
前缀,因为QMainWindow
- 基类已经是QObject
。