Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qsound.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4#include "qpushbutton.h"
5#include "qsoundeffect.h"
6
10 effect.setSource(QUrl::fromLocalFile("engine.wav"));
11 effect.setLoopCount(QSoundEffect::Infinite);
12 effect.setVolume(0.25f);
13 effect.play();
15}
16
18
19class MyGame : public QObject {
21public:
24 : m_explosion(this)
25 {
26 m_explosion.setSource(QUrl::fromLocalFile("explosion.wav"));
27 m_explosion.setVolume(0.25f);
28
29 // Set up click handling etc.
31 }
32private:
33 QSoundEffect m_explosion;
35};
MyGame()
[3]
Definition qsound.cpp:23
void clicked(bool checked=false)
This signal is emitted when the button is activated (i.e., pressed down then released while the mouse...
\inmodule QtCore
Definition qobject.h:103
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
The QPushButton widget provides a command button.
Definition qpushbutton.h:20
The QSoundEffect class provides a way to play low latency sound effects.
void setVolume(float volume)
Sets the sound effect volume to volume.
void play()
\qmlmethod QtMultimedia::SoundEffect::play()
void setSource(const QUrl &url)
Set the current URL to play to url.
static QUrl fromLocalFile(const QString &localfile)
Returns a QUrl representation of localFile, interpreted as a local file.
Definition qurl.cpp:3368
#define this
Definition dialogs.cpp:9
QPushButton * clickSource
Definition qsound.cpp:17
void qsoundeffectsnippet()
Definition qsound.cpp:7
#define Q_OBJECT
QGraphicsOpacityEffect * effect
the effect attached to this item