qt中Qsound怎么声明?为何我更改了pro里面的内容增加了QT += multimedia还是不行?求教。

QT的版本。... QT的版本。 展开
 我来答
次迈0O
推荐于2016-01-07 · TA获得超过355个赞
知道小有建树答主
回答量:564
采纳率:50%
帮助的人:193万
展开全部

The QSound class provides a method to play .wav sound files. More...


Header: #include <QSound>

qmake: QT += multimedia

Inherits: QObject.

List of all members, including inherited members

Public Types


enum Loop { Infinite }

Public Functions


QSound(const QString & filename, QObject * parent = 0)

~QSound()

QString fileName() const

bool isFinished() const

int loops() const

int loopsRemaining() const

void setLoops(int number)

31 public functions inherited from QObject

Public Slots


void play()

void stop()

1 public slot inherited from QObject

Static Public Members


void play(const QString & filename)

10 static public members inherited from QObject

Additional Inherited Members


1 property inherited from QObject

2 signals inherited from QObject

1 public variable inherited from QObject

9 protected functions inherited from QObject

2 protected variables inherited from QObject

Detailed Description


The QSound class provides a method to play .wav sound files.


Qt provides the most commonly required audio operation in GUI applications: asynchronously playing a sound file. This is most easily accomplished using the static play() function:


QSound::play("mysounds/bells.wav");

Alternatively, create a QSound object from the sound file first and then call the play() slot:


QSound bells("mysounds/bells.wav");

bells.play();

Once created a QSound object can be queried for its fileName() and total number of loops() (i.e. the number of times the sound will play). The number of repetitions can be altered using the setLoops() function. While playing the sound, the loopsRemaining() function returns the remaining number of repetitions. Use the isFinished() function to determine whether the sound has finished playing.


Sounds played using a QSound object may use more memory than the static play() function, but it may also play more immediately (depending on the underlying platform audio facilities).


If you require finer control over playing sounds, consider the QSoundEffect or QAudioOutput classes.


See also QSoundEffect.


Member Type Documentation


enum QSound::Loop

Constant Value Description

QSound::Infinite -1 Can be used as a parameter to setLoops() to loop infinitely.

Member Function Documentation


QSound::QSound(const QString & filename, QObject * parent = 0)

Constructs a QSound object from the file specified by the given filename and with the given parent.


See also play().


QSound::~QSound()

Destroys this sound object. If the sound is not finished playing, the stop() function is called before the sound object is destroyed.


See also stop() and isFinished().


QString QSound::fileName() const

Returns the filename associated with this QSound object.


See also QSound().


bool QSound::isFinished() const

Returns true if the sound has finished playing; otherwise returns false.


int QSound::loops() const

Returns the number of times the sound will play. Return value of QSound::Infinite indicates infinite number of loops


See also loopsRemaining() and setLoops().


int QSound::loopsRemaining() const

Returns the remaining number of times the sound will loop (for all positive values this value decreases each time the sound is played). Return value of QSound::Infinite indicates infinite number of loops


See also loops() and isFinished().


[static] void QSound::play(const QString & filename)

Plays the sound stored in the file specified by the given filename.


See also stop(), loopsRemaining(), and isFinished().


[slot] void QSound::play()

This is an overloaded function.


Starts playing the sound specified by this QSound object.


The function returns immediately. Depending on the platform audio facilities, other sounds may stop or be mixed with the new sound. The sound can be played again at any time, possibly mixing or replacing previous plays of the sound.


See also fileName().


void QSound::setLoops(int number)

Sets the sound to repeat the given number of times when it is played.


Note that passing the value QSound::Infinite will cause the sound to loop indefinitely.


See also loops().


[slot] void QSound::stop()

Stops the sound playing.


See also play().


以上内容来之Qt帮助文档

推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式