MediaPlayer.h
#ifndef MEDIAPLAYER_H
#define MEDIAPLAYER_H
#include<QWidget>
#include<QKeyEvent>
#include<QPushButton>
#include<QHBoxLayout>
#include<QFileDialog>
#include<phonon>
#include<QMessageBox>
#include<QTimer>
#include<QSpinBox>
#include<QVBoxLayout>
#include<QGridLayout>
namespace Phonon
{
class AudioOutput;
class MediaObject;
}
//===================================
class Player:public QWidget
{
Q_OBJECT
private:
QTimer* timer[8];
Phonon::AudioOutput* ao[8];
Phonon::MediaObject* media[8];
QSpinBox* spb[8];
public:
Player (QWidget *parent = 0);
void keyPressEvent(QKeyEvent *);
public slots:
void slotLoad(int i);
void timer_start(int i);
};
#endif // MEDIAPLAYER_H
#include<MediaPlayer.h>
Player::Player(QWidget *parent):QWidget(parent)
{
QPushButton *load[8];
QVBoxLayout *vlayout = new QVBoxLayout;
int i;
for(i=0;i<8;i++)
{
media[i] = new Phonon::MediaObject(this);
ao[i] = new Phonon::AudioOutput(Phonon::MusicCategory,this);
spb[i] = new QSpinBox(this);
timer[i] = new QTimer(this);
Phonon::createPath(media[i],ao[i]);
load[i] = new QPushButton ("Load");
spb[i]->setRange(1,20);
spb[i]->setValue(i+1);
connect (load[i],SIGNAL(clicked()),SLOT(slotLoad(int i)));
//==========================================>
QHBoxLayout *hlayout = new QHBoxLayout;
hlayout->addWidget(spb[i]);
hlayout->addWidget(load[i]);
vlayout->addLayout(hlayout);
}
setLayout(vlayout);
}
void Player::slotLoad(int i)
{
QString str = QFileDialog::getOpenFileName(0, "Load", "", "*.mp3");
if(!str.isEmpty())
{
media[i]->setCurrentSource(Phonon::MediaSource(str));
}
}
void Player::keyPressEvent(QKeyEvent *e)
{
switch(e->key())
{
case Qt::Key_F5:
timer_start(0);
break;
case Qt::Key_F6:
timer_start(1);
break;
}
}
void Player::timer_start(int i)
{
timer[i]->start(spb[i]->value()*1000);
connect(timer[i],SIGNAL(timeout()),media[i],SLOT(play()));
}
slotLoad(int i)
такого наверное действительно нет.
есть такой
slotLoad(int )
А как это тогда сделать? что бы у меня было кнопок "Load"?
upd. имел ввиду 8 кнопок*
посмотри на QSignalMapper в частности его использование в примере calculator
Форум Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)