summaryrefslogtreecommitdiffstats
path: root/src/corelib/doc/snippets
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2020-01-29 16:57:12 +0100
committerAlexandru Croitor <alexandru.croitor@qt.io>2020-01-29 16:57:27 +0100
commita1dbdcbd6e818118f5fc28cdd39e47a02380adbd (patch)
tree0d813d9d72baeb1b5f7be048e775896c73f134f5 /src/corelib/doc/snippets
parent67ea445f09db9feea4e863faa12c45fb007f53a4 (diff)
parent4cbadf699838406d14366ce61deec03cf45113f7 (diff)
Merge remote-tracking branch 'origin/dev' into wip/cmake
Conflicts: src/corelib/Qt5CoreConfigExtras.cmake.in src/corelib/Qt5CoreMacros.cmake src/dbus/Qt5DBusConfigExtras.cmake.in src/widgets/Qt5WidgetsConfigExtras.cmake.in Change-Id: Ib782f3b177c38b2cce83beebe15be9c0baa578f7
Diffstat (limited to 'src/corelib/doc/snippets')
-rw-r--r--src/corelib/doc/snippets/code/doc_src_properties.cpp1
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_kernel_qcoreapplication.cpp10
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_statemachine_qstatemachine.cpp2
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_thread_qfuturewatcher.cpp2
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_tools_qtimeline.cpp4
-rw-r--r--src/corelib/doc/snippets/qsignalmapper/buttonwidget.cpp14
-rw-r--r--src/corelib/doc/snippets/qsignalmapper/buttonwidget.h4
-rw-r--r--src/corelib/doc/snippets/resource-system/mainwindow.cpp36
-rw-r--r--src/corelib/doc/snippets/statemachine/main.cpp13
-rw-r--r--src/corelib/doc/snippets/statemachine/main2.cpp15
-rw-r--r--src/corelib/doc/snippets/statemachine/main3.cpp2
-rw-r--r--src/corelib/doc/snippets/statemachine/main5.cpp14
-rw-r--r--src/corelib/doc/snippets/timers/analogclock.cpp2
-rw-r--r--src/corelib/doc/snippets/timers/timers.cpp6
14 files changed, 64 insertions, 61 deletions
diff --git a/src/corelib/doc/snippets/code/doc_src_properties.cpp b/src/corelib/doc/snippets/code/doc_src_properties.cpp
index b72c9d13e1..a67945bbcf 100644
--- a/src/corelib/doc/snippets/code/doc_src_properties.cpp
+++ b/src/corelib/doc/snippets/code/doc_src_properties.cpp
@@ -61,6 +61,7 @@ Q_PROPERTY(type name
[USER bool]
[CONSTANT]
[FINAL])
+ [REQUIRED]
//! [0]
diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qcoreapplication.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qcoreapplication.cpp
index aae2456bf1..36b47e6f6e 100644
--- a/src/corelib/doc/snippets/code/src_corelib_kernel_qcoreapplication.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qcoreapplication.cpp
@@ -56,7 +56,7 @@ QApplication::sendEvent(mainWindow, &event);
//! [1]
QPushButton *quitButton = new QPushButton("Quit");
-connect(quitButton, SIGNAL(clicked()), &app, SLOT(quit()), Qt::QueuedConnection);
+connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection);
//! [1]
@@ -79,12 +79,12 @@ Q_COREAPP_STARTUP_FUNCTION(preRoutineMyDebugTool)
//! [4]
-static int *global_ptr = 0;
+static int *global_ptr = nullptr;
static void cleanup_ptr()
{
delete [] global_ptr;
- global_ptr = 0;
+ global_ptr = nullptr;
}
void init_ptr()
@@ -125,9 +125,9 @@ private:
//! [6]
static inline QString tr(const char *sourceText,
- const char *comment = 0);
+ const char *comment = nullptr);
static inline QString trUtf8(const char *sourceText,
- const char *comment = 0);
+ const char *comment = nullptr);
//! [6]
diff --git a/src/corelib/doc/snippets/code/src_corelib_statemachine_qstatemachine.cpp b/src/corelib/doc/snippets/code/src_corelib_statemachine_qstatemachine.cpp
index a606da1a0c..c756116de4 100644
--- a/src/corelib/doc/snippets/code/src_corelib_statemachine_qstatemachine.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_statemachine_qstatemachine.cpp
@@ -56,7 +56,7 @@ QState *s1 = new QState();
s1->assignProperty(&button, "text", "Click me");
QFinalState *s2 = new QFinalState();
-s1->addTransition(&button, SIGNAL(clicked()), s2);
+s1->addTransition(&button, &QPushButton::clicked, s2);
machine.addState(s1);
machine.addState(s2);
diff --git a/src/corelib/doc/snippets/code/src_corelib_thread_qfuturewatcher.cpp b/src/corelib/doc/snippets/code/src_corelib_thread_qfuturewatcher.cpp
index 043974b25b..336c1e9c79 100644
--- a/src/corelib/doc/snippets/code/src_corelib_thread_qfuturewatcher.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_thread_qfuturewatcher.cpp
@@ -52,7 +52,7 @@
// Instantiate the objects and connect to the finished signal.
MyClass myObject;
QFutureWatcher<int> watcher;
-connect(&watcher, SIGNAL(finished()), &myObject, SLOT(handleFinished()));
+connect(&watcher, QFutureWatcher<int>::finished, &myObject, &MyClass::handleFinished);
// Start the computation.
QFuture<int> future = QtConcurrent::run(...);
diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qtimeline.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qtimeline.cpp
index 004a810fce..80859d5ba5 100644
--- a/src/corelib/doc/snippets/code/src_corelib_tools_qtimeline.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_tools_qtimeline.cpp
@@ -56,10 +56,10 @@ progressBar->setRange(0, 100);
// Construct a 1-second timeline with a frame range of 0 - 100
QTimeLine *timeLine = new QTimeLine(1000, this);
timeLine->setFrameRange(0, 100);
-connect(timeLine, SIGNAL(frameChanged(int)), progressBar, SLOT(setValue(int)));
+connect(timeLine, &QTimeLine::frameChanged, progressBar, &QProgressBar::setValue);
// Clicking the push button will start the progress bar animation
pushButton = new QPushButton(tr("Start animation"), this);
-connect(pushButton, SIGNAL(clicked()), timeLine, SLOT(start()));
+connect(pushButton, &QPushButton::clicked, timeLine, &QTimeLine::start);
...
//! [0]
diff --git a/src/corelib/doc/snippets/qsignalmapper/buttonwidget.cpp b/src/corelib/doc/snippets/qsignalmapper/buttonwidget.cpp
index e91c41b305..84a156bb6d 100644
--- a/src/corelib/doc/snippets/qsignalmapper/buttonwidget.cpp
+++ b/src/corelib/doc/snippets/qsignalmapper/buttonwidget.cpp
@@ -48,11 +48,10 @@
**
****************************************************************************/
-#include <QtGui>
-#include <QtWidgets>
-
#include "buttonwidget.h"
+#include <QtWidgets>
+
//! [0]
ButtonWidget::ButtonWidget(const QStringList &texts, QWidget *parent)
: QWidget(parent)
@@ -62,15 +61,16 @@ ButtonWidget::ButtonWidget(const QStringList &texts, QWidget *parent)
QGridLayout *gridLayout = new QGridLayout;
for (int i = 0; i < texts.size(); ++i) {
QPushButton *button = new QPushButton(texts[i]);
- connect(button, SIGNAL(clicked()), signalMapper, SLOT(map()));
+ connect(button, &QPushButton::clicked,
+ signalMapper, &QSignalMapper::map);
//! [0] //! [1]
signalMapper->setMapping(button, texts[i]);
gridLayout->addWidget(button, i / 3, i % 3);
}
- connect(signalMapper, SIGNAL(mapped(QString)),
+ connect(signalMapper, QOverload<const QString &>::of(&QSignalMapper::mapped),
//! [1] //! [2]
- this, SIGNAL(clicked(QString)));
+ this, &ButtonWidget::clicked);
setLayout(gridLayout);
}
@@ -84,7 +84,7 @@ ButtonWidget::ButtonWidget(const QStringList &texts, QWidget *parent)
for (int i = 0; i < texts.size(); ++i) {
QString text = texts[i];
QPushButton *button = new QPushButton(text);
- connect(button, &QPushButton::clicked, [=] { clicked(text); });
+ connect(button, &QPushButton::clicked, [this, text] { clicked(text); });
gridLayout->addWidget(button, i / 3, i % 3);
}
setLayout(gridLayout);
diff --git a/src/corelib/doc/snippets/qsignalmapper/buttonwidget.h b/src/corelib/doc/snippets/qsignalmapper/buttonwidget.h
index f55683c2d5..b9d59f8dd8 100644
--- a/src/corelib/doc/snippets/qsignalmapper/buttonwidget.h
+++ b/src/corelib/doc/snippets/qsignalmapper/buttonwidget.h
@@ -51,7 +51,7 @@
#ifndef BUTTONWIDGET_H
#define BUTTONWIDGET_H
-#include <qwidget.h>
+#include <QWidget>
class QSignalMapper;
class QString;
@@ -63,7 +63,7 @@ class ButtonWidget : public QWidget
Q_OBJECT
public:
- ButtonWidget(const QStringList &texts, QWidget *parent = 0);
+ ButtonWidget(const QStringList &texts, QWidget *parent = nullptr);
signals:
void clicked(const QString &text);
diff --git a/src/corelib/doc/snippets/resource-system/mainwindow.cpp b/src/corelib/doc/snippets/resource-system/mainwindow.cpp
index 86e93aaa62..6dc525304c 100644
--- a/src/corelib/doc/snippets/resource-system/mainwindow.cpp
+++ b/src/corelib/doc/snippets/resource-system/mainwindow.cpp
@@ -68,10 +68,10 @@ MainWindow::MainWindow()
readSettings();
- connect(textEdit->document(), SIGNAL(contentsChanged()),
- this, SLOT(documentWasModified()));
+ connect(textEdit->document(), &QTextEdit::contentsChanged,
+ this, &QAction::documentWasModified);
- setCurrentFile("");
+ setCurrentFile(QString());
setUnifiedTitleAndToolBarOnMac(true);
}
//! [2]
@@ -95,7 +95,7 @@ void MainWindow::newFile()
{
if (maybeSave()) {
textEdit->clear();
- setCurrentFile("");
+ setCurrentFile(QString());
}
}
//! [6]
@@ -162,31 +162,31 @@ void MainWindow::createActions()
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()));
+ connect(newAct, &QAction::triggered, this, &MainWindow::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()));
+ connect(openAct, &QAction::triggered, this, &MainWindow::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()));
+ connect(saveAct, &QAction::triggered, this, &MainWindow::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()));
+ connect(saveAsAct, &QAction::triggered, this, &MainWindow::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()));
+ connect(exitAct, &QAction::triggered, this, &MainWindow::close);
//! [21]
cutAct = new QAction(QIcon(":/images/cut.png"), tr("Cu&t"), this);
@@ -194,38 +194,38 @@ void MainWindow::createActions()
cutAct->setShortcuts(QKeySequence::Cut);
cutAct->setStatusTip(tr("Cut the current selection's contents to the "
"clipboard"));
- connect(cutAct, SIGNAL(triggered()), textEdit, SLOT(cut()));
+ connect(cutAct, &QAction::triggered, textEdit, &QTextEdit::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()));
+ connect(copyAct, &QAction::triggered, textEdit, &QTextEdit::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()));
+ connect(pasteAct, &QAction::triggered, textEdit, &QTextEdit::paste);
aboutAct = new QAction(tr("&About"), this);
aboutAct->setStatusTip(tr("Show the application's About box"));
- connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
+ connect(aboutAct, &QAction::triggered, this, &MainWindow::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()));
+ connect(aboutQtAct, &QAction::triggered, qApp, &QApplication::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)));
+ connect(textEdit, &QTextEdit::copyAvailable,
+ cutAct, &QAction::setEnabled);
+ connect(textEdit, &QTextEdit::copyAvailable,
+ copyAct, &QAction::setEnabled);
}
//! [24]
diff --git a/src/corelib/doc/snippets/statemachine/main.cpp b/src/corelib/doc/snippets/statemachine/main.cpp
index 8cd8b69e12..c399f4f199 100644
--- a/src/corelib/doc/snippets/statemachine/main.cpp
+++ b/src/corelib/doc/snippets/statemachine/main.cpp
@@ -48,13 +48,14 @@
**
****************************************************************************/
-#include <QtGui>
+#include <QtWidgets>
int main(int argv, char **args)
{
QApplication app(argv, args);
QLabel *label = new QLabel;
+ QPushButton *button = new QPushButton;
//![0]
QStateMachine machine;
@@ -70,14 +71,14 @@ int main(int argv, char **args)
//![4]
//![5]
- QObject::connect(s3, SIGNAL(entered()), button, SLOT(showMaximized()));
- QObject::connect(s3, SIGNAL(exited()), button, SLOT(showMinimized()));
+ QObject::connect(s3, &QState::entered, button, &QPushButton:showMaximized);
+ QObject::connect(s3, &QState::exited, button, &QPushButton::showMinimized);
//![5]
//![1]
- s1->addTransition(button, SIGNAL(clicked()), s2);
- s2->addTransition(button, SIGNAL(clicked()), s3);
- s3->addTransition(button, SIGNAL(clicked()), s1);
+ s1->addTransition(button, &QPushButton::clicked, s2);
+ s2->addTransition(button, &QPushButton::clicked, s3);
+ s3->addTransition(button, &QPushButton::clicked, s1);
//![1]
//![2]
diff --git a/src/corelib/doc/snippets/statemachine/main2.cpp b/src/corelib/doc/snippets/statemachine/main2.cpp
index 96eb912b14..dedd2d29bf 100644
--- a/src/corelib/doc/snippets/statemachine/main2.cpp
+++ b/src/corelib/doc/snippets/statemachine/main2.cpp
@@ -48,11 +48,11 @@
**
****************************************************************************/
-#include <QtGui>
+#include <QtWidgets>
int main(int argv, char **args)
{
- QApplication app(argv, args);
+ QApplication app(argv, args);
QStateMachine machine;
@@ -66,16 +66,17 @@ int main(int argv, char **args)
//![0]
//![2]
- s12->addTransition(quitButton, SIGNAL(clicked()), s12);
+ s12->addTransition(quitButton, &QPushButton::clicked, s12);
//![2]
//![1]
QFinalState *s2 = new QFinalState();
- s1->addTransition(quitButton, SIGNAL(clicked()), s2);
+ s1->addTransition(quitButton, &QPushButton::clicked, s2);
machine.addState(s2);
machine.setInitialState(s1);
- QObject::connect(&machine, SIGNAL(finished()), QApplication::instance(), SLOT(quit()));
+ QObject::connect(&machine, &QStateMachine::finished,
+ QCoreApplication::instance(), &QCoreApplication::quit);
//![1]
QButton *interruptButton = new QPushButton("Interrupt Button");
@@ -90,11 +91,11 @@ int main(int argv, char **args)
mbox->addButton(QMessageBox::Ok);
mbox->setText("Interrupted!");
mbox->setIcon(QMessageBox::Information);
- QObject::connect(s3, SIGNAL(entered()), mbox, SLOT(exec()));
+ QObject::connect(s3, &QState::entered, mbox, &QMessageBox::exec);
s3->addTransition(s1h);
machine.addState(s3);
- s1->addTransition(interruptButton, SIGNAL(clicked()), s3);
+ s1->addTransition(interruptButton, &QPushButton::clicked, s3);
//![3]
return app.exec();
diff --git a/src/corelib/doc/snippets/statemachine/main3.cpp b/src/corelib/doc/snippets/statemachine/main3.cpp
index bc9a0e29c4..b665565aef 100644
--- a/src/corelib/doc/snippets/statemachine/main3.cpp
+++ b/src/corelib/doc/snippets/statemachine/main3.cpp
@@ -62,7 +62,7 @@ int main(int argv, char **args)
//![0]
//![1]
- s1->addTransition(s1, SIGNAL(finished()), s2);
+ s1->addTransition(s1, &QState::finished, s2);
//![1]
return app.exec();
diff --git a/src/corelib/doc/snippets/statemachine/main5.cpp b/src/corelib/doc/snippets/statemachine/main5.cpp
index 38bb2cb475..d701f51e2b 100644
--- a/src/corelib/doc/snippets/statemachine/main5.cpp
+++ b/src/corelib/doc/snippets/statemachine/main5.cpp
@@ -98,7 +98,7 @@ int main(int argv, char **args)
s1->assignProperty(button, "geometry", QRectF(0, 0, 50, 50));
s2->assignProperty(button, "geometry", QRectF(0, 0, 100, 100));
- s1->addTransition(button, SIGNAL(clicked()), s2);
+ s1->addTransition(button, &QPushButton::clicked, s2);
//![3]
}
@@ -111,7 +111,7 @@ int main(int argv, char **args)
s1->assignProperty(button, "geometry", QRectF(0, 0, 50, 50));
s2->assignProperty(button, "geometry", QRectF(0, 0, 100, 100));
- QSignalTransition *transition = s1->addTransition(button, SIGNAL(clicked()), s2);
+ QSignalTransition *transition = s1->addTransition(button, &QPushButton::clicked, s2);
transition->addAnimation(new QPropertyAnimation(button, "geometry"));
//![4]
@@ -130,9 +130,9 @@ int main(int argv, char **args)
QState *s2 = new QState();
s2->assignProperty(button, "geometry", QRectF(0, 0, 50, 50));
- connect(s2, SIGNAL(entered()), messageBox, SLOT(exec()));
+ connect(s2, &QState::entered, messageBox, SLOT(exec()));
- s1->addTransition(button, SIGNAL(clicked()), s2);
+ s1->addTransition(button, &QPushButton::clicked, s2);
//![5]
}
@@ -151,10 +151,10 @@ int main(int argv, char **args)
s2->assignProperty(button, "geometry", QRectF(0, 0, 50, 50));
QState *s3 = new QState();
- connect(s3, SIGNAL(entered()), messageBox, SLOT(exec()));
+ connect(s3, &QState::entered, messageBox, SLOT(exec()));
- s1->addTransition(button, SIGNAL(clicked()), s2);
- s2->addTransition(s2, SIGNAL(propertiesAssigned()), s3);
+ s1->addTransition(button, &QPushButton::clicked, s2);
+ s2->addTransition(s2, &QState::propertiesAssigned, s3);
//![6]
}
diff --git a/src/corelib/doc/snippets/timers/analogclock.cpp b/src/corelib/doc/snippets/timers/analogclock.cpp
index 4e1957a450..3edfce3235 100644
--- a/src/corelib/doc/snippets/timers/analogclock.cpp
+++ b/src/corelib/doc/snippets/timers/analogclock.cpp
@@ -61,7 +61,7 @@ AnalogClock::AnalogClock(QWidget *parent)
//! [3] //! [4]
QTimer *timer = new QTimer(this);
//! [4] //! [5]
- connect(timer, SIGNAL(timeout()), this, SLOT(update()));
+ connect(timer, &QTimer::timeout, this, QOverload<>::of(&AnalogClock::update));
//! [5] //! [6]
timer->start(1000);
//! [6]
diff --git a/src/corelib/doc/snippets/timers/timers.cpp b/src/corelib/doc/snippets/timers/timers.cpp
index 5f95899af2..eb0c82c625 100644
--- a/src/corelib/doc/snippets/timers/timers.cpp
+++ b/src/corelib/doc/snippets/timers/timers.cpp
@@ -61,13 +61,13 @@ Foo::Foo()
//! [0]
QTimer *timer = new QTimer(this);
//! [0] //! [1]
- connect(timer, SIGNAL(timeout()), this, SLOT(updateCaption()));
+ connect(timer, &QTimer::timeout, this, &Foo::updateCaption);
//! [1] //! [2]
timer->start(1000);
//! [2]
//! [3]
- QTimer::singleShot(200, this, SLOT(updateCaption()));
+ QTimer::singleShot(200, this, &Foo::updateCaption);
//! [3]
{
@@ -75,7 +75,7 @@ Foo::Foo()
//! [4]
QTimer *timer = new QTimer(this);
//! [4] //! [5]
- connect(timer, SIGNAL(timeout()), this, SLOT(processOneThing()));
+ connect(timer, &QTimer::timeout, this, &Foo::processOneThing);
//! [5] //! [6]
timer->start();
//! [6]