Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# QSound Class Reference

The QSound class provides access to the platform audio facilities. More...

`#include <qsound.h>`

Inherits QObject.

List of all member functions.

## Public Members

- QSound ( const QString & filename, QObject * parent = 0, const char * name = 0 )
- ~QSound ()
- int loops () const
- int loopsRemaining () const
- void setLoops ( int l )
- QString fileName () const
- bool isFinished () const

## Public Slots

- void play ()
- void stop ()

## Static Public Members

- bool isAvailable ()
- void play ( const QString & filename )
- bool available ()

## Detailed Description

The QSound class provides access to the platform audio facilities.

Qt provides the most commonly required audio operation in GUI applications: playing a sound file asynchronously to the user. This is most simply accomplished with a single call:

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

A second API is provided in which a QSound object is created from a sound file and is later played:

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

        bells.play();

Sounds played by the second model may use more memory but play more immediately than sounds played using the first model, depending on the underlying platform audio facilities.

On Microsoft Windows the underlying multimedia system is used; only WAVE format sound files are supported.

On X11 the Network Audio System is used if available, otherwise all operations work silently. NAS supports WAVE and AU files.

On Macintosh, in an ironic turn of events we use QT (QuickTime) for sound, this means all QuickTime formats are supported by Qt/Mac.

On Qt/Embedded, a built-in mixing sound server is used, which accesses `/dev/dsp` directly. Only the WAVE format is supported.

The availability of sound can be tested with QSound::isAvailable().

See also Multimedia Classes.

## Member Function Documentation

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

Constructs a QSound that can quickly play the sound in a file named filename.

This can use more memory than the static `play` function.

The parent and name arguments (default 0) are passed on to the QObject constructor.

### QSound::~QSound ()

Destroys the sound object.

### bool QSound::available ()`[static]`

Returns TRUE if sound support is available; otherwise returns FALSE.

### QString QSound::fileName () const

Returns the filename associated with the sound.

### bool QSound::isAvailable ()`[static]`

Returns TRUE if sound facilities exist on the platform; otherwise returns FALSE. An application may choose either to notify the user if sound is crucial to the application or to operate silently without bothering the user.

If no sound is available, all QSound operations work silently and quickly.

### 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.

### int QSound::loopsRemaining () const

Returns the number of times the sound will loop. This value decreases each time the sound loops.

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

Plays the sound in a file called filename.

### void QSound::play ()`[slot]`

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Starts the sound playing. The function returns immediately. Depending on the platform audio facilities, other sounds may stop or may be mixed with the new sound.

The sound can be played again at any time, possibly mixing or replacing previous plays of the sound.

### void QSound::setLoops ( int l )

Sets the sound to repeat l times when it is played. Passing the value -1 will cause the sound to loop indefinitely.

See also loops().

### void QSound::stop ()`[slot]`

Stops the sound playing.

See also play().

This file is part of the Qt toolkit, copyright © 1995-2001 Trolltech, all rights reserved.