Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QSound Class

TheQSound class provides access to the platform audio facilities.More...

Header:#include <QSound>
Inherits:QObject

Public Functions

QSound(const QString & filename, QObject * parent = 0)
~QSound()
QStringfileName() const
boolisFinished() const
intloops() const
intloopsRemaining() const
voidsetLoops(int number)
  • 29 public functions inherited fromQObject

Public Slots

voidplay()
voidstop()
  • 1 public slot inherited fromQObject

Static Public Members

boolisAvailable()
voidplay(const QString & filename)
  • 7 static public members inherited fromQObject

Additional Inherited Members

  • 1 property inherited fromQObject
  • 1 signal inherited fromQObject
  • 8 protected functions inherited fromQObject

Detailed Description

TheQSound class provides access to the platform audio facilities.

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

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

Alternatively, create aQSound object from the sound file first and then call theplay() slot:

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

Once created aQSound object can be queried for itsfileName() and total number ofloops() (i.e. the number of times the sound will play). The number of repetitions can be altered using thesetLoops() function. While playing the sound, theloopsRemaining() function returns the remaining number of repetitions. Use theisFinished() function to determine whether the sound has finished playing.

Sounds played using aQSound object may use more memory than the staticplay() function, but it may also play more immediately (depending on the underlying platform audio facilities). Use the staticisAvailable() function to determine whether sound facilities exist on the platform. Which facilities that are actually used varies:

PlatformAudio Facility
Microsoft WindowsThe underlying multimedia system is used; only WAVE format sound files are supported.
X11TheNetwork Audio System is used if available, otherwise all operations work silently. NAS supports WAVE and AU files.
Mac OS XNSSound is used. All formats that NSSound supports, including QuickTime formats, are supported by Qt for Mac OS X.
Qt for Embedded LinuxA built-in mixing sound server is used, accessing/dev/dsp directly. Only the WAVE format is supported.
SymbianCMdaAudioPlayerUtility is used. All formats that Symbian OS or devices support are supported also by Qt.

Note thatQSound does not supportresources. This might be fixed in a future Qt version.

Member Function Documentation

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

Constructs aQSound object from the file specified by the givenfilename and with the givenparent.

This may use more memory than the staticplay() function, but it may also play more immediately (depending on the underlying platform audio facilities).

See alsoplay().

QSound::~QSound()

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

See alsostop() andisFinished().

QString QSound::fileName() const

Returns the filename associated with thisQSound object.

See alsoQSound().

[static]bool QSound::isAvailable()

Returns true if sound facilities exist on the platform; otherwise returns false.

If no sound is available, allQSound operations work silently and quickly. An application may choose either to notify the user if sound is crucial to the application or to operate silently without bothering the user.

Note: On Windows this always returns true because some sound card drivers do not implement a way to find out whether it is available or not.

bool QSound::isFinished() const

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

Warning: On Windows this function always returns true for unlooped sounds.

int QSound::loops() const

Returns the number of times the sound will play.

See alsoloopsRemaining() andsetLoops().

int QSound::loopsRemaining() const

Returns the remaining number of times the sound will loop (this value decreases each time the sound is played).

See alsoloops() andisFinished().

[static]void QSound::play(constQString & filename)

Plays the sound stored in the file specified by the givenfilename.

See alsostop(),loopsRemaining(), andisFinished().

[slot]void QSound::play()

This is an overloaded function.

Starts playing the sound specified by thisQSound 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 alsofileName().

void QSound::setLoops(int number)

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

Note that passing the value -1 will cause the sound to loop indefinitely.

See alsoloops().

[slot]void QSound::stop()

Stops the sound playing.

Note that on Windows the current loop will finish if a sound is played in a loop.

See alsoplay().

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp