PDA

View Full Version : Problem with the QWidget::winId() method



yellowmat
2nd March 2007, 10:13
Hi everybody,

As explain in the title, I (think I) have a problem with the QWidget::winId() method return value.

I am using mplayer to play movies in my application. I use the -wid argument to tell mplayer into which widget to display. I can hear sound but I can't see the video.

I did the followings tests :
* I try to run, in the command line, mplayer with the name of a movie file as the only argument ... it works fine because a window opens, and I can see the movie
* I try to do the same in my application, adding the -wid argument with the widget id ... I can hear sounds but can't see anything
* I use a specific background color for my widget in order to be sure it is shown when I request mplayer to play the movie ... I can see a square, with the specific background color where the movie (the widget itself) is supposed to be played so the widget is well shown

So, I don't understand why I can't see the movie.

Here is the code of my widget :
.h


#ifndef _WIDGET_VIDEO_H
#define _WIDGET_VIDEO_H

#include <qwidget.h>

class QString;
class QProcess;

class CWidgetVideo : public QWidget
{
public:
CWidgetVideo(QWidget* parent=0, const char* name=0);
~WidgetVideo();

public:
void StartVideo(const QString& video);
void StopVideo();

private:
QProcess* m_pProcessVideo;
};
#endif


.cpp


#include "WidgetVideo.h"
#include <qapplication.h>
#include <qstring.h>
#include <qprocess.h>

CWidgetVideo::CWidgetVideo(QWidget* parent/*=0*/, const char* name/*=0*/):
QWidget(parent, name),
m_pProcessVideo(0)
{
}

CWidgetVideo::~CWidgetVideo()
{
StopVideo();
}

void CWidgetVideo::StartVideo(const QString& video)
{
setBackgroundColor(QColor(255, 0, 255));

if( m_pProcessVideo )
StopVideo();

m_pProcessVideo = new QProcess( this );

m_pProcessVideo->addArgument("C:\\MPLAYER\\mplayer.exe");
m_pProcessVideo->addArgument("-wid");
m_pProcessVideo->addArgument(QString::number((int)winId()));
m_pProcessVideo->addArgument(video);

if( !m_pProcessVideo->start() )
qDebug("Impossible to start");
}

void CWidgetVideo::StopVideo()
{
if( m_pProcessVideo )
{
m_pProcessVideo->tryTerminate();

delete m_pProcessVideo;
m_pProcessVideo = 0;
}
}


Finally the main application source code :


void TestMPlayerDialog::init()
{
m_pPlayer = 0;
}


void TestMPlayerDialog::starting()
{
QString directory = QDir::currentDirPath() + "/";
QString video = QFileDialog::getOpenFileName(directory, "Video (*.avi *.wmv *.mpeg *.mov)", this, "", "");

if( video != "" )
{
if( m_pPlayer )
{
delete m_pPlayer;
m_pPlayer = 0;
}

m_pPlayer = new CWidgetVideo(this, "Player");

m_pPlayer->setGeometry(10, 120, 320, 240);
m_pPlayer->StartVideo(video);
m_pPlayer->show();
}
}


void TestMPlayerDialog::stopping()
{
if( m_pPlayer )
{
m_pPlayer->StopVideo();
m_pPlayer->hide();

delete m_pPlayer;
m_pPlayer = 0;
}
}


starting and stopping are two slots called when buttons start and stop are pressed.

I hope someone could help me, thantks in advance.

wysota
2nd March 2007, 10:44
You need to force OpenGL or DirectX output. Try adding a -vo gl2 (or -vo directx) option to mplayer.

yellowmat
2nd March 2007, 10:51
I have already tryed with those two options without success :
* No sound and no video when forcing output to OpenGL
* No video when forving output to DirectX

It is strange because ... I'm not sure of that ... but the same application played video with success under Windows2000, but as I said, I'm not sure of that point.

yellowmat
2nd March 2007, 11:05
I works now, since I tell mplayer to use directx as you advise me but I also specify the noaccel argument because it is the source of my problem ... I found it into the pages of mplayer.

Thanks for your help.

MrShahi
22nd April 2008, 11:33
yes its is the problem of winId() because in window os QWidget->winId() return H_WND which makes problem to embed the mplayer within QWidget.....
I have the same problem. If any one can solve this problem please do it fast .I need your help..........
thanx in advance:rolleyes:

MrShahi
22nd April 2008, 12:15
hello guys .....I have solved this problem .........you can embed mplayer within QWidget in window o.s .
Simply use the -vo option with directx:noaccel ........:cool:
this is solution.............. ;)