Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Tous les espaces de nom  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

QSound Class Reference
[QtGui module]

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

 #include <QSound>

Inherits QObject.

Public Functions

  • 29 public functions inherited from QObject

Public Slots

  • 1 public slot inherited from QObject

Static Public Members

  • 5 static public members inherited from QObject

Additional Inherited Members

  • 1 property inherited from QObject
  • 1 signal inherited from QObject
  • 7 protected functions inherited from 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:

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

Note that QSound does not support resources. This might be fixed in a future Qt version.


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.

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

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

QString QSound::fileName () const

Returns the filename associated with this QSound object.

See also QSound().

bool QSound::isAvailable ()   [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.

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 also loopsRemaining() and setLoops().

int QSound::loopsRemaining () 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().

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

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

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

void QSound::play ()   [slot]

This is an overloaded member function, provided for convenience.

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 -1 will cause the sound to loop indefinitely.

See also loops().

void QSound::stop ()   [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().

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 53
  2. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  3. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  4. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. La rubrique Qt a besoin de vous ! 1
Page suivante

Le Qt Developer Network au hasard

Logo

Livre blanc de l'outillage de Qt Quick

Le Qt Developer Network est un réseau de développeurs Qt anglophone, où ils peuvent partager leur expérience sur le framework. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 4.4
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web