blob: 644dcb2289ec18db192dfcaf04a845b6823ace0f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "qpushbutton.h"
#include "qsoundeffect.h"
void qsoundeffectsnippet() {
//! [2]
QSoundEffect effect;
effect.setSource(QUrl::fromLocalFile("engine.wav"));
effect.setLoopCount(QSoundEffect::Infinite);
effect.setVolume(0.25f);
effect.play();
//! [2]
}
QPushButton *clickSource;
class MyGame : public QObject {
Q_OBJECT
public:
//! [3]
MyGame()
: m_explosion(this)
{
m_explosion.setSource(QUrl::fromLocalFile("explosion.wav"));
m_explosion.setVolume(0.25f);
// Set up click handling etc.
connect(clickSource, &QPushButton::clicked, &m_explosion, &QSoundEffect::play);
}
private:
QSoundEffect m_explosion;
//! [3]
};
|