CopperSpice API  1.9.1
QSound Class Reference

Provides access to the platform audio facilities. More...

Inheritance diagram for QSound:
QObject

Public Types

enum  Loop
 

Public Slots

void play ()
 
void stop ()
 
- Public Slots inherited from QObject
void deleteLater ()
 

Public Methods

 QSound (const QString &filename, QObject *parent=nullptr)
 
 ~QSound ()
 
QString fileName () const
 
bool isFinished () const
 
int loops () const
 
int loopsRemaining () const
 
void setLoops (int count)
 
- Public Methods inherited from QObject
 QObject (QObject *parent=nullptr)
 
 ~QObject ()
 
bool blockSignals (bool block)
 
const QList< QObject * > & children () const
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QStringdynamicPropertyNames () const
 
virtual bool event (QEvent *event)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
template<typename T >
findChild (const QString &childName=QString ()) const
 
template<class T >
QList< T > findChildren (const QRegularExpression &regExp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<class T >
QList< T > findChildren (const QString &childName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
bool inherits (const QString &className) const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const
 
bool isWindowType () const
 
void killTimer (int id)
 
const QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const
 
QObject * parent () const
 
template<class T = QVariant>
property (const QString &name) const
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const QString &name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
QThreadthread () const
 

Static Public Methods

static void play (const QString &filename)
 
- Static Public Methods inherited from QObject
static bool connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ())
 
static bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, std::nullptr_t, const QObject *receiver, std::nullptr_t)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...))
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod)
 
static QMetaObjectstaticMetaObject ()
 
static QString tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >())
 

Additional Inherited Members

- Public Signals inherited from QObject
void destroyed (QObject *obj=nullptr)
 
void objectNameChanged (const QString &objectName)
 
- Protected Methods inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signalMethod) const
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signalMethod) const
 
bool isSignalConnected (const QMetaMethod &signalMethod) const
 
int receivers (const QString &signal) const
 
QObject * sender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 
- Properties inherited from QObject
 objectName
 

Detailed Description

The QSound class provides functionality to play .wav format sound files.

CopperSpice 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(). The number of repetitions can be altered using the setLoops() method. While playing the sound loopsRemaining() returns the remaining number of repetitions. Use isFinished() to determine whether the sound has finished playing.

Sounds played using a QSound object may use more memory than the static play() method, however it may start sooner. If finer control over playing sounds is required, consider QSoundEffect or QAudioOutput classes.

Member Enumeration Documentation

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

Constructor & Destructor Documentation

QSound::QSound ( const QString filename,
QObject parent = nullptr 
)
explicit

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(), isFinished()

Method Documentation

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.

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(), 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(), isFinished()
void QSound::play ( )
slot

Starts playing the sound specified by this QSound object.

The method 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::play ( const QString filename)
static

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

See also
stop(), loopsRemaining(), isFinished()
void QSound::setLoops ( int  count)

Sets the sound to repeat the given count of times. Passing -1 will cause the sound to loop indefinitely.

See also
loops()
void QSound::stop ( )
slot

Stops the sound playing. On Windows the current loop will finish if a sound is played in a loop.

See also
play()