QDialog中的Phonon :: VideoWidget问题

时间:2011-03-02 00:56:52

标签: c++ qt phonon

我正在使用QDialog作为主窗口编写应用程序。在这个应用程序中,我有3个QGroupBox,一个有几个按钮,第二个有一个GLWidget显示网络摄像头内容(使用OpenCV捕获和处理并用OpenGL显示),在第三个我尝试使用Phonon播放不同的视频(基本上我打算使用QComboBox选择视频,虽然这与我的问题无关)。

一切正常,GUI初始化,做我需要的一切......直到我尝试创建一个VideoWidget对象。这是我班级的代码:

    GUIT::GUIT(QWidget *parent, Qt::WFlags flags)
    {       

        // Initialization of the different QGroupBox
        createVideo();  
        createButtons();
        createScoreFE();
        createPhonon();

        gbScoreFE->hide();

        QHBoxLayout *layout = new QHBoxLayout;
        QVBoxLayout *mainLayout = new QVBoxLayout;
        mainLayout->addWidget(gbVideo, 0, 0);
        mainLayout->addWidget(gbButtons, 1, 0);
        mainLayout->addWidget(gbScoreFE, 0, 0);

        layout->addLayout(mainLayout);
        layout->addWidget(gbPhonon);

        gbPhonon->hide();   

        this->setLayout(layout);

        layout->setSizeConstraint(QLayout::SetFixedSize);

    }

崩溃的方法是:

void GUIT::createPhonon()
{

    gbPhonon = new QGroupBox(tr("Test"));

    // This line makes the program to stop executing.
    Phonon::VideoWidget *_player_video = new Phonon::VideoWidget;

    QVBoxLayout *layout = new QVBoxLayout;

    gbPhonon->setLayout(layout);

}

它是如何崩溃的?好吧,它只是在创建一个新的VideoWidget后杀了几个线程。它看起来像:

The thread 'Win32 Thread' (0x12e8) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0x1304) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0xf20) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0xdec) has exited with code 1 (0x1).
The thread 'QThread' (0x1e20) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0x19b0) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0x1f58) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0x1794) has exited with code 1 (0x1).

事实是我对这个问题有点困惑。当我在编写QWidget时,我会用它的组件创建VideoWidget ...我检查了其他Phonon类,并且GUI在初始化时不受影响。例如:

Phonon::MediaObject *mediaObject = new Phonon::MediaObject(this);

我还尝试用更简单的GUI重现问题,并且编译和工作没有问题,所以应该有一些与Phonon冲突的东西。我以为它可能是GLWidget,但是我断开了GUI的这一部分......它仍然杀死了线程。

有人遇到过类似的问题吗?有人知道可能出现什么问题或如何检查线程杀死吗?

2 个答案:

答案 0 :(得分:0)

我认为QDialog是造成这个问题的原因。

答案 1 :(得分:0)

#ifndef DIALOG_H
#define DIALOG_H

#include <QDialog>
#include <QVBoxLayout>
#include <QGroupBox>
#include <Phonon>
#include <QPushButton>

class Dialog : public QDialog
{
    Q_OBJECT
public:
    explicit Dialog(QWidget *parent = 0);

private:
    QGroupBox *gbButtons;
    QGroupBox *gbPhonon;
    QVBoxLayout *mainLayout;
    QPushButton *btnPlay;

    Phonon::AudioOutput *audioOut;
    Phonon::VideoWidget *vWidget;
    Phonon::MediaObject *mObject;

    void createPhonon();
    void createButtons();

private slots:
    void playVideo();
};

#endif // DIALOG_H


#include "dialog.h"

Dialog::Dialog(QWidget *parent) :
    QDialog(parent)
{
    mainLayout = new QVBoxLayout();
    createButtons();
    createPhonon();

    setLayout(mainLayout);
}

void Dialog::createButtons()
{
    gbButtons = new QGroupBox("Buttons");
    btnPlay = new QPushButton("Play",gbButtons);
    connect(btnPlay,SIGNAL(clicked()),this,SLOT(playVideo()));
    mainLayout->addWidget(gbButtons);
}

void Dialog::createPhonon()
{
    gbPhonon = new QGroupBox("Phonon");

    QVBoxLayout *vLayout = new QVBoxLayout();
    vWidget = new Phonon::VideoWidget;
    mObject = new Phonon::MediaObject;
    audioOut = new Phonon::AudioOutput(Phonon::VideoCategory);

    Phonon::createPath(mObject,vWidget);
    Phonon::createPath(mObject,audioOut);

    vLayout->addWidget(vWidget);
    gbPhonon->setLayout(vLayout);
    mainLayout->addWidget(gbPhonon);

    gbPhonon->hide();
}

void Dialog::playVideo(){

    gbPhonon->show();
    mObject->setCurrentSource(Phonon::MediaSource("C:/Videos/Loving You Tonight.mp4"));
    mObject->play();
}