QSound Class Reference

The QSound class provides access to the platform audio facilities.

  1. #include <QSound>

Inherits: QObject.

Detailed Description

The QSound 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 static play() function:

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

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

  1. QSound bells("mysounds/bells.wav");
  2. 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). Use the static isAvailable() 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.
X11The Network 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 that QSound does not support resources. This might be fixed in a future Qt version.

Public Functions

Toggle details QSound

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

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

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

See also play().

Look up this member in the source code.

Toggle details QSound

~QSound~QSound () ()

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

See also stop() and isFinished().

Look up this member in the source code.

Toggle details QString QSound

fileNamefileName () ()const

Returns the filename associated with this QSound object.

See also QSound().

Look up this member in the source code.

Toggle details bool QSound

isAvailableisAvailable () () [static]

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

If no sound is available, all QSound 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.

Look up this member in the source code.

Toggle details bool QSound

isFinishedisFinished () ()const

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

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

Look up this member in the source code.

Toggle details int QSound

loopsloops () ()const

Returns the number of times the sound will play.

See also loopsRemaining() and setLoops().

Look up this member in the source code.

Toggle details int QSound

loopsRemainingloopsRemaining () ()const

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

See also loops() and isFinished().

Look up this member in the source code.

Toggle details void QSound

playplay ( const QString &filename ) ( const QString &filename ) [static]

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

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

Look up this member in the source code.

Toggle details void QSound

setLoopssetLoops ( int number ) ( int number )

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

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

See also loops().

Look up this member in the source code.

Toggle details QSound

QSoundQSound ( const QString &filename , QObject *parent , const char *name ...) ( const QString &filename , QObject *parent , const char *name ) Qt3-support

Constructs a QSound object from the file specified by the given filename and with the given parent and name. Use the QSound() construcor and QObject::setObjectName() instead.

For example, if you have code like

  1. QSound *mySound = new QSound(filename, parent, name);

you can rewrite it as

  1. QSounc *mySound = new QSound(filename, parent);
  2. mySound->setObjectName(name);

Look up this member in the source code.

Toggle details bool QSound

availableavailable () () [static] Qt3-support

Use the isAvailable() function instead.

Look up this member in the source code.

Public Slots

Toggle details void QSound

playplay () () [slot]

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().

Look up this member in the source code.

Toggle details void QSound

stopstop () () [slot]

Stops the sound playing.

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

See also play().

Look up this member in the source code.

Notes provided by the Qt Community

No notes