Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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
7
void
qsoundeffectsnippet
() {
8
//! [2]
9
QSoundEffect
effect;
10
effect.setSource(QUrl::fromLocalFile(
"engine.wav"
));
11
effect.setLoopCount(QSoundEffect::Infinite);
12
effect.setVolume(0.25f);
13
effect.play();
14
//! [2]
15
}
16
17
QPushButton
*
clickSource
;
18
19
class
MyGame
:
public
QObject
{
20
Q_OBJECT
21
public
:
22
//! [3]
23
MyGame
()
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.
30
connect
(
clickSource
, &
QPushButton
::
clicked
, &
m_explosion
, &
QSoundEffect
::
play
);
31
}
32
private
:
33
QSoundEffect
m_explosion
;
34
//! [3]
35
};
MyGame
Definition
qsound.cpp:19
QSoundEffect
The QSoundEffect class provides a way to play low latency sound effects.
Definition
qsoundeffect.h:21
clickSource
QPushButton * clickSource
Definition
qsound.cpp:17
qsoundeffectsnippet
void qsoundeffectsnippet()
Definition
qsound.cpp:7
qtmultimedia
src
multimedia
doc
snippets
multimedia-snippets
qsound.cpp
Generated on
for Qt by
1.14.0