diff options
author | Andreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com> | 2009-09-15 13:29:48 (GMT) |
---|---|---|
committer | Andreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com> | 2009-09-15 13:29:48 (GMT) |
commit | 9d96ff055390cea8996b68dc4aef39512fbd9c96 (patch) | |
tree | 525c1afc933bba0f3f00bbcbfc560d10db439179 /doc/src/snippets | |
parent | b13365187b58ecc2d259589ab523a7d0da84dc83 (diff) | |
parent | f42f5c457b3368adb4c92e521dc56969f138bdd3 (diff) | |
download | Qt-9d96ff055390cea8996b68dc4aef39512fbd9c96.zip Qt-9d96ff055390cea8996b68dc4aef39512fbd9c96.tar.gz Qt-9d96ff055390cea8996b68dc4aef39512fbd9c96.tar.bz2 |
Merge commit 'qt-mainline/4.6' into kinetic-declarativeui
Diffstat (limited to 'doc/src/snippets')
-rw-r--r-- | doc/src/snippets/audio/main.cpp | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/doc/src/snippets/audio/main.cpp b/doc/src/snippets/audio/main.cpp new file mode 100644 index 0000000..a215d43 --- /dev/null +++ b/doc/src/snippets/audio/main.cpp @@ -0,0 +1,109 @@ + +#include <QtGui> + +#include <QAudioOutput> +#include <QAudioDeviceInfo> +#include <QAudioInput> + +class Window2 : public QWidget +{ + Q_OBJECT + +public slots: +//![0] + void stateChanged(QAudio::State newState) + { + switch(newState) { + case QAudio::StopState: + if (input->error() != QAudio::NoError) { + // Error handling + } else { + + } + break; +//![0] + default: + ; + } + } + +private: + QAudioInput *input; + +}; + +class Window : public QWidget +{ + Q_OBJECT + +public: + Window() + { + output = new QAudioOutput; + connect(output, SIGNAL(stateChanged(QAudio::State)), + this, SLOT(stateChanged(QAudio::State))); + } + +private: + void setupFormat() + { +//![1] + QAudioFormat format; + format.setFrequency(44100); +//![1] + format.setChannels(2); + format.setSampleSize(16); + format.setCodec("audio/pcm"); + format.setByteOrder(QAudioFormat::LittleEndian); +//![2] + format.setSampleType(QAudioFormat::SignedInt); + + QAudioDeviceId id = QAudioDeviceInfo::defaultOutputDevice(); + QAudioDeviceInfo info(id); + + if (!info.isFormatSupported(format)) + format = info.nearestFormat(format); +//![2] + } + +public slots: +//![3] + void stateChanged(QAudio::State newState) + { + switch (newState) { + case QAudio::StopState: + if (output->error() != QAudio::NoError) { + // Do your error handlin + } else { + // Normal stop + } + break; +//![3] + + // Handle + case QAudio::ActiveState: + // Handle active state... + break; + break; + default: + ; + } + } + +private: + QAudioOutput *output; +}; + +int main(int argv, char **args) +{ + QApplication app(argv, args); + + Window window; + window.show(); + + return app.exec(); +} + + +#include "main.moc" + |