Results 1 to 6 of 6

Thread: Problem with the QWidget::winId() method

  1. #1
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default Problem with the QWidget::winId() method

    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
    Qt Code:
    1. #ifndef _WIDGET_VIDEO_H
    2. #define _WIDGET_VIDEO_H
    3.  
    4. #include <qwidget.h>
    5.  
    6. class QString;
    7. class QProcess;
    8.  
    9. class CWidgetVideo : public QWidget
    10. {
    11. public:
    12. CWidgetVideo(QWidget* parent=0, const char* name=0);
    13. ~WidgetVideo();
    14.  
    15. public:
    16. void StartVideo(const QString& video);
    17. void StopVideo();
    18.  
    19. private:
    20. QProcess* m_pProcessVideo;
    21. };
    22. #endif
    To copy to clipboard, switch view to plain text mode 

    .cpp
    Qt Code:
    1. #include "WidgetVideo.h"
    2. #include <qapplication.h>
    3. #include <qstring.h>
    4. #include <qprocess.h>
    5.  
    6. CWidgetVideo::CWidgetVideo(QWidget* parent/*=0*/, const char* name/*=0*/):
    7. QWidget(parent, name),
    8. m_pProcessVideo(0)
    9. {
    10. }
    11.  
    12. CWidgetVideo::~CWidgetVideo()
    13. {
    14. StopVideo();
    15. }
    16.  
    17. void CWidgetVideo::StartVideo(const QString& video)
    18. {
    19. setBackgroundColor(QColor(255, 0, 255));
    20.  
    21. if( m_pProcessVideo )
    22. StopVideo();
    23.  
    24. m_pProcessVideo = new QProcess( this );
    25.  
    26. m_pProcessVideo->addArgument("C:\\MPLAYER\\mplayer.exe");
    27. m_pProcessVideo->addArgument("-wid");
    28. m_pProcessVideo->addArgument(QString::number((int)winId()));
    29. m_pProcessVideo->addArgument(video);
    30.  
    31. if( !m_pProcessVideo->start() )
    32. qDebug("Impossible to start");
    33. }
    34.  
    35. void CWidgetVideo::StopVideo()
    36. {
    37. if( m_pProcessVideo )
    38. {
    39. m_pProcessVideo->tryTerminate();
    40.  
    41. delete m_pProcessVideo;
    42. m_pProcessVideo = 0;
    43. }
    44. }
    To copy to clipboard, switch view to plain text mode 

    Finally the main application source code :
    Qt Code:
    1. void TestMPlayerDialog::init()
    2. {
    3. m_pPlayer = 0;
    4. }
    5.  
    6.  
    7. void TestMPlayerDialog::starting()
    8. {
    9. QString directory = QDir::currentDirPath() + "/";
    10. QString video = QFileDialog::getOpenFileName(directory, "Video (*.avi *.wmv *.mpeg *.mov)", this, "", "");
    11.  
    12. if( video != "" )
    13. {
    14. if( m_pPlayer )
    15. {
    16. delete m_pPlayer;
    17. m_pPlayer = 0;
    18. }
    19.  
    20. m_pPlayer = new CWidgetVideo(this, "Player");
    21.  
    22. m_pPlayer->setGeometry(10, 120, 320, 240);
    23. m_pPlayer->StartVideo(video);
    24. m_pPlayer->show();
    25. }
    26. }
    27.  
    28.  
    29. void TestMPlayerDialog::stopping()
    30. {
    31. if( m_pPlayer )
    32. {
    33. m_pPlayer->StopVideo();
    34. m_pPlayer->hide();
    35.  
    36. delete m_pPlayer;
    37. m_pPlayer = 0;
    38. }
    39. }
    To copy to clipboard, switch view to plain text mode 

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

    I hope someone could help me, thantks in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem with the QWidget::winId() method

    You need to force OpenGL or DirectX output. Try adding a -vo gl2 (or -vo directx) option to mplayer.

  3. #3
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: Problem with the QWidget::winId() method

    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.

  4. #4
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: Problem with the QWidget::winId() method

    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.

  5. #5
    Join Date
    Jan 2008
    Posts
    72
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Unhappy Re: Problem with the QWidget::winId() method

    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

  6. #6
    Join Date
    Jan 2008
    Posts
    72
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Smile Re: Problem with the QWidget::winId() method

    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 ........
    this is solution..............

Similar Threads

  1. QT4 scope problem
    By the_bis in forum Newbie
    Replies: 5
    Last Post: 29th January 2007, 23:01
  2. Replies: 2
    Last Post: 8th October 2006, 20:14
  3. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 12:54
  4. Replies: 16
    Last Post: 7th March 2006, 15:57
  5. Problem with QScrollArea updating from 4.0.1 to 4.1.0
    By SkripT in forum Qt Programming
    Replies: 8
    Last Post: 28th January 2006, 22:35

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.