小弟最近想要使用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();
}
在這裡先謝過大家了