diff options
Diffstat (limited to 'doc')
-rw-r--r-- | doc/src/external-resources.qdoc | 5 | ||||
-rw-r--r-- | doc/src/porting/qt4-threads.qdoc | 2 | ||||
-rw-r--r-- | doc/src/snippets/audio/audio.pro | 2 | ||||
-rw-r--r-- | doc/src/snippets/audio/main.cpp | 123 | ||||
-rw-r--r-- | doc/src/snippets/code/doc_src_qt4-arthur.cpp | 9 | ||||
-rw-r--r-- | doc/src/snippets/code/src_corelib_kernel_qmetatype.cpp | 2 | ||||
-rw-r--r-- | doc/src/snippets/sqldatabase/sqldatabase.cpp | 2 |
7 files changed, 120 insertions, 25 deletions
diff --git a/doc/src/external-resources.qdoc b/doc/src/external-resources.qdoc index 5ef48ec..2107669 100644 --- a/doc/src/external-resources.qdoc +++ b/doc/src/external-resources.qdoc @@ -498,3 +498,8 @@ \externalpage http://www.developer.nokia.com/Community/Wiki/Graphics_memory_handling \title Graphics Out Of Memory monitor */ + +/*! + \externalpage ftp://ftp.qt.nokia.com/pub/qt/solutions/lgpl/qtmotifextension-2.7_1-opensource.tar.gz + \title Motif Extension +*/ diff --git a/doc/src/porting/qt4-threads.qdoc b/doc/src/porting/qt4-threads.qdoc index 17c02f8..bd14d4f 100644 --- a/doc/src/porting/qt4-threads.qdoc +++ b/doc/src/porting/qt4-threads.qdoc @@ -58,7 +58,7 @@ immediately; instead, it is invoked when control returns to the event loop of the thread to which the object belongs. The slot is executed in the thread where the receiver object lives. See - QObject::connect() for details. + \l{signals-and-slots-across-threads} and QObject::connect() for details. Qt 4 also introduces a new synchronization class: QReadWriteLock. It is similar to QMutex, except that it distinguishes between diff --git a/doc/src/snippets/audio/audio.pro b/doc/src/snippets/audio/audio.pro new file mode 100644 index 0000000..cc02dc8 --- /dev/null +++ b/doc/src/snippets/audio/audio.pro @@ -0,0 +1,2 @@ +QT += multimedia +SOURCES += main.cpp diff --git a/doc/src/snippets/audio/main.cpp b/doc/src/snippets/audio/main.cpp index 2afd1a4..f8e7991 100644 --- a/doc/src/snippets/audio/main.cpp +++ b/doc/src/snippets/audio/main.cpp @@ -48,29 +48,71 @@ class Window2 : public QWidget { Q_OBJECT -public slots: +public: + +//![0] + void startRecording() + { + outputFile.setFileName("/tmp/test.raw"); + outputFile.open( QIODevice::WriteOnly | QIODevice::Truncate ); + + QAudioFormat format; + // set up the format you want, eg. + format.setFrequency(8000); + format.setChannels(1); + format.setSampleSize(8); + format.setCodec("audio/pcm"); + format.setByteOrder(QAudioFormat::LittleEndian); + format.setSampleType(QAudioFormat::UnSignedInt); + + QAudioDeviceInfo info = QAudioDeviceInfo::defaultInputDevice(); + if (!info.isFormatSupported(format)) { + qWarning()<<"default format not supported try to use nearest"; + format = info.nearestFormat(format); + } + + audioInput = new QAudioInput(format, this); + QTimer::singleShot(3000, this, SLOT(stopRecording())); + audioInput->start(&outputFile); + // Records audio for 3000ms + } //![0] + +//![1] + void stopRecording() + { + audioInput->stop(); + outputFile.close(); + delete audioInput; + } +//![1] + +public slots: +//![2] void stateChanged(QAudio::State newState) { switch(newState) { - case QAudio::StopState: - if (input->error() != QAudio::NoError) { - // Error handling + case QAudio::StoppedState: + if (audioInput->error() != QAudio::NoError) { + // Perform error handling } else { } break; -//![0] +//![2] default: ; } } private: - QAudioInput *input; - +//![3] + QFile outputFile; // class member. + QAudioInput *audioInput; // class member. +//![3] }; + class Window : public QWidget { Q_OBJECT @@ -78,45 +120,86 @@ class Window : public QWidget public: Window() { - output = new QAudioOutput; - connect(output, SIGNAL(stateChanged(QAudio::State)), + audioOutput = new QAudioOutput; + connect(audioOutput, SIGNAL(stateChanged(QAudio::State)), this, SLOT(stateChanged(QAudio::State))); } +public: + +//![4] + void startPlaying() + { + inputFile.setFileName("/tmp/test.raw"); + inputFile.open(QIODevice::ReadOnly); + + QAudioFormat format; + // Set up the format, eg. + format.setFrequency(8000); + format.setChannels(1); + format.setSampleSize(8); + format.setCodec("audio/pcm"); + format.setByteOrder(QAudioFormat::LittleEndian); + format.setSampleType(QAudioFormat::UnSignedInt); + + QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice()); + if (!info.isFormatSupported(format)) { + qWarning()<<"raw audio format not supported by backend, cannot play audio."; + return; + } + + audioOutput = new QAudioOutput(format, this); + connect(audioOutput,SIGNAL(stateChanged(QAudio::State)),SLOT(finishedPlaying(QAudio::State))); + audioOutput->start(&inputFile); + } +//![4] + +//![5] + void finishedPlaying(QAudio::State state) + { + if (state == QAudio::IdleState) { + audioOutput->stop(); + inputFile.close(); + delete audioOutput; + } + } +//![5] + private: + void setupFormat() { -//![1] +//![6] QAudioFormat format; format.setFrequency(44100); -//![1] +//![6] format.setChannels(2); format.setSampleSize(16); format.setCodec("audio/pcm"); format.setByteOrder(QAudioFormat::LittleEndian); -//![2] +//![7] format.setSampleType(QAudioFormat::SignedInt); QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice()); if (!info.isFormatSupported(format)) format = info.nearestFormat(format); -//![2] +//![7] } public slots: -//![3] +//![8] void stateChanged(QAudio::State newState) { switch (newState) { - case QAudio::StopState: - if (output->error() != QAudio::NoError) { + case QAudio::StoppedState: + if (audioOutput->error() != QAudio::NoError) { // Perform error handling } else { // Normal stop } break; -//![3] +//![8] // Handle case QAudio::ActiveState: @@ -129,7 +212,11 @@ public slots: } private: - QAudioOutput *output; + +//![9] + QFile inputFile; // class member. + QAudioOutput *audioOutput; // class member. +//![9] }; int main(int argv, char **args) diff --git a/doc/src/snippets/code/doc_src_qt4-arthur.cpp b/doc/src/snippets/code/doc_src_qt4-arthur.cpp index 0de11ce..6a24b0f 100644 --- a/doc/src/snippets/code/doc_src_qt4-arthur.cpp +++ b/doc/src/snippets/code/doc_src_qt4-arthur.cpp @@ -74,7 +74,7 @@ painter.drawEllipse(0, 0, 100, 100); painter.setBrush(QColor(255, 0, 0, 127)); painter.drawRect(0, 0, width()/2, height()); -// Specify semi-transparend blue +// Specify semi-transparent blue painter.setBrush(QColor(0, 0, 255, 127)); painter.drawRect(0, 0, width(), height()/2); //! [3] @@ -86,15 +86,16 @@ painter.drawLine(0, 0, width()/2, height()); // One line with anti-aliasing painter.setRenderHint(QPainter::Antialiasing); -painter.drawLine(width()/2, 0, width()/2, height()); +painter.drawLine(width()/2, 0, width(), height()); //! [4] //! [5] QPainterPath path; path.addRect(20, 20, 60, 60); -path.addBezier(0, 0, 99, 0, 50, 50, 99, 99); -path.addBezier(99, 99, 0, 99, 50, 50, 0, 0); +path.moveTo(0, 0); +path.cubicTo(99, 0, 50, 50, 99, 99); +path.cubicTo(0, 99, 50, 50, 0, 0); painter.drawPath(path); //! [5] diff --git a/doc/src/snippets/code/src_corelib_kernel_qmetatype.cpp b/doc/src/snippets/code/src_corelib_kernel_qmetatype.cpp index 96f0e2e..7454463 100644 --- a/doc/src/snippets/code/src_corelib_kernel_qmetatype.cpp +++ b/doc/src/snippets/code/src_corelib_kernel_qmetatype.cpp @@ -73,7 +73,7 @@ MyStruct s2 = var.value<MyStruct>(); //! [3] int id = QMetaType::type("MyClass"); -if (id == 0) { +if (id != 0) { void *myClassPtr = QMetaType::construct(id); ... QMetaType::destroy(id, myClassPtr); diff --git a/doc/src/snippets/sqldatabase/sqldatabase.cpp b/doc/src/snippets/sqldatabase/sqldatabase.cpp index c40b689..e1acdaf 100644 --- a/doc/src/snippets/sqldatabase/sqldatabase.cpp +++ b/doc/src/snippets/sqldatabase/sqldatabase.cpp @@ -284,12 +284,12 @@ void QSqlTableModel_snippets() model->setTable("employee"); model->setEditStrategy(QSqlTableModel::OnManualSubmit); model->select(); - model->removeColumn(0); // don't show the ID model->setHeaderData(0, Qt::Horizontal, tr("Name")); model->setHeaderData(1, Qt::Horizontal, tr("Salary")); QTableView *view = new QTableView; view->setModel(model); + view->hideColumn(0); // don't show the ID view->show(); //! [24] |