Problem with Phonon::VideoWidget in QDialog
I am writing an application using a QDialog as the main Window. In this application I have 3 QGroupBox, one with several Buttons, the second one with a GLWidget displaying webcam content (captured and processed using OpenCV and displayed with OpenGL), and in the third one I was trying to play different videos using Phonon (basically I intend to select the videos using a QComboBox, although this is not relevant to my probl开发者_运维问答em).
Everything works, the GUI initializes, does everything that I need... until I try to create a VideoWidget object. This is the code of my class:
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);
}
And the method that crashes is:
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);
}
How does it crashes?? Well, it just kills several threads after creating a new VideoWidget. It just looks like:
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).
The truth is that I'm a little bit confused about this problem. It arise while I was writing a QWidget where I was going to create the VideoWidget with its components... I checked other Phonon classes, and the GUI is not affected when they are initialized. Eg:
Phonon::MediaObject *mediaObject = new Phonon::MediaObject(this);
I have also tried to reproduce the problem with a simpler GUI, and it compiles and works with no problem, so there should be something that is in conflict with Phonon. I thought it could be the GLWidget, but I disconnected this part of the GUI... and it still kills the threads.
Has somebody run into a similar problem? Has somebody any insight of what could be going wrong or how to check the thread kills?
I think QDialog is the reason to cause that problem.
#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();
}
精彩评论