有關使用qprocess來播放mp3的問題

喜歡程式設計嗎?想要一窺 KDE/Qt 程式設計的奧秘嗎?想要
學習 X Window 上的視窗程式設計嗎?歡迎各類關於 KDE/Qt、Qtopia、Qt/Embedded、QSA、PyQt 等各類心得討論。

版主: AceLan, Franklin

有關使用qprocess來播放mp3的問題

文章tourach » 週五 6月 13, 2008 9:56 pm

小弟最近想要使用QProcess來播放單一個mp3檔案

原本的目標是設計一個簡單的dialog

裡面有兩個button

其中一個按了後可以播mp3

另一個按了就會把dialog關掉

但是一直放不出聲音來

想請教各位先進要如何解決

以下是小弟的code:

main.cpp:
#include <qapplication.h>
#include <test00.h>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Test00 *dialog = new Test00;
app.setMainWidget(dialog);
dialog->show();
return app.exec();
}

test00.h:
#ifndef TEST00_H
#define TEST00_H

#include <qvariant.h>
#include <qdialog.h>

class QVBoxLayout;
class QHBoxLayout;
class QGridLayout;
class QSpacerItem;
class QLabel;
class QPushButton;

class Test00 : public QDialog
{
Q_OBJECT

public:
Test00( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 );
~Test00();

QLabel* label;
QPushButton* play;
QPushButton* quit;

public slots:
virtual void play_mp3();

protected:
QVBoxLayout* layout2;
QHBoxLayout* layout1;

protected slots:
virtual void languageChange();

};

#endif // TEST00_H

test00.cpp
#include "test00.h"

#include <qvariant.h>
#include <qlabel.h>
#include <qpushbutton.h>
#include <qlayout.h>
#include <qtooltip.h>
#include <qwhatsthis.h>
#include "test00.ui.h"

/*
* Constructs a Test00 as a child of 'parent', with the
* name 'name' and widget flags set to 'f'.
*
* The dialog will by default be modeless, unless you set 'modal' to
* TRUE to construct a modal dialog.
*/
Test00::Test00( QWidget* parent, const char* name, bool modal, WFlags fl )
: QDialog( parent, name, modal, fl )
{
if ( !name )
setName( "Test00" );

QWidget* privateLayoutWidget = new QWidget( this, "layout2" );
privateLayoutWidget->setGeometry( QRect( 110, 40, 174, 56 ) );
layout2 = new QVBoxLayout( privateLayoutWidget, 11, 6, "layout2");

label = new QLabel( privateLayoutWidget, "label" );
layout2->addWidget( label );

layout1 = new QHBoxLayout( 0, 0, 6, "layout1");

play = new QPushButton( privateLayoutWidget, "play" );
layout1->addWidget( play );

quit = new QPushButton( privateLayoutWidget, "quit" );
layout1->addWidget( quit );
layout2->addLayout( layout1 );
languageChange();
resize( QSize(394, 136).expandedTo(minimumSizeHint()) );
clearWState( WState_Polished );

// signals and slots connections
connect( quit, SIGNAL( clicked() ), this, SLOT( close() ) );
connect( play, SIGNAL( clicked() ), this, SLOT( play_mp3() ) );
}

/*
* Destroys the object and frees any allocated resources
*/
Test00::~Test00()
{
// no need to delete child widgets, Qt does it all for us
}

/*
* Sets the strings of the subwidgets using the current
* language.
*/
void Test00::languageChange()
{
setCaption( tr( "Mplayer Test" ) );
label->setText( tr( "<p align=\"center\">It is a brave try......</p>" ) );
play->setText( tr( "play" ) );
quit->setText( tr( "quit" ) );
}

test00.ui.h
#include <qprocess.h>
#include <qstring.h>

void Test00::play_mp3()
{
QProcess *myP = new QProcess;
myP->addArgument("/root/Video/MPlayer-1.0rc2/mplayer");
myP->addArgument(" /root/Music/01.mp3");
myP->start();
}


在這裡先謝過大家了
tourach
可愛的小學生
可愛的小學生
 
文章: 1
註冊時間: 週四 5月 29, 2008 1:43 pm

回到 KDE/Qt 程式設計

誰在線上

正在瀏覽這個版面的使用者:沒有註冊會員 和 1 位訪客