summaryrefslogtreecommitdiffstats
path: root/src/corelib/doc
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/doc')
-rw-r--r--src/corelib/doc/qtcore.qdocconf1
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp8
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_io_qstorageinfo.cpp62
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_tools_qcommandlineoption.cpp11
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_tools_qcommandlineparser_main.cpp17
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp10
-rw-r--r--src/corelib/doc/snippets/qbytearraylist/main.cpp51
-rw-r--r--src/corelib/doc/snippets/qbytearraylist/qbytearraylist.pro2
-rw-r--r--src/corelib/doc/snippets/qloggingcategory/main.cpp31
-rw-r--r--src/corelib/doc/snippets/qprocess-environment/main.cpp2
-rw-r--r--src/corelib/doc/snippets/qversionnumber/main.cpp109
-rw-r--r--src/corelib/doc/snippets/signalsandslots/signalsandslots.cpp17
-rw-r--r--src/corelib/doc/src/custom-types.qdoc2
-rw-r--r--src/corelib/doc/src/eventsandfilters.qdoc2
-rw-r--r--src/corelib/doc/src/filestorage.qdoc22
-rw-r--r--src/corelib/doc/src/objectmodel/properties.qdoc4
-rw-r--r--src/corelib/doc/src/objectmodel/signalsandslots.qdoc177
17 files changed, 371 insertions, 157 deletions
diff --git a/src/corelib/doc/qtcore.qdocconf b/src/corelib/doc/qtcore.qdocconf
index c9c8f1da54..7c879cbbfd 100644
--- a/src/corelib/doc/qtcore.qdocconf
+++ b/src/corelib/doc/qtcore.qdocconf
@@ -2,7 +2,6 @@ include($QT_INSTALL_DOCS/global/qt-module-defaults.qdocconf)
project = QtCore
description = Qt Core Reference Documentation
-url = http://qt-project.org/doc/qt-$QT_VER
version = $QT_VERSION
examplesinstallpath = core
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 b907c9acb1..d804514584 100644
--- a/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp
@@ -136,9 +136,9 @@ int roundedValueB = qRound(valueB);
qreal valueA = 42949672960.3;
qreal valueB = 42949672960.7;
-int roundedValueA = qRound(valueA);
+qint64 roundedValueA = qRound64(valueA);
// roundedValueA = 42949672960
-int roundedValueB = qRound(valueB);
+qint64 roundedValueB = qRound64(valueB);
// roundedValueB = 42949672961
//! [12]
@@ -305,7 +305,7 @@ void load(const QString &fileName)
{
QFile file(fileName);
if (!file.exists())
- qCritical("File '%s' does not exist!", qPrintable(fileName));
+ qCritical("File '%s' does not exist!", qUtf8Printable(fileName));
}
//! [28]
@@ -424,7 +424,7 @@ void TheClass::addLabels()
//! [37]
-qWarning("%s: %s", qPrintable(key), qPrintable(value));
+qWarning("%s: %s", qUtf8Printable(key), qUtf8Printable(value));
//! [37]
diff --git a/src/corelib/doc/snippets/code/src_corelib_io_qstorageinfo.cpp b/src/corelib/doc/snippets/code/src_corelib_io_qstorageinfo.cpp
new file mode 100644
index 0000000000..bba3703325
--- /dev/null
+++ b/src/corelib/doc/snippets/code/src_corelib_io_qstorageinfo.cpp
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Ivan Komissarov
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [0]
+ QStorageInfo storage(qApp->applicationDirPath());
+ if (storage.isValid() && storage.isReady()) {
+ // ...
+ }
+//! [0]
+
+//! [1]
+ foreach (const QStorageInfo &storage, QStorageInfo::mountedVolumes()) {
+ if (storage.isValid() && storage.isReady()) {
+ if (!storage.isReadOnly()) {
+ // ...
+ }
+ }
+ }
+//! [1]
+
+//! [2]
+ QStorageInfo storage = QStorageInfo::root();
+
+ qDebug() << storage.rootPath();
+ if (storage.isReadOnly())
+ qDebug() << "isReadOnly:" << storage.isReadOnly();
+
+ qDebug() << "name:" << storage.name();
+ qDebug() << "fileSystemType:" << storage.fileSystemType();
+ qDebug() << "size:" << storage.bytesTotal()/1000/1000 << "MB";
+ qDebug() << "availableSize:" << storage.bytesAvailable()/1000/1000 << "MB";
+//! [2]
diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qcommandlineoption.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qcommandlineoption.cpp
index 67d5f41b38..6d6d7fe2ed 100644
--- a/src/corelib/doc/snippets/code/src_corelib_tools_qcommandlineoption.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_tools_qcommandlineoption.cpp
@@ -39,6 +39,7 @@
****************************************************************************/
#include <QCommandLineOption>
+#include <QCommandLineParser>
int main()
{
@@ -48,4 +49,14 @@ QCommandLineOption verboseOption("verbose", "Verbose mode. Prints out more infor
QCommandLineOption outputOption(QStringList() << "o" << "output", "Write generated data into <file>.", "file");
//! [0]
+//! [cxx11-init]
+QCommandLineParser parser;
+parser.addOption({"verbose", "Verbose mode. Prints out more information."});
+//! [cxx11-init]
+
+//! [cxx11-init-list]
+QCommandLineParser parser;
+parser.addOption({{"o", "output"}, "Write generated data into <file>.", "file"});
+//! [cxx11-init-list]
+
}
diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qcommandlineparser_main.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qcommandlineparser_main.cpp
index 257a138d0d..26bc43f194 100644
--- a/src/corelib/doc/snippets/code/src_corelib_tools_qcommandlineparser_main.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_tools_qcommandlineparser_main.cpp
@@ -82,3 +82,20 @@ int main(int argc, char *argv[])
}
//! [0]
+
+void f() {
+//! [cxx11]
+ parser.addOptions({
+ // A boolean option with a single name (-p)
+ {"p",
+ QCoreApplication::translate("main", "Show progress during copy")},
+ // A boolean option with multiple names (-f, --force)
+ {{"f", "force"},
+ QCoreApplication::translate("main", "Overwrite existing files.")},
+ // An option with a value
+ {{"t", "target-directory"},
+ QCoreApplication::translate("main", "Copy all source files into <directory>."),
+ QCoreApplication::translate("main", "directory")},
+ });
+//! [cxx11]
+}
diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp
index 8c21083976..aa0473964c 100644
--- a/src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp
@@ -297,3 +297,13 @@ while (i != hash.end() && i.key() == "plenty") {
++i;
}
//! [26]
+
+//! [qhashbits]
+inline uint qHash(const std::vector<int> &key, uint seed = 0)
+{
+ if (key.empty())
+ return seed;
+ else
+ return qHashBits(&key.front(), key.size() * sizeof(int), seed);
+}
+//! [qhashbits]
diff --git a/src/corelib/doc/snippets/qbytearraylist/main.cpp b/src/corelib/doc/snippets/qbytearraylist/main.cpp
new file mode 100644
index 0000000000..be462dea60
--- /dev/null
+++ b/src/corelib/doc/snippets/qbytearraylist/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 by Southwest Research Institute (R)
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <QByteArrayList>
+
+int main(int, char **)
+{
+ QByteArray ba1, ba2, ba3;
+//! [0]
+ QByteArrayList longerList = (QByteArrayList() << ba1 << ba2 << ba3);
+//! [0]
+}
diff --git a/src/corelib/doc/snippets/qbytearraylist/qbytearraylist.pro b/src/corelib/doc/snippets/qbytearraylist/qbytearraylist.pro
new file mode 100644
index 0000000000..87397b491d
--- /dev/null
+++ b/src/corelib/doc/snippets/qbytearraylist/qbytearraylist.pro
@@ -0,0 +1,2 @@
+QT = core
+SOURCES = main.cpp
diff --git a/src/corelib/doc/snippets/qloggingcategory/main.cpp b/src/corelib/doc/snippets/qloggingcategory/main.cpp
index 628243dbdd..3c6424921e 100644
--- a/src/corelib/doc/snippets/qloggingcategory/main.cpp
+++ b/src/corelib/doc/snippets/qloggingcategory/main.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 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.
@@ -43,12 +43,15 @@
//![1]
// in a header
-Q_DECLARE_LOGGING_CATEGORY(QT_DRIVER_USB)
+Q_DECLARE_LOGGING_CATEGORY(driverUsb)
// in one source file
-Q_LOGGING_CATEGORY(QT_DRIVER_USB, "qt.driver.usb")
+Q_LOGGING_CATEGORY(driverUsb, "driver.usb")
//![1]
+//![5]
+Q_LOGGING_CATEGORY(driverUsbEvents, "driver.usb.events", QtWarningMsg)
+//![5]
// Completely made up example, inspired by en.wikipedia.org/wiki/USB :)
struct UsbEntry {
@@ -76,8 +79,8 @@ QLoggingCategory::CategoryFilter oldCategoryFilter;
void myCategoryFilter(QLoggingCategory *category)
{
- // configure qt.driver.usb category here, otherwise forward to to default filter.
- if (qstrcmp(category->categoryName(), "qt.driver.usb") == 0)
+ // configure driver.usb category here, otherwise forward to to default filter.
+ if (qstrcmp(category->categoryName(), "driver.usb") == 0)
category->setEnabled(QtDebugMsg, true);
else
oldCategoryFilter(category);
@@ -89,7 +92,7 @@ int main(int argc, char *argv[])
QCoreApplication a(argc, argv);
//![2]
- QLoggingCategory::setFilterRules(QStringLiteral("qt.driver.usb.debug=true"));
+ QLoggingCategory::setFilterRules(QStringLiteral("driver.usb.debug=true"));
//![2]
//![22]
@@ -103,48 +106,48 @@ oldCategoryFilter = QLoggingCategory::installFilter(myCategoryFilter);
//![3]
//![4]
- // usbEntries() will only be called if QT_DRIVER_USB category is enabled
- qCDebug(QT_DRIVER_USB) << "devices: " << usbEntries();
+ // usbEntries() will only be called if driverUsb category is enabled
+ qCDebug(driverUsb) << "devices: " << usbEntries();
//![4]
{
//![10]
- QLoggingCategory category("qt.driver.usb");
+ QLoggingCategory category("driver.usb");
qCDebug(category) << "a debug message";
//![10]
}
{
//![11]
- QLoggingCategory category("qt.driver.usb");
+ QLoggingCategory category("driver.usb");
qCWarning(category) << "a warning message";
//![11]
}
{
//![12]
- QLoggingCategory category("qt.driver.usb");
+ QLoggingCategory category("driver.usb");
qCCritical(category) << "a critical message";
//![12]
}
{
//![13]
- QLoggingCategory category("qt.driver.usb");
+ QLoggingCategory category("driver.usb");
qCDebug(category, "a debug message logged into category %s", category.categoryName());
//![13]
}
{
//![14]
- QLoggingCategory category("qt.driver.usb");
+ QLoggingCategory category("driver.usb");
qCWarning(category, "a warning message logged into category %s", category.categoryName());
//![14]
}
{
//![15]
- QLoggingCategory category("qt.driver.usb");
+ QLoggingCategory category("driver.usb");
qCCritical(category, "a critical message logged into category %s", category.categoryName());
//![15]
}
diff --git a/src/corelib/doc/snippets/qprocess-environment/main.cpp b/src/corelib/doc/snippets/qprocess-environment/main.cpp
index d858746889..2e078eea6d 100644
--- a/src/corelib/doc/snippets/qprocess-environment/main.cpp
+++ b/src/corelib/doc/snippets/qprocess-environment/main.cpp
@@ -47,7 +47,6 @@ void startProcess()
QProcess process;
QStringList env = QProcess::systemEnvironment();
env << "TMPDIR=C:\\MyApp\\temp"; // Add an environment variable
-env.replaceInStrings(QRegExp("^PATH=(.*)", Qt::CaseInsensitive), "PATH=\\1;C:\\Bin");
process.setEnvironment(env);
process.start("myapp");
//! [0]
@@ -58,7 +57,6 @@ process.start("myapp");
QProcess process;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert("TMPDIR", "C:\\MyApp\\temp"); // Add an environment variable
-env.insert("PATH", env.value("Path") + ";C:\\Bin");
process.setProcessEnvironment(env);
process.start("myapp");
//! [1]
diff --git a/src/corelib/doc/snippets/qversionnumber/main.cpp b/src/corelib/doc/snippets/qversionnumber/main.cpp
new file mode 100644
index 0000000000..ba72a52816
--- /dev/null
+++ b/src/corelib/doc/snippets/qversionnumber/main.cpp
@@ -0,0 +1,109 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Keith Gardner <kreios4004@gmail.com>
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the documentation 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$
+**
+****************************************************************************/
+
+#include <QVersionNumber>
+
+class Object
+{
+public:
+ static void genericExample();
+ static void equalityExample();
+ static void isPrefixOf();
+ static void parse();
+ static void equivalent();
+};
+
+void Object::genericExample()
+{
+ //! [0]
+ QVersionNumber version(1, 2, 3); // 1.2.3
+ //! [0]
+}
+
+void Object::equalityExample()
+{
+ //! [1]
+ QVersionNumber v1(1, 2);
+ QVersionNumber v2(1, 2, 0);
+ int compare = QVersionNumber::compare(v1, v2); // compare == -1
+ //! [1]
+}
+
+void Object::isPrefixOf()
+{
+ //! [2]
+ QVersionNumber v1(5, 3);
+ QVersionNumber v2(5, 3, 1);
+ bool value = v1.isPrefixOf(v2); // true
+ //! [2]
+}
+
+void QObject::parse()
+{
+ //! [3]
+ QString string("5.4.0-alpha");
+ int suffixIndex;
+ QVersionNumber version = QVersionNumber::fromString(string, &suffixIndex);
+ // version is 5.4.0
+ // suffixIndex is 5
+ //! [3]
+}
+
+void Object::equivalent()
+{
+ //! [4]
+ QVersionNumber v1(5, 4);
+ QVersionNumber v2(5, 4, 0);
+ bool equivalent = v1.normalized() == v2.normalized();
+ bool equal = v1 == v2;
+ // equivalent is true
+ // equal is false
+ //! [4]
+}
+
+int main()
+{
+ Object::genericExample();
+ Object::equalityExample();
+ Object::isPrefixOf();
+ Object::parse();
+ Object::equivalent();
+}
diff --git a/src/corelib/doc/snippets/signalsandslots/signalsandslots.cpp b/src/corelib/doc/snippets/signalsandslots/signalsandslots.cpp
index 91cd3de9d2..357269bac0 100644
--- a/src/corelib/doc/snippets/signalsandslots/signalsandslots.cpp
+++ b/src/corelib/doc/snippets/signalsandslots/signalsandslots.cpp
@@ -38,8 +38,6 @@
**
****************************************************************************/
-#include <QAbstractButton>
-
#include "signalsandslots.h"
//! [0]
@@ -66,19 +64,4 @@ int main()
//! [3] //! [4]
b.setValue(48); // a.value() == 12, b.value() == 48
//! [4]
-
-
- QWidget *widget = reinterpret_cast<QWidget *>(new QObject(0));
-//! [5]
- if (widget->inherits("QAbstractButton")) {
- QAbstractButton *button = static_cast<QAbstractButton *>(widget);
- button->toggle();
-//! [5] //! [6]
- }
-//! [6]
-
-//! [7]
- if (QAbstractButton *button = qobject_cast<QAbstractButton *>(widget))
- button->toggle();
-//! [7]
}
diff --git a/src/corelib/doc/src/custom-types.qdoc b/src/corelib/doc/src/custom-types.qdoc
index ed846aee83..bac4a90829 100644
--- a/src/corelib/doc/src/custom-types.qdoc
+++ b/src/corelib/doc/src/custom-types.qdoc
@@ -147,7 +147,7 @@
The output sent to the debug stream can, of course, be made as simple or as
complicated as you like. Note that the value returned by this function is
the QDebug object itself, though this is often obtained by calling the
- maybeSpace() member function of QDebug that pads out the stream with space
+ \l{QDebug::}{maybeSpace()} member function of QDebug that pads out the stream with space
characters to make it more readable.
\section1 Further Reading
diff --git a/src/corelib/doc/src/eventsandfilters.qdoc b/src/corelib/doc/src/eventsandfilters.qdoc
index a880cc8187..d9b2e35e19 100644
--- a/src/corelib/doc/src/eventsandfilters.qdoc
+++ b/src/corelib/doc/src/eventsandfilters.qdoc
@@ -194,7 +194,7 @@
\l{QCoreApplication::}{sendEvent()} processes the event immediately.
When it returns, the event filters and/or the object itself have
already processed the event. For many event classes there is a function
- called isAccepted() that tells you whether the event was accepted
+ called \l{QEvent::}{isAccepted()} that tells you whether the event was accepted
or rejected by the last handler that was called.
\l{QCoreApplication::}{postEvent()} posts the event on a queue for
diff --git a/src/corelib/doc/src/filestorage.qdoc b/src/corelib/doc/src/filestorage.qdoc
index fb1279cea5..394d920923 100644
--- a/src/corelib/doc/src/filestorage.qdoc
+++ b/src/corelib/doc/src/filestorage.qdoc
@@ -30,15 +30,15 @@
\title File and Datastream Functions
The QIODevice class is the base interface class of all I/O devices in
-\l {Qt Core}. QIODevice provides both a common implementation and an
+\l{Qt Core}. QIODevice provides both a common implementation and an
abstract interface for devices that support reading and writing of blocks
of data. The device can be a memory buffer, a file, or a datastream.
Some subclasses like QFile have been implemented using a memory buffer for
intermediate storing of data. This speeds up programs by reducing
-read/write operations. Buffering makes functions like getChar() and putChar()
-fast, as they can operate on the memory buffer instead of directly on the
-device itself.
+read/write operations. Buffering makes functions like \l{QFile::}{getChar()} and
+\l{QFile::}{putChar()} fast, as they can operate on the memory buffer instead of
+directly on the device itself.
The QFile class provides functions for reading from and writing to files.
A QFile may be used by itself or, more conveniently, with a QTextStream or
@@ -48,6 +48,7 @@ QBuffer allows you to access a QByteArray using the QIODevice interface.
The QByteArray is treated just as a standard random-accessed file.
An example:
+\code
QBuffer buffer;
char ch;
@@ -58,12 +59,13 @@ An example:
buffer.getChar(&ch); // ch == 't'
buffer.getChar(&ch); // ch == ' '
buffer.getChar(&ch); // ch == 'r'
+\endcode
-Call open() to open the buffer. Then call write() or putChar() to write to
-the buffer, and read(), readLine(), readAll(), or getChar() to read from it.
-size() returns the current size of the buffer, and you can seek to arbitrary
-positions in the buffer by calling seek(). When you are done with accessing
-the buffer, call close().
+Call \l{QBuffer::}{open()} to open the buffer. Then call \l{QBuffer::}{write()} or \l{QBuffer::}{putChar()} to write to
+the buffer, and \l{QBuffer::}{read()}, \l{QBuffer::}{readLine()}, \l{QBuffer::}{readAll()}, or \l{QBuffer::}{getChar()} to read from it.
+\l{QBuffer::}{size()} returns the current size of the buffer, and you can seek to arbitrary
+positions in the buffer by calling \l{QBuffer::}{seek()}. When you are done with accessing
+the buffer, call \l{QBuffer::}{close()}.
The QDataStream class provides serialization of binary data to a QIODevice.
A data stream is a binary stream of encoded information which is 100% inde-
@@ -91,7 +93,7 @@ There are three general ways to use QTextStream when reading text files:
\li Character by character, by streaming into QChar or char types. This
method is often used for convenient input handling when parsing files,
independent of character encoding and end-of-line semantics. To skip
- white space, call skipWhiteSpace().
+ white space, call \l{QTextStream::}{skipWhiteSpace()}.
\endlist
QByteArray can be used to store both raw bytes (including \c{\0}) and traditional
diff --git a/src/corelib/doc/src/objectmodel/properties.qdoc b/src/corelib/doc/src/objectmodel/properties.qdoc
index 70f0b88e06..8a6c7f53d9 100644
--- a/src/corelib/doc/src/objectmodel/properties.qdoc
+++ b/src/corelib/doc/src/objectmodel/properties.qdoc
@@ -226,7 +226,7 @@
In the example, the enumeration type that is the property type is
declared in MyClass and registered with the \l{Meta-Object System}
using the Q_ENUMS() macro. This makes the enumeration values
- available as strings for use as in the call to setProperty(). Had
+ available as strings for use as in the call to \l{QObject::}{setProperty()}. Had
the enumeration type been declared in another class, its fully
qualified name (i.e., OtherClass::Priority) would be required, and
that other class would also have to inherit QObject and register
@@ -249,7 +249,7 @@
If the value is \e not compatible with the property's type, the
property is \e not changed, and false is returned. But if the
property with the given name doesn't exist in the QObject (i.e.,
- if it wasn't declared with Q_PROPERTY(), a new property with the
+ if it wasn't declared with Q_PROPERTY()), a new property with the
given name and value is automatically added to the QObject, but
false is still returned. This means that a return of false can't
be used to determine whether a particular property was actually
diff --git a/src/corelib/doc/src/objectmodel/signalsandslots.qdoc b/src/corelib/doc/src/objectmodel/signalsandslots.qdoc
index e894d547d0..f79e8a7dca 100644
--- a/src/corelib/doc/src/objectmodel/signalsandslots.qdoc
+++ b/src/corelib/doc/src/objectmodel/signalsandslots.qdoc
@@ -36,7 +36,8 @@
Signals and slots are used for communication between objects. The
signals and slots mechanism is a central feature of Qt and
probably the part that differs most from the features provided by
- other frameworks.
+ other frameworks. Signals and slots are made possible by Qt's
+ \l{The Meta-Object System}{meta-object system}.
\tableofcontents
@@ -48,17 +49,14 @@
if a user clicks a \uicontrol{Close} button, we probably want the
window's \l{QWidget::close()}{close()} function to be called.
- Older toolkits achieve this kind of communication using
+ Other toolkits achieve this kind of communication using
callbacks. A callback is a pointer to a function, so if you want
a processing function to notify you about some event you pass a
pointer to another function (the callback) to the processing
function. The processing function then calls the callback when
- appropriate. Callbacks have two fundamental flaws: Firstly, they
- are not type-safe. We can never be certain that the processing
- function will call the callback with the correct arguments.
- Secondly, the callback is strongly coupled to the processing
- function since the processing function must know which callback
- to call.
+ appropriate. While successful frameworks using this method do exist,
+ callbacks can be unintuitive and may suffer from problems in ensuring
+ the type-correctness of callback arguments.
\section1 Signals and Slots
@@ -112,87 +110,6 @@
Together, signals and slots make up a powerful component programming
mechanism.
- \section1 A Small Example
-
- A minimal C++ class declaration might read:
-
- \snippet signalsandslots/signalsandslots.h 0
-
- A small QObject-based class might read:
-
- \snippet signalsandslots/signalsandslots.h 1
- \codeline
- \snippet signalsandslots/signalsandslots.h 2
- \snippet signalsandslots/signalsandslots.h 3
-
- The QObject-based version has the same internal state, and provides
- public methods to access the state, but in addition it has support
- for component programming using signals and slots. This class can
- tell the outside world that its state has changed by emitting a
- signal, \c{valueChanged()}, and it has a slot which other objects
- can send signals to.
-
- All classes that contain signals or slots must mention
- Q_OBJECT at the top of their declaration. They must also derive
- (directly or indirectly) from QObject.
-
- Slots are implemented by the application programmer.
- Here is a possible implementation of the \c{Counter::setValue()}
- slot:
-
- \snippet signalsandslots/signalsandslots.cpp 0
-
- The \c{emit} line emits the signal \c valueChanged() from the
- object, with the new value as argument.
-
- In the following code snippet, we create two \c Counter objects
- and connect the first object's \c valueChanged() signal to the
- second object's \c setValue() slot using QObject::connect():
-
- \snippet signalsandslots/signalsandslots.cpp 1
- \snippet signalsandslots/signalsandslots.cpp 2
- \codeline
- \snippet signalsandslots/signalsandslots.cpp 3
- \snippet signalsandslots/signalsandslots.cpp 4
-
- Calling \c{a.setValue(12)} makes \c{a} emit a
- \c{valueChanged(12)} signal, which \c{b} will receive in its
- \c{setValue()} slot, i.e. \c{b.setValue(12)} is called. Then
- \c{b} emits the same \c{valueChanged()} signal, but since no slot
- has been connected to \c{b}'s \c{valueChanged()} signal, the
- signal is ignored.
-
- Note that the \c{setValue()} function sets the value and emits
- the signal only if \c{value != m_value}. This prevents infinite
- looping in the case of cyclic connections (e.g., if
- \c{b.valueChanged()} were connected to \c{a.setValue()}).
-
- By default, for every connection you make, a signal is emitted;
- two signals are emitted for duplicate connections. You can break
- all of these connections with a single disconnect() call.
- If you pass the Qt::UniqueConnection \a type, the connection will only
- be made if it is not a duplicate. If there is already a duplicate
- (exact same signal to the exact same slot on the same objects),
- the connection will fail and connect will return false
-
- This example illustrates that objects can work together without needing to
- know any information about each other. To enable this, the objects only
- need to be connected together, and this can be achieved with some simple
- QObject::connect() function calls, or with \c{uic}'s
- \l{Using a Designer UI File in Your Application#Automatic Connections}
- {automatic connections} feature.
-
- \section1 Building the Example
-
- The C++ preprocessor changes or removes the \c{signals},
- \c{slots}, and \c{emit} keywords so that the compiler is
- presented with standard C++.
-
- By running the \l moc on class definitions that contain signals
- or slots, a C++ source file is produced which should be compiled
- and linked with the other object files for the application. If
- you use \l qmake, the makefile rules to automatically invoke \c
- moc will be added to your project's makefile.
\section1 Signals
@@ -267,27 +184,77 @@
alongside a Qt-based application. To solve this problem, \c
#undef the offending preprocessor symbol.
- \section1 Meta-Object Information
- The meta-object compiler (\l moc) parses the class declaration in
- a C++ file and generates C++ code that initializes the
- meta-object. The meta-object contains the names of all the signal
- and slot members, as well as pointers to these functions.
+ \section1 A Small Example
+
+ A minimal C++ class declaration might read:
+
+ \snippet signalsandslots/signalsandslots.h 0
+
+ A small QObject-based class might read:
+
+ \snippet signalsandslots/signalsandslots.h 1
+ \codeline
+ \snippet signalsandslots/signalsandslots.h 2
+ \snippet signalsandslots/signalsandslots.h 3
+
+ The QObject-based version has the same internal state, and provides
+ public methods to access the state, but in addition it has support
+ for component programming using signals and slots. This class can
+ tell the outside world that its state has changed by emitting a
+ signal, \c{valueChanged()}, and it has a slot which other objects
+ can send signals to.
+
+ All classes that contain signals or slots must mention
+ Q_OBJECT at the top of their declaration. They must also derive
+ (directly or indirectly) from QObject.
+
+ Slots are implemented by the application programmer.
+ Here is a possible implementation of the \c{Counter::setValue()}
+ slot:
+
+ \snippet signalsandslots/signalsandslots.cpp 0
+
+ The \c{emit} line emits the signal \c valueChanged() from the
+ object, with the new value as argument.
+
+ In the following code snippet, we create two \c Counter objects
+ and connect the first object's \c valueChanged() signal to the
+ second object's \c setValue() slot using QObject::connect():
- The meta-object contains additional information such as the
- object's \l{QMetaObject::className()}{class name}. You can
- also check if an object \l{QObject::inherits()}{inherits}
- a specific class, for example:
+ \snippet signalsandslots/signalsandslots.cpp 1
+ \snippet signalsandslots/signalsandslots.cpp 2
+ \codeline
+ \snippet signalsandslots/signalsandslots.cpp 3
+ \snippet signalsandslots/signalsandslots.cpp 4
+
+ Calling \c{a.setValue(12)} makes \c{a} emit a
+ \c{valueChanged(12)} signal, which \c{b} will receive in its
+ \c{setValue()} slot, i.e. \c{b.setValue(12)} is called. Then
+ \c{b} emits the same \c{valueChanged()} signal, but since no slot
+ has been connected to \c{b}'s \c{valueChanged()} signal, the
+ signal is ignored.
- \snippet signalsandslots/signalsandslots.cpp 5
- \snippet signalsandslots/signalsandslots.cpp 6
+ Note that the \c{setValue()} function sets the value and emits
+ the signal only if \c{value != m_value}. This prevents infinite
+ looping in the case of cyclic connections (e.g., if
+ \c{b.valueChanged()} were connected to \c{a.setValue()}).
- The meta-object information is also used by qobject_cast<T>(), which
- is similar to QObject::inherits() but is less error-prone:
+ By default, for every connection you make, a signal is emitted;
+ two signals are emitted for duplicate connections. You can break
+ all of these connections with a single disconnect() call.
+ If you pass the Qt::UniqueConnection \a type, the connection will only
+ be made if it is not a duplicate. If there is already a duplicate
+ (exact same signal to the exact same slot on the same objects),
+ the connection will fail and connect will return false
- \snippet signalsandslots/signalsandslots.cpp 7
+ This example illustrates that objects can work together without needing to
+ know any information about each other. To enable this, the objects only
+ need to be connected together, and this can be achieved with some simple
+ QObject::connect() function calls, or with \c{uic}'s
+ \l{Using a Designer UI File in Your Application#Automatic Connections}
+ {automatic connections} feature.
- See \l{Meta-Object System} for more information.
\section1 A Real Example
@@ -392,7 +359,7 @@
compatible with the slot's arguments. Arguments can also be implicitly
converted by the compiler, if needed.
- You can also connect to functors or C++11 lamdas:
+ You can also connect to functors or C++11 lambdas:
\code
connect(sender, &QObject::destroyed, [=](){ this->m_objects.remove(sender); });