From f262815f2ef147113780312a410eccdf4b318a82 Mon Sep 17 00:00:00 2001 From: Sergio Ahumada Date: Sat, 26 Jan 2013 13:39:56 +0100 Subject: Fix some more old references and links to Nokia Task-number: QTBUG-28156 Change-Id: I9ba0d6f1e92103219bec1e61e716b6b2f269a8ad Reviewed-by: Laszlo Papp Reviewed-by: Jerome Pasion --- src/corelib/doc/snippets/code/src_corelib_io_qurl.cpp | 8 ++++---- src/corelib/doc/snippets/code/src_corelib_tools_qbytearray.cpp | 10 +++++----- src/corelib/doc/snippets/qxmlstreamwriter/main.cpp | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) (limited to 'src/corelib/doc/snippets') diff --git a/src/corelib/doc/snippets/code/src_corelib_io_qurl.cpp b/src/corelib/doc/snippets/code/src_corelib_io_qurl.cpp index 432b0b9167..ca178e03a0 100644 --- a/src/corelib/doc/snippets/code/src_corelib_io_qurl.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_io_qurl.cpp @@ -45,7 +45,7 @@ QUrl url("http://www.example.com/List of holidays.xml"); //! [1] -QUrl url = QUrl::fromEncoded("http://qt.nokia.com/List%20of%20holidays.xml"); +QUrl url = QUrl::fromEncoded("http://qt-project.org/List%20of%20holidays.xml"); //! [1] @@ -73,10 +73,10 @@ http://www.example.com/cgi-bin/drawgraph.cgi?type(pie)color(green) //! [5] -QUrl baseUrl("http://qt.nokia.com/support"); -QUrl relativeUrl("../products/solutions"); +QUrl baseUrl("http://qt.digia.com/Support/"); +QUrl relativeUrl("../Product/Library/"); qDebug(baseUrl.resolved(relativeUrl).toString()); -// prints "http://qt.nokia.com/products/solutions" +// prints "http://qt.digia.com/Product/Library/" //! [5] diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qbytearray.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qbytearray.cpp index eef026af75..759c31c098 100644 --- a/src/corelib/doc/snippets/code/src_corelib_tools_qbytearray.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qbytearray.cpp @@ -258,7 +258,7 @@ if (url.startsWith("ftp:")) //! [26] -QByteArray url("http://qt.nokia.com/index.html"); +QByteArray url("http://qt-project.org/doc/qt-5.0/qtdoc/index.html"); if (url.endsWith(".html")) ... //! [26] @@ -286,16 +286,16 @@ QByteArray z = x.mid(5); // z == "pineapples" //! [30] -QByteArray x("Qt by NOKIA"); +QByteArray x("Qt by DIGIA"); QByteArray y = x.toLower(); -// y == "qt by nokia" +// y == "qt by digia" //! [30] //! [31] -QByteArray x("Qt by NOKIA"); +QByteArray x("Qt by DIGIA"); QByteArray y = x.toUpper(); -// y == "QT BY NOKIA" +// y == "QT BY DIGIA" //! [31] diff --git a/src/corelib/doc/snippets/qxmlstreamwriter/main.cpp b/src/corelib/doc/snippets/qxmlstreamwriter/main.cpp index 2a436f1a4c..5af3596171 100644 --- a/src/corelib/doc/snippets/qxmlstreamwriter/main.cpp +++ b/src/corelib/doc/snippets/qxmlstreamwriter/main.cpp @@ -61,8 +61,8 @@ int main(int argc, char *argv[]) stream.writeAttribute("folded", "no"); //! [write element] stream.writeStartElement("bookmark"); - stream.writeAttribute("href", "http://qt.nokia.com/"); - stream.writeTextElement("title", "Qt Home"); + stream.writeAttribute("href", "http://qt-project.org/"); + stream.writeTextElement("title", "Qt Project"); stream.writeEndElement(); // bookmark //! [write element] stream.writeEndElement(); // folder -- cgit v1.2.3 From 747348f4556440aa21c0c8aeb76cbd71da49d007 Mon Sep 17 00:00:00 2001 From: Jerome Pasion Date: Thu, 24 Jan 2013 14:59:55 +0100 Subject: Doc: Fixing snippets and input file for a Qt Core article. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -copied snippet and input files from Qt Widgets. -adapted new paths in the resource-system.qdoc file. -removed the old path entry in qdocconf. Task-number: QTBUG-29101 Change-Id: Ieeb118106756a1a39890ab219294de18f437c56c Reviewed-by: Topi Reiniƶ Reviewed-by: Nico Vertriest Reviewed-by: Geir Vattekar --- .../doc/snippets/resource-system/application.pro | 14 + .../doc/snippets/resource-system/application.qrc | 10 + .../doc/snippets/resource-system/mainwindow.cpp | 392 +++++++++++++++++++++ 3 files changed, 416 insertions(+) create mode 100644 src/corelib/doc/snippets/resource-system/application.pro create mode 100644 src/corelib/doc/snippets/resource-system/application.qrc create mode 100644 src/corelib/doc/snippets/resource-system/mainwindow.cpp (limited to 'src/corelib/doc/snippets') diff --git a/src/corelib/doc/snippets/resource-system/application.pro b/src/corelib/doc/snippets/resource-system/application.pro new file mode 100644 index 0000000000..652cc73485 --- /dev/null +++ b/src/corelib/doc/snippets/resource-system/application.pro @@ -0,0 +1,14 @@ +QT += widgets + +HEADERS = mainwindow.h +SOURCES = main.cpp \ + mainwindow.cpp +#! [0] +RESOURCES = application.qrc +#! [0] + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/widgets/mainwindows/application +INSTALLS += target + +simulator: warning(This example might not fully work on Simulator platform) diff --git a/src/corelib/doc/snippets/resource-system/application.qrc b/src/corelib/doc/snippets/resource-system/application.qrc new file mode 100644 index 0000000000..0a776fab4d --- /dev/null +++ b/src/corelib/doc/snippets/resource-system/application.qrc @@ -0,0 +1,10 @@ + + + images/copy.png + images/cut.png + images/new.png + images/open.png + images/paste.png + images/save.png + + diff --git a/src/corelib/doc/snippets/resource-system/mainwindow.cpp b/src/corelib/doc/snippets/resource-system/mainwindow.cpp new file mode 100644 index 0000000000..8bdd0303de --- /dev/null +++ b/src/corelib/doc/snippets/resource-system/mainwindow.cpp @@ -0,0 +1,392 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +#include + +#include "mainwindow.h" +//! [0] + +//! [1] +MainWindow::MainWindow() +//! [1] //! [2] +{ + textEdit = new QPlainTextEdit; + setCentralWidget(textEdit); + + createActions(); + createMenus(); + createToolBars(); + createStatusBar(); + + readSettings(); + + connect(textEdit->document(), SIGNAL(contentsChanged()), + this, SLOT(documentWasModified())); + + setCurrentFile(""); + setUnifiedTitleAndToolBarOnMac(true); +} +//! [2] + +//! [3] +void MainWindow::closeEvent(QCloseEvent *event) +//! [3] //! [4] +{ + if (maybeSave()) { + writeSettings(); + event->accept(); + } else { + event->ignore(); + } +} +//! [4] + +//! [5] +void MainWindow::newFile() +//! [5] //! [6] +{ + if (maybeSave()) { + textEdit->clear(); + setCurrentFile(""); + } +} +//! [6] + +//! [7] +void MainWindow::open() +//! [7] //! [8] +{ + if (maybeSave()) { + QString fileName = QFileDialog::getOpenFileName(this); + if (!fileName.isEmpty()) + loadFile(fileName); + } +} +//! [8] + +//! [9] +bool MainWindow::save() +//! [9] //! [10] +{ + if (curFile.isEmpty()) { + return saveAs(); + } else { + return saveFile(curFile); + } +} +//! [10] + +//! [11] +bool MainWindow::saveAs() +//! [11] //! [12] +{ + QString fileName = QFileDialog::getSaveFileName(this); + if (fileName.isEmpty()) + return false; + + return saveFile(fileName); +} +//! [12] + +//! [13] +void MainWindow::about() +//! [13] //! [14] +{ + QMessageBox::about(this, tr("About Application"), + tr("The Application example demonstrates how to " + "write modern GUI applications using Qt, with a menu bar, " + "toolbars, and a status bar.")); +} +//! [14] + +//! [15] +void MainWindow::documentWasModified() +//! [15] //! [16] +{ + setWindowModified(textEdit->document()->isModified()); +} +//! [16] + +//! [17] +void MainWindow::createActions() +//! [17] //! [18] +{ + newAct = new QAction(QIcon(":/images/new.png"), tr("&New"), this); + newAct->setShortcuts(QKeySequence::New); + newAct->setStatusTip(tr("Create a new file")); + connect(newAct, SIGNAL(triggered()), this, SLOT(newFile())); + +//! [19] + openAct = new QAction(QIcon(":/images/open.png"), tr("&Open..."), this); + openAct->setShortcuts(QKeySequence::Open); + openAct->setStatusTip(tr("Open an existing file")); + connect(openAct, SIGNAL(triggered()), this, SLOT(open())); +//! [18] //! [19] + + saveAct = new QAction(QIcon(":/images/save.png"), tr("&Save"), this); + saveAct->setShortcuts(QKeySequence::Save); + saveAct->setStatusTip(tr("Save the document to disk")); + connect(saveAct, SIGNAL(triggered()), this, SLOT(save())); + + saveAsAct = new QAction(tr("Save &As..."), this); + saveAsAct->setShortcuts(QKeySequence::SaveAs); + saveAsAct->setStatusTip(tr("Save the document under a new name")); + connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs())); + +//! [20] + exitAct = new QAction(tr("E&xit"), this); + exitAct->setShortcuts(QKeySequence::Quit); +//! [20] + exitAct->setStatusTip(tr("Exit the application")); + connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); + +//! [21] + cutAct = new QAction(QIcon(":/images/cut.png"), tr("Cu&t"), this); +//! [21] + cutAct->setShortcuts(QKeySequence::Cut); + cutAct->setStatusTip(tr("Cut the current selection's contents to the " + "clipboard")); + connect(cutAct, SIGNAL(triggered()), textEdit, SLOT(cut())); + + copyAct = new QAction(QIcon(":/images/copy.png"), tr("&Copy"), this); + copyAct->setShortcuts(QKeySequence::Copy); + copyAct->setStatusTip(tr("Copy the current selection's contents to the " + "clipboard")); + connect(copyAct, SIGNAL(triggered()), textEdit, SLOT(copy())); + + pasteAct = new QAction(QIcon(":/images/paste.png"), tr("&Paste"), this); + pasteAct->setShortcuts(QKeySequence::Paste); + pasteAct->setStatusTip(tr("Paste the clipboard's contents into the current " + "selection")); + connect(pasteAct, SIGNAL(triggered()), textEdit, SLOT(paste())); + + aboutAct = new QAction(tr("&About"), this); + aboutAct->setStatusTip(tr("Show the application's About box")); + connect(aboutAct, SIGNAL(triggered()), this, SLOT(about())); + +//! [22] + aboutQtAct = new QAction(tr("About &Qt"), this); + aboutQtAct->setStatusTip(tr("Show the Qt library's About box")); + connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt())); +//! [22] + +//! [23] + cutAct->setEnabled(false); +//! [23] //! [24] + copyAct->setEnabled(false); + connect(textEdit, SIGNAL(copyAvailable(bool)), + cutAct, SLOT(setEnabled(bool))); + connect(textEdit, SIGNAL(copyAvailable(bool)), + copyAct, SLOT(setEnabled(bool))); +} +//! [24] + +//! [25] //! [26] +void MainWindow::createMenus() +//! [25] //! [27] +{ + fileMenu = menuBar()->addMenu(tr("&File")); + fileMenu->addAction(newAct); +//! [28] + fileMenu->addAction(openAct); +//! [28] + fileMenu->addAction(saveAct); +//! [26] + fileMenu->addAction(saveAsAct); + fileMenu->addSeparator(); + fileMenu->addAction(exitAct); + + editMenu = menuBar()->addMenu(tr("&Edit")); + editMenu->addAction(cutAct); + editMenu->addAction(copyAct); + editMenu->addAction(pasteAct); + + menuBar()->addSeparator(); + + helpMenu = menuBar()->addMenu(tr("&Help")); + helpMenu->addAction(aboutAct); + helpMenu->addAction(aboutQtAct); +} +//! [27] + +//! [29] //! [30] +void MainWindow::createToolBars() +{ + fileToolBar = addToolBar(tr("File")); + fileToolBar->addAction(newAct); +//! [29] //! [31] + fileToolBar->addAction(openAct); +//! [31] + fileToolBar->addAction(saveAct); + + editToolBar = addToolBar(tr("Edit")); + editToolBar->addAction(cutAct); + editToolBar->addAction(copyAct); + editToolBar->addAction(pasteAct); +} +//! [30] + +//! [32] +void MainWindow::createStatusBar() +//! [32] //! [33] +{ + statusBar()->showMessage(tr("Ready")); +} +//! [33] + +//! [34] //! [35] +void MainWindow::readSettings() +//! [34] //! [36] +{ + QSettings settings("QtProject", "Application Example"); + QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint(); + QSize size = settings.value("size", QSize(400, 400)).toSize(); + resize(size); + move(pos); +} +//! [35] //! [36] + +//! [37] //! [38] +void MainWindow::writeSettings() +//! [37] //! [39] +{ + QSettings settings("QtProject", "Application Example"); + settings.setValue("pos", pos()); + settings.setValue("size", size()); +} +//! [38] //! [39] + +//! [40] +bool MainWindow::maybeSave() +//! [40] //! [41] +{ + if (textEdit->document()->isModified()) { + QMessageBox::StandardButton ret; + ret = QMessageBox::warning(this, tr("Application"), + tr("The document has been modified.\n" + "Do you want to save your changes?"), + QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); + if (ret == QMessageBox::Save) + return save(); + else if (ret == QMessageBox::Cancel) + return false; + } + return true; +} +//! [41] + +//! [42] +void MainWindow::loadFile(const QString &fileName) +//! [42] //! [43] +{ + QFile file(fileName); + if (!file.open(QFile::ReadOnly | QFile::Text)) { + QMessageBox::warning(this, tr("Application"), + tr("Cannot read file %1:\n%2.") + .arg(fileName) + .arg(file.errorString())); + return; + } + + QTextStream in(&file); +#ifndef QT_NO_CURSOR + QApplication::setOverrideCursor(Qt::WaitCursor); +#endif + textEdit->setPlainText(in.readAll()); +#ifndef QT_NO_CURSOR + QApplication::restoreOverrideCursor(); +#endif + + setCurrentFile(fileName); + statusBar()->showMessage(tr("File loaded"), 2000); +} +//! [43] + +//! [44] +bool MainWindow::saveFile(const QString &fileName) +//! [44] //! [45] +{ + QFile file(fileName); + if (!file.open(QFile::WriteOnly | QFile::Text)) { + QMessageBox::warning(this, tr("Application"), + tr("Cannot write file %1:\n%2.") + .arg(fileName) + .arg(file.errorString())); + return false; + } + + QTextStream out(&file); +#ifndef QT_NO_CURSOR + QApplication::setOverrideCursor(Qt::WaitCursor); +#endif + out << textEdit->toPlainText(); +#ifndef QT_NO_CURSOR + QApplication::restoreOverrideCursor(); +#endif + + setCurrentFile(fileName); + statusBar()->showMessage(tr("File saved"), 2000); + return true; +} +//! [45] + +//! [46] +void MainWindow::setCurrentFile(const QString &fileName) +//! [46] //! [47] +{ + curFile = fileName; + textEdit->document()->setModified(false); + setWindowModified(false); + + QString shownName = curFile; + if (curFile.isEmpty()) + shownName = "untitled.txt"; + setWindowFilePath(shownName); +} +//! [47] + +//! [48] +QString MainWindow::strippedName(const QString &fullFileName) +//! [48] //! [49] +{ + return QFileInfo(fullFileName).fileName(); +} +//! [49] -- cgit v1.2.3 From f0c8e63e5bbd5d5265478a8740cc7f0d587bfdb9 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Mon, 28 Jan 2013 16:50:59 +0100 Subject: Fix documented signature for QtMessageHandler Task-number: QTBUG-29352 Change-Id: I46190a59cd73e53e778551a2d33c6b2801e9587e Reviewed-by: Thiago Macieira --- src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib/doc/snippets') diff --git a/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp b/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp index a3a458fbc7..62ce04a6f8 100644 --- a/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp @@ -535,7 +535,7 @@ CApaApplication *myApplicationFactory(); //! [49] -void myMessageHandler(QtMsgType, const QMessageLogContext &, const char *); +void myMessageHandler(QtMsgType, const QMessageLogContext &, const QString &); //! [49] //! [50] -- cgit v1.2.3 From c5c584c116798c495d78a4d89c568a77bc065010 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Fri, 1 Feb 2013 14:39:23 +0100 Subject: Optimize code sample of QObject::isSignalConnected Since isSignalConnected is meant to be used in performance critical code, and that QMetaMethod::fromSignal is relatively slow, it is better to have it a a static variable in the code sample, as a good recommendation on how to use it. Since QMetaMethod::fromSignal should not change during the life of the program, it should be safe. Also, if different threads run at the same time, both should lead to the same result. Change-Id: Ib6113d11ca93f216bc3a92aea4eaa4da6a4151ca Reviewed-by: Thiago Macieira --- src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/corelib/doc/snippets') diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp index 932a006436..bafd3f8eb8 100644 --- a/src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp @@ -480,7 +480,8 @@ QObject::disconnect(lineEdit, &QLineEdit::textChanged, //! [48] //! [49] -if (isSignalConnected(QMetaMethod::fromSignal(&MyObject::valueChanged))) { +static const QMetaMethod valueChangedSignal = QMetaMethod::fromSignal(&MyObject::valueChanged); +if (isSignalConnected(valueChangedSignal)) { QByteArray data; data = get_the_value(); // expensive operation emit valueChanged(data); -- cgit v1.2.3 From 91e12dca757a8ef5c4691b70eb80db61a9d47e83 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Sat, 19 Jan 2013 16:17:51 +0100 Subject: QThread documentation: do not discourage the reimplementation of QThread The new QThread documentation now really discourage to reimplement QThread. But in fact, there are many cases where it is perfectly fine. And the example given is even a case where using worker object is wrong. The examle even contains a leak since the thread will never stop and will even leak. This changes put back some sentences from before commit d4ad9dbbf96884c0899e8f8116a8a056facd52d5. The sample code has been re-writen. Notice how reimpementing run takes less lines of code, less runtime overhead, no leaks, and also is more complete than the previous example. Change-Id: I6cb80826e917dd5ce442ccad2572ec692ccb25ab Reviewed-by: Andre Somers Reviewed-by: Geir Vattekar Reviewed-by: Debao Zhang Reviewed-by: Thiago Macieira --- .../snippets/code/src_corelib_thread_qthread.cpp | 79 +++++++++++++++------- 1 file changed, 53 insertions(+), 26 deletions(-) (limited to 'src/corelib/doc/snippets') diff --git a/src/corelib/doc/snippets/code/src_corelib_thread_qthread.cpp b/src/corelib/doc/snippets/code/src_corelib_thread_qthread.cpp index f0bc759320..c33c8bb48a 100644 --- a/src/corelib/doc/snippets/code/src_corelib_thread_qthread.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_thread_qthread.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2013 Olivier Goffart ** Contact: http://www.qt-project.org/legal ** ** This file is part of the documentation of the Qt Toolkit. @@ -38,41 +38,68 @@ ** ****************************************************************************/ -//! [0] -class Worker : public QObject +#include +class MyObject; + +//! [reimpl-run] +class WorkerThread : public QThread { Q_OBJECT - -public slots: - void doWork() { - ... + void run() Q_DECL_OVERRIDE { + QString result; + /* expensive or blocking operation */ + emit resultReady(result); } +signals: + void resultReady(const QString &s); }; -void MyObject::putWorkerInAThread() +void MyObject::startWorkInAThread() { - Worker *worker = new Worker; - QThread *workerThread = new QThread(this); - - connect(workerThread, &QThread::started, worker, &Worker::doWork); - connect(workerThread, &QThread::finished, worker, &Worker::deleteLater); - worker->moveToThread(workerThread); - - // Starts an event loop, and emits workerThread->started() + WorkerThread *workerThread = new WorkerThread(this); + connect(workerThread, &WorkerThread::resultReady, this, &MyObject::handleResults); + connect(workerThread, &WorkerThread::finished, workerThread, &QObject::deleteLater); workerThread->start(); } -//! [0] +//! [reimpl-run] + -//! [1] -class AdvancedThreadManager : public QThread +//! [worker] +class Worker : public QObject { -protected: - void run() - { - /* ... other code to initialize thread... */ + Q_OBJECT + QThread workerThread; - // Begin event handling - exec(); +public slots: + void doWork(const QString ¶meter) { + // ... + emit resultReady(result); } + +signals: + void resultReady(const QString &result); +}; + +class Controller : public QObject +{ + Q_OBJECT + QThread workerThread; +public: + Controller() { + Worker *worker = new Worker; + worker->moveToThread(&workerThread); + connect(workerThread, &QThread::finished, worker, &QObject::deleteLater); + connect(this, &Controller::operate, worker, &Worker::doWork); + connect(worker, &Worker::resultReady, this, &Controller::handleResults); + workerThread.start(); + } + ~Controller() { + workerThread.quit(); + workerThread.wait(); + } +public slots: + void handleResults(const QString &); +signals: + void operate(const QString &); }; -//! [1] +//! [worker] -- cgit v1.2.3 From d7cad756efc89281f0294fec4ce84df1188c8aad Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Tue, 5 Feb 2013 19:03:25 +0100 Subject: Replace nokia in example by Qt Project Change-Id: I23adfd6a1cf02c8c99996b698fb780988434b9a7 Reviewed-by: Gabriel de Dietrich --- src/corelib/doc/snippets/qstring/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/corelib/doc/snippets') diff --git a/src/corelib/doc/snippets/qstring/main.cpp b/src/corelib/doc/snippets/qstring/main.cpp index 0fdb88cd8b..6149e9d051 100644 --- a/src/corelib/doc/snippets/qstring/main.cpp +++ b/src/corelib/doc/snippets/qstring/main.cpp @@ -856,8 +856,8 @@ void Widget::toLongLongFunction() void Widget::toLowerFunction() { //! [75] - QString str = "Qt by NOKIA"; - str = str.toLower(); // str == "qt by nokia" + QString str = "The QT PROJECT"; + str = str.toLower(); // str == "the qt project" //! [75] } -- cgit v1.2.3 From 05ce12849b2e266210b71a432ce65883a1fdbe60 Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Wed, 6 Feb 2013 09:48:46 +0100 Subject: Spell "Qt" correctly Change-Id: Idf2b5c888f159ee8ffdb81ed74e685c40951c6b4 Reviewed-by: Frederik Gladhorn --- src/corelib/doc/snippets/qstring/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib/doc/snippets') diff --git a/src/corelib/doc/snippets/qstring/main.cpp b/src/corelib/doc/snippets/qstring/main.cpp index 6149e9d051..6ee3088138 100644 --- a/src/corelib/doc/snippets/qstring/main.cpp +++ b/src/corelib/doc/snippets/qstring/main.cpp @@ -856,7 +856,7 @@ void Widget::toLongLongFunction() void Widget::toLowerFunction() { //! [75] - QString str = "The QT PROJECT"; + QString str = "The Qt PROJECT"; str = str.toLower(); // str == "the qt project" //! [75] } -- cgit v1.2.3