This change fixes most qdoc errors in QtCore. There are about 900 left.
The main thing this change does is moving documentation from qtcore from
/doc/src to /src/corelib/doc.
Other issues resolved are mis-use of qdoc commands.
Change-Id: I002d01edfb13575e8bf27ce91596a577a92562d1
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Reviewed-by: Jason McDonald <jason.mcdonald@nokia.com>
Reviewed-by: Jerome Pasion <jerome.pasion@nokia.com>
--- /dev/null
+Cpp.ignoretokens = QT_ASCII_CAST_WARN \
+ QT_ASCII_CAST_WARN_CONSTRUCTOR \
+ QT_BEGIN_HEADER \
+ QT_BOOTSTRAPPED \
+ QT_DESIGNER_STATIC \
+ QT_END_HEADER \
+ QT_FASTCALL \
+ Q_COMPAT_EXPORT \
+ Q_CORE_EXPORT \
+ Q_CORE_EXPORT_INLINE \
+ Q_EXPORT \
+ Q_EXPORT_PLUGIN \
+ Q_EXPORT_PLUGIN2 \
+ Q_AUTOTEST_EXPORT \
+ Q_GUI_EXPORT \
+ Q_GUI_EXPORT_INLINE \
+ Q_INLINE_TEMPLATE \
+ Q_NETWORK_EXPORT \
+ Q_OPENGL_EXPORT \
+ Q_OPENVG_EXPORT \
+ Q_OUTOFLINE_TEMPLATE \
+ Q_SQL_EXPORT \
+ Q_SVG_EXPORT \
+ Q_SCRIPT_EXPORT \
+ Q_SCRIPTTOOLS_EXPORT \
+ Q_XML_EXPORT \
+ Q_XMLPATTERNS_EXPORT \
+ QDBUS_EXPORT \
+ Q_DBUS_EXPORT \
+ QT_BEGIN_NAMESPACE \
+ QT_BEGIN_INCLUDE_NAMESPACE \
+ QT_END_NAMESPACE \
+ QT_END_INCLUDE_NAMESPACE \
+ Q_GADGET \
+ Q_INVOKABLE \
+ Q_DECL_CONSTEXPR
+Cpp.ignoredirectives = Q_DECLARE_INTERFACE \
+ Q_DECLARE_METATYPE \
+ Q_DECLARE_OPERATORS_FOR_FLAGS \
+ Q_DECLARE_PRIVATE \
+ Q_DECLARE_PUBLIC \
+ Q_DECLARE_SHARED \
+ Q_DECLARE_TR_FUNCTIONS \
+ Q_DECLARE_TYPEINFO \
+ Q_DISABLE_COPY \
+ QT_FORWARD_DECLARE_CLASS \
+ Q_DUMMY_COMPARISON_OPERATOR \
+ Q_ENUMS \
+ Q_FLAGS \
+ Q_INTERFACES \
+ __attribute__ \
+ Q_PRIVATE_PROPERTY \
+ Q_DECLARE_PRIVATE_D \
+ Q_CLASSINFO
--- /dev/null
+body{
+font: normal 400 14px/1.2 Arial;
+margin-top:85px;
+font-family: Arial, Helvetica;
+color:#313131;
+text-align:justify;
+margin-left:5px;
+margin-right:5px;
+}
+
+img{
+-moz-box-shadow: 3px 3px 3px #ccc;
+-webkit-box-shadow: 3px 3px 3px #ccc;
+box-shadow: 3px 3px 3px #ccc;
+border:#8E8D8D 2px solid;
+margin-left:0px;
+max-width: 800px;
+height: auto
+}
+
+b{
+font-weight:600;
+}
+
+.content{}
+
+.descr{
+margin-top:35px;
+/*max-width: 75%;*/
+margin-left:5px;
+text-align:justify;
+min-height:700px;
+vertical-align:top;
+}
+
+.name{
+max-width: 75%;
+font-weight:100;
+}
+
+tt{
+text-align:left;}
+
+/*
+-----------
+links
+-----------
+*/
+
+a:link{
+color: #2C418D;
+text-decoration: none;
+text-align:left;
+}
+
+a:hover{
+color: #869CD1;
+text-decoration:underline;
+text-align:left;
+}
+
+a:visited{
+color: #869CD1;
+text-decoration: none;
+text-align:left;
+}
+
+a:visited:hover{
+text-decoration:underline;
+text-align:left;
+}
+
+a[href*="http://"], a[href*="ftp://"],a[href*="https://"]
+{
+text-decoration: none;
+background-image:url(../images/ico_out.png);
+background-repeat:no-repeat;
+background-position:left;
+padding-left:20px;
+text-align:left;
+}
+
+.flags{
+text-decoration:none;
+text-height:24px;
+}
+
+/*
+-------------------------------
+NOTE styles
+-------------------------------
+*/
+.notetitle, .tiptitle, .fastpathtitle{
+font-weight:bold;
+}
+
+.attentiontitle,.cautiontitle,.dangertitle,.importanttitle,.remembertitle,.restrictiontitle{
+font-weight:bold;
+}
+
+.note,.tip,.fastpath{
+background: #F2F2F2 url(../images/ico_note.png);
+background-repeat: no-repeat;
+background-position: top left;
+padding:5px;
+padding-left:40px;
+padding-bottom:10px;
+border:#999 1px dotted;
+color:#666666;
+margin:5px;
+}
+
+.attention,.caution,.danger,.important,.remember,.restriction{
+background: #F2F2F2 url(../images/ico_note_attention.png);
+background-repeat:no-repeat;
+background-position:top left;
+padding:5px;
+padding-left:40px;
+padding-bottom:10px;
+border:#999 1px dotted;
+color:#666666;
+margin:5px;
+}
+
+/*
+-------------------------------
+Top navigation
+-------------------------------
+*/
+
+.header{
+
+height:1px;
+padding:0px;
+margin:0px;
+}
+
+.qtref{
+display: block;
+position: relative;
+top: -76px;
+height:15px;
+z-index: 1;
+font-size:11px;
+padding-right:10px;
+float:right;
+}
+
+.naviNextPrevious{
+display: block;
+position: relative;
+text-align: right;
+top: -53px;
+float:right;
+height:20px;
+z-index:1;
+padding-right:10px;
+padding-top:2px;
+vertical-align:top;
+margin:0px;
+}
+
+
+.naviNextPrevious > a:first-child{
+background-image:url(../images/btn_prev.png);
+background-repeat:no-repeat;
+background-position:left;
+padding-left:20px;
+height:20px;
+padding-left:20px;
+}
+
+.naviNextPrevious > a:last-child{
+background-image:url(../images/btn_next.png);
+background-repeat:no-repeat;
+background-position:right;
+padding-right:20px;
+height:20px;
+margin-left:30px;
+}
+
+.breadcrumb{
+display: block;
+position: relative;
+top:-20px;
+/*border-top:2px solid #ffffff;*/
+border-bottom: 1px solid #cecece;
+background-color:#F2F2F2;
+z-index:1;
+height:20px;
+padding:0px;
+margin:0px;
+padding-left:10px;
+padding-top:2px;
+margin-left:-5px;
+margin-right:-5px;
+}
+
+.breadcrumb ul{
+ margin:0px;
+ padding:0px;
+}
+
+.breadcrumb ul li{
+background-color:#F2F2F2;
+list-style-type:none;
+padding:0;
+margin:0;
+height:20px;
+}
+
+.breadcrumb li{
+float:left;
+}
+
+.breadcrumb .first {
+background:url(../images/home.png);
+background-position:left;
+background-repeat:no-repeat;
+padding-left:20px;
+}
+
+
+.breadcrumb li a{
+color:#2C418D;
+display:block;
+text-decoration:none;
+background:url(../images/arrow.png);
+background-repeat:no-repeat;
+background-position:right;
+padding-right:25px;
+padding-left:10px;
+}
+
+.breadcrumb li a:hover{
+color:#909090;
+display:block;
+text-decoration:none;
+background:url(../images/arrow.png);
+background-repeat:no-repeat;
+background-position:right;
+padding-right:20px;
+padding-left:10px;
+}
+
+
+/* table of content
+no display
+*/
+
+/*
+-----------
+headers
+-----------
+*/
+
+
+@media screen{
+.title{
+color:#313131;
+font-size: 18px;
+font-weight: normal;
+left: 0;
+padding-bottom: 20px;
+padding-left: 10px;
+padding-top: 20px;
+position: absolute;
+right: 0;
+top: 0;
+background-color:#E6E6E6;
+border-bottom: 1px #CCC solid;
+border-top: 2px #CCC solid;
+font-weight:bold;
+margin-left:0px;
+margin-right:0px;
+}
+}
+
+h1 {
+margin: 0;
+}
+
+h2, p.h2 {
+font: 500 16px/1.2 Arial;
+font-weight:100;
+background-color:#F2F3F4;
+padding:4px;
+margin-bottom:30px;
+margin-top:30px;
+border-top:#E0E0DE 1px solid;
+border-bottom: #E0E0DE 1px solid;
+max-width: 99%;
+}
+
+h3{
+
+font: 500 14px/1.2 Arial;
+font-weight:100;
+text-decoration:underline;
+margin-bottom:30px;
+margin-top:30px;
+}
+
+h3.fn,span.fn{
+border-width: 1px;
+border-style: solid;
+border-color: #E6E6E6;
+-moz-border-radius: 7px 7px 7px 7px;
+-webkit-border-radius: 7px 7px 7px 7px;
+border-radius: 7px 7px 7px 7px;
+background-color: #F6F6F6;
+word-spacing: 3px;
+padding: 5px 5px;
+text-decoration:none;
+font-weight:bold;
+max-width:75%;
+font-size:14px;
+margin:0px;
+margin-top:30px;
+
+}
+
+.name{
+color:#1A1A1A;
+}
+.type{
+color:#808080;
+}
+
+
+
+@media print {
+.title {
+color:#0066CB;
+font-family:Arial, Helvetica;
+font-size: 32px;
+font-weight: normal;
+left: 0;
+position: absolute;
+right: 0;
+top: 0;
+}
+}
+
+
+/*
+-----------------
+table styles
+-----------------
+*/
+.table img {
+border:none;
+margin-left:0px;
+-moz-box-shadow:0px 0px 0px #fff;
+-webkit-box-shadow: 0px 0px 0px #fff;
+box-shadow: 0px 0px 0px #fff;
+}
+
+/* table with border alternative colours*/
+
+ table,pre{
+-moz-border-radius: 7px 7px 7px 7px;
+-webkit-border-radius: 7px 7px 7px 7px;
+ border-radius: 7px 7px 7px 7px;
+background-color: #F6F6F6;
+border: 1px solid #E6E6E6;
+border-collapse: separate;
+font-size: 12px;
+line-height: 1.2;
+margin-bottom: 25px;
+margin-left: 15px;
+font-size: 12px;
+line-height: 1.2;
+margin-bottom: 25px;
+margin-left: 15px;
+}
+
+
+table th{
+text-align:left;
+padding-left:20px;
+}
+
+table td {
+padding: 3px 15px 3px 20px;
+border-bottom:#CCC dotted 1px;
+}
+table p { margin:0px;}
+
+table tr.even {
+background-color: white;
+color: #66666E;
+}
+
+table tr.odd {
+background-color: #F6F6F6;
+color: #66666E;
+}
+
+
+table thead {
+text-align:left;
+padding-left:20px;
+background-color:#e1e0e0;
+border-left:none;
+border-right:none;
+}
+
+table thead th {
+padding-top:5px;
+padding-left:10px;
+padding-bottom:5px;
+border-bottom: 2px solid #D1D1D1;
+padding-right:10px;
+}
+
+
+/* table bodless & white*/
+
+.borderless {
+border-radius: 0px 0px 0px 0px;
+background-color: #fff;
+border: 1px solid #fff;
+}
+
+.borderless tr {
+background-color: #FFF;
+color: #66666E;
+}
+
+.borderless td {
+border:none;
+border-bottom:#fff dotted 1px;
+}
+
+/*
+-----------
+List
+-----------
+*/
+
+ul{
+padding-bottom:2px;
+}
+
+li {
+margin-bottom: 10px;
+padding-left: 8px;
+list-style:outside;
+list-style-type:square;
+text-align:left;
+}
+
+
+ol{
+margin:10px;
+padding:0;
+}
+
+ol > li{
+margin-left: 30px;
+padding-left:8px;
+list-style:decimal;
+}
+
+.centerAlign{
+text-align: left;
+}
+
+.cpp{
+display: block;
+margin: 10;
+overflow: hidden;
+overflow-x: hidden;
+overflow-y: hidden;
+padding: 20px 0 20px 0;
+}
+
+.footer{
+margin-top: 50px;
+padding-left:5px;
+margin-bottom: 10px;
+font-size:10px;
+border-top: 1px solid #999;
+padding-top:11px;
+}
+
+.footerNavi{
+width:auto;
+text-align:right;
+margin-top:50px;
+z-index:1;
+}
+
+.memItemLeft{
+padding-right: 3px;
+}
+
+.memItemRight{
+padding: 3px 15px 3px 0;
+}
+
+.qml{
+display: block;
+margin: 10;
+overflow: hidden;
+overflow-x: hidden;
+overflow-y: hidden;
+padding: 20px 0 20px 0;
+}
+
+.qmldefault{
+padding-left: 5px;
+float: right;
+color: red;
+}
+
+.qmlreadonly{
+padding-left: 5px;
+float: right;
+color: #254117;
+}
+
+.rightAlign{
+padding: 3px 5px 3px 10px;
+text-align: right;
+}
+
+/*
+-----------
+Content table
+-----------
+*/
+
+@media print{
+.toc {
+float: right;
+padding-bottom: 10px;
+padding-top: 50px;
+width: 100%;
+background-image:url(../images/bgrContent.png);
+background-position:top;
+background-repeat:no-repeat;
+}
+}
+
+@media screen{
+.toc{
+clear:both;
+float:right;
+vertical-align:top;
+-moz-border-radius: 7px 7px 7px 7px;
+-webkit-border-radius: 7px 7px 7px 7px;
+border-radius: 7px 7px 7px 7px;
+ background:#FFF url(../images/bgrContent.png);
+background-position:top;
+background-repeat:repeat-x;
+border: 1px solid #E6E6E6;
+padding-left:5px;
+padding-bottom:10px;
+height: auto;
+width: 200px;
+text-align:left;
+z-index:2;
+margin-left:20px;
+margin-right:20px;
+margin-top:0px;
+padding-top:0px;
+}
+}
+
+.toc h3{
+text-decoration:none;
+}
+
+.toc h3{font: 500 14px/1.2 Arial;
+font-weight:100;
+padding:0px;
+margin:0px;
+padding-top:5px;
+padding-left:5px;
+}
+
+
+.toc ul{
+width:160px;
+padding-left:10px;
+padding-right:5px;
+padding-bottom:10px;
+padding-top:10px;
+}
+
+.toc ul li{
+margin-left:20px;
+list-style-image:url(../images/blu_dot.png);
+list-style:outside;
+
+}
+
+
+.toc ul li a:link{
+color: #2C418D;
+text-decoration: none;
+}
+
+.toc ul li a:hover{
+color: #869CD1;
+text-decoration:underline;
+
+}
+
+.toc ul li a:visited{
+color: #869CD1;
+font-weight: bold;
+}
+
+.level1{
+border:none;}
+
+.clearfix{
+clear:both;}
+
for Qt.
\legalese
- Copyright (C) 2000 Ming-Che Chuang \BR
- Copyright (C) 2002 James Su, Turbolinux Inc. \BR
+ Copyright (C) 2000 Ming-Che Chuang
+ Copyright (C) 2002 James Su, Turbolinux Inc.
Copyright (C) 2002 Anthony Fok, ThizLinux Laboratory Ltd.
Redistribution and use in source and binary forms, with or without
for the various Big5 CharMapML tables.
\legalese
- Copyright (C) 2000 Ming-Che Chuang \BR
- Copyright (C) 2001, 2002 James Su, Turbolinux Inc. \BR
- Copyright (C) 2002 WU Yi, HancomLinux Inc. \BR
+ Copyright (C) 2000 Ming-Che Chuang
+ Copyright (C) 2001, 2002 James Su, Turbolinux Inc.
+ Copyright (C) 2002 WU Yi, HancomLinux Inc.
Copyright (C) 2001, 2002 Anthony Fok, ThizLinux Laboratory Ltd.
Redistribution and use in source and binary forms, with or without
The copyright notice for their code follows:
\legalese
- Copyright (C) 2000 TurboLinux, Inc. Written by Justin Yu and Sean Chen. \BR
- Copyright (C) 2001, 2002 Turbolinux, Inc. Written by James Su. \BR
+ Copyright (C) 2000 TurboLinux, Inc. Written by Justin Yu and Sean Chen.
+ Copyright (C) 2001, 2002 Turbolinux, Inc. Written by James Su.
Copyright (C) 2001, 2002 ThizLinux Laboratory Ltd. Written by Anthony Fok.
Redistribution and use in source and binary forms, with or without
KOI8-R encoding, and want to convert it to Unicode. The simple way
to do it is like this:
- \snippet doc/src/snippets/code/src_corelib_codecs_qtextcodec.cpp 0
+ \snippet code/src_corelib_codecs_qtextcodec.cpp 0
After this, \c string holds the text converted to Unicode.
Converting a string from Unicode to the local encoding is just as
easy:
- \snippet doc/src/snippets/code/src_corelib_codecs_qtextcodec.cpp 1
+ \snippet code/src_corelib_codecs_qtextcodec.cpp 1
To read or write files in various encodings, use QTextStream and
its \l{QTextStream::setCodec()}{setCodec()} function. See the
object for the codec and use this QTextDecoder for the whole
decoding process, as shown below:
- \snippet doc/src/snippets/code/src_corelib_codecs_qtextcodec.cpp 2
+ \snippet code/src_corelib_codecs_qtextcodec.cpp 2
The QTextDecoder object maintains state between chunks and therefore
works correctly even if a multi-byte character is split between
--- /dev/null
+include(../../../doc/global/qt-cpp-ignore.qdocconf)
+
+project = QtCore
+description = Qt Core Reference Documentation
+url = http://qt-project.org/doc/qt-5.0/qtcore
+version = 5.0.0
+
+sourceencoding = UTF-8
+outputencoding = UTF-8
+naturallanguage = en_US
+qhp.projects = QtCore
+
+qhp.QtCore.file = qtcore.qhp
+qhp.Qt.namespace = org.qt-project.qtcore.500
+qhp.Qt.virtualFolder = qdoc
+qhp.Qt.indexTitle = Qt Core Reference Documentation
+qhp.Qt.indexRoot =
+
+qhp.Qt.filterAttributes = qtcore 5.0.0 qtrefdoc
+qhp.Qt.customFilters.Qt.name = QtCore 5.0.0
+qhp.Qt.customFilters.Qt.filterAttributes = qtcore 5.0.0
+qhp.Qt.subprojects = classes overviews examples
+qhp.Qt.subprojects.classes.title = Classes
+qhp.Qt.subprojects.classes.indexTitle = Qt Core's Classes
+qhp.Qt.subprojects.classes.selectors = class fake:headerfile
+qhp.Qt.subprojects.classes.sortPages = true
+qhp.Qt.subprojects.overviews.title = Overviews
+qhp.Qt.subprojects.overviews.indexTitle = All Overviews and HOWTOs
+qhp.Qt.subprojects.overviews.selectors = fake:page,group,module
+qhp.Qt.subprojects.examples.title = Qt Core Tutorials and Examples
+qhp.Qt.subprojects.examples.indexTitle = Qt Core Examples
+qhp.Qt.subprojects.examples.selectors = fake:example
+
+dita.metadata.default.author = Qt Project
+dita.metadata.default.permissions = all
+dita.metadata.default.publisher = Qt Project
+dita.metadata.default.copyryear = 2012
+dita.metadata.default.copyrholder = Nokia
+dita.metadata.default.audience = programmer
+
+sources.fileextensions = "*.c++ *.cc *.cpp *.cxx *.mm *.qml *.qdoc"
+headers.fileextensions = "*.ch *.h *.h++ *.hh *.hpp *.hxx"
+
+examples.fileextensions = "*.cpp *.h *.js *.xq *.svg *.xml *.ui *.qhp *.qhcp *.qml *.css"
+examples.imageextensions = "*.png"
+
+outputdir = ../../../doc/qtcore
+tagfile = ../../../doc/qtcore/qtcore.tags
+
+HTML.generatemacrefs = "true"
+HTML.nobreadcrumbs = "true"
+
+HTML.templatedir = .
+
+HTML.stylesheets = ../../../doc/global/style/offline.css
+
+HTML.headerstyles = \
+ " <link rel=\"stylesheet\" type=\"text/css\" href=\"style/offline.css\" />\n"
+
+HTML.endheader = \
+ "</head>\n" \
+
+defines = Q_QDOC \
+ QT_.*_SUPPORT \
+ QT_.*_LIB \
+ QT_COMPAT \
+ QT_KEYPAD_NAVIGATION \
+ QT_NO_EGL \
+ Q_WS_.* \
+ Q_OS_.* \
+ Q_BYTE_ORDER \
+ QT_DEPRECATED \
+ QT_DEPRECATED_* \
+ Q_NO_USING_KEYWORD \
+ __cplusplus \
+ Q_COMPILER_INITIALIZER_LISTS
+
+versionsym = QT_VERSION_STR
+
+codeindent = 1
+
+headerdirs += ..
+
+sourcedirs += ..
+
+exampledirs += ../../../examples \
+ ../ \
+ snippets
+
+imagedirs += images
--- /dev/null
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** 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 Nokia Corporation 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]
+QQueue<int> queue;
+queue.enqueue(1);
+queue.enqueue(2);
+queue.enqueue(3);
+while (!queue.isEmpty())
+ cout << queue.dequeue() << endl;
+//! [0]
--- /dev/null
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** 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 Nokia Corporation 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]
+QVector<int> integerVector;
+QVector<QString> stringVector;
+//! [0]
+
+
+//! [1]
+QVector<QString> vector(200);
+//! [1]
+
+
+//! [2]
+QVector<QString> vector(200, "Pass");
+//! [2]
+
+
+//! [3]
+if (vector[0] == "Liz")
+ vector[0] = "Elizabeth";
+//! [3]
+
+
+//! [4]
+for (int i = 0; i < vector.size(); ++i) {
+ if (vector.at(i) == "Alfonso")
+ cout << "Found Alfonso at position " << i << endl;
+}
+//! [4]
+
+
+//! [5]
+int i = vector.indexOf("Harumi");
+if (i != -1)
+ cout << "First occurrence of Harumi is at position " << i << endl;
+//! [5]
+
+
+//! [6]
+QVector<int> vector(10);
+int *data = vector.data();
+for (int i = 0; i < 10; ++i)
+ data[i] = 2 * i;
+//! [6]
+
+
+//! [7]
+QVector<QString> vector(0);
+vector.append("one");
+vector.append("two");
+vector.append("three");
+// vector: ["one", "two", "three"]
+//! [7]
+
+
+//! [8]
+QVector<QString> vector;
+vector.prepend("one");
+vector.prepend("two");
+vector.prepend("three");
+// vector: ["three", "two", "one"]
+//! [8]
+
+
+//! [9]
+QVector<QString> vector;
+vector << "alpha" << "beta" << "delta";
+vector.insert(2, "gamma");
+// vector: ["alpha", "beta", "gamma", "delta"]
+//! [9]
+
+
+//! [10]
+QVector<double> vector;
+vector << 2.718 << 1.442 << 0.4342;
+vector.insert(1, 3, 9.9);
+// vector: [2.718, 9.9, 9.9, 9.9, 1.442, 0.4342]
+//! [10]
+
+
+//! [11]
+QVector<QString> vector(3);
+vector.fill("Yes");
+// vector: ["Yes", "Yes", "Yes"]
+
+vector.fill("oh", 5);
+// vector: ["oh", "oh", "oh", "oh", "oh"]
+//! [11]
+
+
+//! [12]
+QVector<QString> vector;
+vector << "A" << "B" << "C" << "B" << "A";
+vector.indexOf("B"); // returns 1
+vector.indexOf("B", 1); // returns 1
+vector.indexOf("B", 2); // returns 3
+vector.indexOf("X"); // returns -1
+//! [12]
+
+
+//! [13]
+QList<QString> vector;
+vector << "A" << "B" << "C" << "B" << "A";
+vector.lastIndexOf("B"); // returns 3
+vector.lastIndexOf("B", 3); // returns 3
+vector.lastIndexOf("B", 2); // returns 1
+vector.lastIndexOf("X"); // returns -1
+//! [13]
+
+
+//! [14]
+QVector<double> vect;
+vect << "red" << "green" << "blue" << "black";
+
+QList<double> list = vect.toList();
+// list: ["red", "green", "blue", "black"]
+//! [14]
+
+
+//! [15]
+QStringList list;
+list << "Sven" << "Kim" << "Ola";
+
+QVector<QString> vect = QVector<QString>::fromList(list);
+// vect: ["Sven", "Kim", "Ola"]
+//! [15]
+
+
+//! [16]
+std::vector<double> stdvector;
+vector.push_back(1.2);
+vector.push_back(0.5);
+vector.push_back(3.14);
+
+QVector<double> vector = QVector<double>::fromStdVector(stdvector);
+//! [16]
+
+
+//! [17]
+QVector<double> vector;
+vector << 1.2 << 0.5 << 3.14;
+
+std::vector<double> stdvector = vector.toStdVector();
+//! [17]
--- /dev/null
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** 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 Nokia Corporation 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 <QApplication>
+#include <QLabel>
+#include <QPointer>
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+//! [0]
+ QPointer<QLabel> label = new QLabel;
+ label->setText("&Status:");
+//! [0]
+
+//! [1]
+ if (label)
+//! [1] //! [2]
+ label->show();
+//! [2]
+ return 0;
+}
Here's an example custom data type that meets the requirement of
an assignable data type:
- \snippet doc/src/snippets/code/doc_src_containers.cpp 0
+ \snippet code/doc_src_containers.cpp 0
If we don't provide a copy constructor or an assignment operator,
C++ provides a default implementation that performs a
explicit constructors or assignment operator, the following data
type can be stored in a container:
- \snippet doc/src/snippets/streaming/main.cpp 0
+ \snippet streaming/main.cpp 0
Some containers have additional requirements for the data types
they can store. For example, the Key type of a QMap<Key, T> must
straightforward; here's how we could do it for the Movie struct
above:
- \snippet doc/src/snippets/streaming/main.cpp 1
+ \snippet streaming/main.cpp 1
\codeline
- \snippet doc/src/snippets/streaming/main.cpp 2
+ \snippet streaming/main.cpp 2
\keyword default-constructed values
iterator positions as red arrows for a list containing four
items:
- \img javaiterators1.png
+ \image javaiterators1.png
Here's a typical loop for iterating through all the elements of a
QList<QString> in order and printing them to the console:
- \snippet doc/src/snippets/code/doc_src_containers.cpp 1
+ \snippet code/doc_src_containers.cpp 1
It works as follows: The QList to iterate over is passed to the
QListIterator constructor. At that point, the iterator is located
Here's how to iterate backward in a QList:
- \snippet doc/src/snippets/code/doc_src_containers.cpp 2
+ \snippet code/doc_src_containers.cpp 2
The code is symmetric with iterating forward, except that we
start by calling \l{QListIterator::toBack()}{toBack()}
\l{QListIterator::next()}{next()} and
\l{QListIterator::previous()}{previous()} on an iterator:
- \img javaiterators2.png
+ \image javaiterators2.png
The following table summarizes the QListIterator API:
QMutableListIterator. Here's an example where we remove all
odd numbers from a QList<int> using QMutableListIterator:
- \snippet doc/src/snippets/code/doc_src_containers.cpp 3
+ \snippet code/doc_src_containers.cpp 3
The next() call in the loop is made every time. It jumps over the
next item in the list. The
the iterator, so it is safe to continue using it. This works just
as well when iterating backward:
- \snippet doc/src/snippets/code/doc_src_containers.cpp 4
+ \snippet code/doc_src_containers.cpp 4
If we just want to modify the value of an existing item, we can
use \l{QMutableListIterator::setValue()}{setValue()}. In the code
below, we replace any value larger than 128 with 128:
- \snippet doc/src/snippets/code/doc_src_containers.cpp 5
+ \snippet code/doc_src_containers.cpp 5
Just like \l{QMutableListIterator::remove()}{remove()},
\l{QMutableListIterator::setValue()}{setValue()} operates on the
operations, we don't even need
\l{QMutableListIterator::setValue()}{setValue()}:
- \snippet doc/src/snippets/code/doc_src_containers.cpp 6
+ \snippet code/doc_src_containers.cpp 6
As mentioned above, QLinkedList's, QVector's, and QSet's iterator
classes have exactly the same API as QList's. We will now turn to
The following example removes all (capital, country) pairs where
the capital's name ends with "City":
- \snippet doc/src/snippets/code/doc_src_containers.cpp 7
+ \snippet code/doc_src_containers.cpp 7
QMapIterator also provides a key() and a value() function that
operate directly on the iterator and that return the key and
example, the following code copies the contents of a QMap into a
QHash:
- \snippet doc/src/snippets/code/doc_src_containers.cpp 8
+ \snippet code/doc_src_containers.cpp 8
If we want to iterate through all the items with the same
value, we can use \l{QMapIterator::findNext()}{findNext()}
Here's an example where we remove all the items with a particular
value:
- \snippet doc/src/snippets/code/doc_src_containers.cpp 9
+ \snippet code/doc_src_containers.cpp 9
\section2 STL-Style Iterators
Here's a typical loop for iterating through all the elements of a
QList<QString> in order and converting them to lowercase:
- \snippet doc/src/snippets/code/doc_src_containers.cpp 10
+ \snippet code/doc_src_containers.cpp 10
Unlike \l{Java-style iterators}, STL-style iterators point
directly at items. The begin() function of a container returns an
The diagram below shows the valid iterator positions as red
arrows for a vector containing four items:
- \img stliterators1.png
+ \image stliterators1.png
Iterating backward with an STL-style iterator requires us to
decrement the iterator \e before we access the item. This
requires a \c while loop:
- \snippet doc/src/snippets/code/doc_src_containers.cpp 11
+ \snippet code/doc_src_containers.cpp 11
In the code snippets so far, we used the unary \c * operator to
retrieve the item (of type QString) stored at a certain iterator
For read-only access, you can use const_iterator, constBegin(),
and constEnd(). For example:
- \snippet doc/src/snippets/code/doc_src_containers.cpp 12
+ \snippet code/doc_src_containers.cpp 12
The following table summarizes the STL-style iterators' API:
value() function to retrieve the value. For example, here's how
we would print all items in a QMap to the console:
- \snippet doc/src/snippets/code/doc_src_containers.cpp 13
+ \snippet code/doc_src_containers.cpp 13
Thanks to \l{implicit sharing}, it is very inexpensive for a
function to return a container per value. The Qt API contains
using an STL iterator, you should always take a copy of the
container and iterate over the copy. For example:
- \snippet doc/src/snippets/code/doc_src_containers.cpp 14
+ \snippet code/doc_src_containers.cpp 14
This problem doesn't occur with functions that return a const or
non-const reference to a container.
statement. For example, here's how to use \c foreach to iterate
over a QLinkedList<QString>:
- \snippet doc/src/snippets/code/doc_src_containers.cpp 15
+ \snippet code/doc_src_containers.cpp 15
The \c foreach code is significantly shorter than the equivalent
code that uses iterators:
- \snippet doc/src/snippets/code/doc_src_containers.cpp 16
+ \snippet code/doc_src_containers.cpp 16
Unless the data type contains a comma (e.g., \c{QPair<int,
int>}), the variable used for iteration can be defined within the
\c foreach statement:
- \snippet doc/src/snippets/code/doc_src_containers.cpp 17
+ \snippet code/doc_src_containers.cpp 17
And like any other C++ loop construct, you can use braces around
the body of a \c foreach loop, and you can use \c break to leave
the loop:
- \snippet doc/src/snippets/code/doc_src_containers.cpp 18
+ \snippet code/doc_src_containers.cpp 18
With QMap and QHash, \c foreach accesses the value component of
the (key, value) pairs. If you want to iterate over both the keys
and the values, you can use iterators (which are fastest), or you
can write code like this:
- \snippet doc/src/snippets/code/doc_src_containers.cpp 19
+ \snippet code/doc_src_containers.cpp 19
For a multi-valued map:
- \snippet doc/src/snippets/code/doc_src_containers.cpp 20
+ \snippet code/doc_src_containers.cpp 20
Qt automatically takes a copy of the container when it enters a
\c foreach loop. If you modify the container as you are
In addition to \c foreach, Qt also provides a \c forever
pseudo-keyword for infinite loops:
- \snippet doc/src/snippets/code/doc_src_containers.cpp 21
+ \snippet code/doc_src_containers.cpp 21
If you're worried about namespace pollution, you can disable
these macros by adding the following line to your \c .pro file:
- \snippet doc/src/snippets/code/doc_src_containers.cpp 22
+ \snippet code/doc_src_containers.cpp 22
\section1 Other Container-Like Classes
Consider the following code, which builds a QString from another
QString:
- \snippet doc/src/snippets/code/doc_src_containers.cpp 23
+ \snippet code/doc_src_containers.cpp 23
We build the string \c out dynamically by appending one character
to it at a time. Let's assume that we append 15000 characters to
data in all member functions that change the internal data.
Code fragment:
- \snippet doc/src/snippets/code/doc_src_groups.cpp 0
+ \snippet code/doc_src_groups.cpp 0
\section1 List of Classes
concern for the copying overhead.
Example:
- \snippet doc/src/snippets/code/doc_src_groups.cpp 1
+ \snippet code/doc_src_groups.cpp 1
In this example, \c p1 and \c p2 share data until QPainter::begin()
is called for \c p2, because painting a pixmap will modify it.
data in a binary format that is directly mmap'able and very fast to
access.
- More details about the JSON data format can be found at \link json.org
+ More details about the JSON data format can be found at \l{http://json.org}{json.org}
and in \l{http://tools.ietf.org/html/rfc4627}{RFC-4627}.
\tableofcontents
For example, let's assume \c MyWidget inherits from QWidget and
is declared with the Q_OBJECT macro:
- \snippet doc/src/snippets/qtcast/qtcast.cpp 0
+ \snippet qtcast/qtcast.cpp 0
The \c obj variable, of type \c{QObject *}, actually refers to a
\c MyWidget object, so we can cast it appropriately:
- \snippet doc/src/snippets/qtcast/qtcast.cpp 1
+ \snippet qtcast/qtcast.cpp 1
The cast from QObject to QWidget is successful, because the
object is actually a \c MyWidget, which is a subclass of QWidget.
Since we know that \c obj is a \c MyWidget, we can also cast it to
\c{MyWidget *}:
- \snippet doc/src/snippets/qtcast/qtcast.cpp 2
+ \snippet qtcast/qtcast.cpp 2
The cast to \c MyWidget is successful because qobject_cast()
makes no distinction between built-in Qt types and custom types.
- \snippet doc/src/snippets/qtcast/qtcast.cpp 3
- \snippet doc/src/snippets/qtcast/qtcast.cpp 4
+ \snippet qtcast/qtcast.cpp 3
+ \snippet qtcast/qtcast.cpp 4
The cast to QLabel, on the other hand, fails. The pointer is then
set to 0. This makes it possible to handle objects of different
types differently at run-time, based on the type:
- \snippet doc/src/snippets/qtcast/qtcast.cpp 5
- \snippet doc/src/snippets/qtcast/qtcast.cpp 6
+ \snippet qtcast/qtcast.cpp 5
+ \snippet qtcast/qtcast.cpp 6
While it is possible to use QObject as a base class without the
Q_OBJECT macro and without meta-object code, neither signals
behavior applies. Normally, the order of destruction still doesn't
present a problem. Consider the following snippet:
- \snippet doc/src/snippets/code/doc_src_objecttrees.cpp 0
+ \snippet code/doc_src_objecttrees.cpp 0
The parent, \c window, and the child, \c quit, are both \l {QObject}
{QObjects} because QPushButton inherits QWidget, and QWidget inherits
But now consider what happens if we swap the order of construction, as
shown in this second snippet:
- \snippet doc/src/snippets/code/doc_src_objecttrees.cpp 1
+ \snippet code/doc_src_objecttrees.cpp 1
In this case, the order of destruction causes a problem. The parent's
destructor is called first because it was created last. It then calls
To declare a property, use the \l {Q_PROPERTY()} {Q_PROPERTY()}
macro in a class that inherits QObject.
- \snippet doc/src/snippets/code/doc_src_properties.cpp 0
+ \snippet code/doc_src_properties.cpp 0
Here are some typical examples of property declarations taken from
class QWidget.
- \snippet doc/src/snippets/code/doc_src_properties.cpp 1
+ \snippet code/doc_src_properties.cpp 1
A property behaves like a class data member, but it has additional
features accessible through the \l {Meta-Object System}.
be a user-defined type. In this example, class QDate is considered
to be a user-defined type.
- \snippet doc/src/snippets/code/doc_src_properties.cpp 2
+ \snippet code/doc_src_properties.cpp 2
Because QDate is user-defined, you must include the \c{<QDate>}
header file with the property declaration.
the code snippet below, the call to QAbstractButton::setDown() and
the call to QObject::setProperty() both set property "down".
- \snippet doc/src/snippets/code/doc_src_properties.cpp 3
+ \snippet code/doc_src_properties.cpp 3
Accessing a property through its \c WRITE accessor is the better
of the two, because it is faster and gives better diagnostics at
can \e discover a class's properties at run time by querying its
QObject, QMetaObject, and \l {QMetaProperty} {QMetaProperties}.
- \snippet doc/src/snippets/code/doc_src_properties.cpp 4
+ \snippet code/doc_src_properties.cpp 4
In the above snippet, QMetaObject::property() is used to get \l
{QMetaProperty} {metadata} about each property defined in some
for the \c READ and \c WRITE functions. The declaration of MyClass
then might look like this:
- \snippet doc/src/snippets/code/doc_src_properties.cpp 5
+ \snippet code/doc_src_properties.cpp 5
The \c READ function is const and returns the property type. The
\c WRITE function returns void and has exactly one parameter of
QObject that is an instance of MyClass, we have two ways to set
its priority property:
- \snippet doc/src/snippets/code/doc_src_properties.cpp 6
+ \snippet code/doc_src_properties.cpp 6
In the example, the enumeration type that is the property type is
declared in MyClass and registered with the \l{Meta-Object System}
Q_CLASSINFO(), that can be used to attach additional
\e{name}--\e{value} pairs to a class's meta-object, for example:
- \snippet doc/src/snippets/code/doc_src_properties.cpp 7
+ \snippet code/doc_src_properties.cpp 7
Like other meta-data, class information is accessible at run-time
through the meta-object; see QMetaObject::classInfo() for details.
In GUI programming, when we change one widget, we often want
another widget to be notified. More generally, we want objects of
any kind to be able to communicate with one another. For example,
- if a user clicks a \gui{Close} button, we probably want the
+ 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
practice to subclass widgets and add your own slots so that you
can handle the signals that you are interested in.
- \img abstract-connections.png
+ \image abstract-connections.png
\omit
\caption An abstract view of some signals and slots connections
\endomit
A minimal C++ class declaration might read:
- \snippet doc/src/snippets/signalsandslots/signalsandslots.h 0
+ \snippet signalsandslots/signalsandslots.h 0
A small QObject-based class might read:
- \snippet doc/src/snippets/signalsandslots/signalsandslots.h 1
+ \snippet signalsandslots/signalsandslots.h 1
\codeline
- \snippet doc/src/snippets/signalsandslots/signalsandslots.h 2
- \snippet doc/src/snippets/signalsandslots/signalsandslots.h 3
+ \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
Here is a possible implementation of the \c{Counter::setValue()}
slot:
- \snippet doc/src/snippets/signalsandslots/signalsandslots.cpp 0
+ \snippet signalsandslots/signalsandslots.cpp 0
The \c{emit} line emits the signal \c valueChanged() from the
object, with the new value as argument.
and connect the first object's \c valueChanged() signal to the
second object's \c setValue() slot using QObject::connect():
- \snippet doc/src/snippets/signalsandslots/signalsandslots.cpp 1
- \snippet doc/src/snippets/signalsandslots/signalsandslots.cpp 2
+ \snippet signalsandslots/signalsandslots.cpp 1
+ \snippet signalsandslots/signalsandslots.cpp 2
\codeline
- \snippet doc/src/snippets/signalsandslots/signalsandslots.cpp 3
- \snippet doc/src/snippets/signalsandslots/signalsandslots.cpp 4
+ \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
also check if an object \link QObject::inherits()
inherits\endlink a specific class, for example:
- \snippet doc/src/snippets/signalsandslots/signalsandslots.cpp 5
- \snippet doc/src/snippets/signalsandslots/signalsandslots.cpp 6
+ \snippet signalsandslots/signalsandslots.cpp 5
+ \snippet signalsandslots/signalsandslots.cpp 6
The meta-object information is also used by qobject_cast<T>(), which
is similar to QObject::inherits() but is less error-prone:
- \snippet doc/src/snippets/signalsandslots/signalsandslots.cpp 7
+ \snippet signalsandslots/signalsandslots.cpp 7
See \l{Meta-Object System} for more information.
Here is a simple commented example of a widget.
- \snippet doc/src/snippets/signalsandslots/lcdnumber.h 0
- \snippet doc/src/snippets/signalsandslots/lcdnumber.h 1
+ \snippet signalsandslots/lcdnumber.h 0
+ \snippet signalsandslots/lcdnumber.h 1
\codeline
- \snippet doc/src/snippets/signalsandslots/lcdnumber.h 2
+ \snippet signalsandslots/lcdnumber.h 2
\codeline
- \snippet doc/src/snippets/signalsandslots/lcdnumber.h 3
- \snippet doc/src/snippets/signalsandslots/lcdnumber.h 4
- \snippet doc/src/snippets/signalsandslots/lcdnumber.h 5
+ \snippet signalsandslots/lcdnumber.h 3
+ \snippet signalsandslots/lcdnumber.h 4
+ \snippet signalsandslots/lcdnumber.h 5
\c LcdNumber inherits QObject, which has most of the signal-slot
knowledge, via QFrame and QWidget. It is somewhat similar to the
\l{moc}{run the moc} or to include the moc output in the link
command.
- \snippet doc/src/snippets/signalsandslots/lcdnumber.h 6
- \snippet doc/src/snippets/signalsandslots/lcdnumber.h 7
+ \snippet signalsandslots/lcdnumber.h 6
+ \snippet signalsandslots/lcdnumber.h 7
It's not obviously relevant to the moc, but if you inherit
QWidget you almost certainly want to have the \c parent argument
Some destructors and member functions are omitted here; the \c
moc ignores member functions.
- \snippet doc/src/snippets/signalsandslots/lcdnumber.h 8
- \snippet doc/src/snippets/signalsandslots/lcdnumber.h 9
+ \snippet signalsandslots/lcdnumber.h 8
+ \snippet signalsandslots/lcdnumber.h 9
\c LcdNumber emits a signal when it is asked to show an impossible
value.
functions when the number overflows, simply connect the signal to
two different slots. Qt will call both (in the order they were connected).
- \snippet doc/src/snippets/signalsandslots/lcdnumber.h 10
- \snippet doc/src/snippets/signalsandslots/lcdnumber.h 11
- \snippet doc/src/snippets/signalsandslots/lcdnumber.h 12
+ \snippet signalsandslots/lcdnumber.h 10
+ \snippet signalsandslots/lcdnumber.h 11
+ \snippet signalsandslots/lcdnumber.h 12
\codeline
- \snippet doc/src/snippets/signalsandslots/lcdnumber.h 13
+ \snippet signalsandslots/lcdnumber.h 13
A slot is a receiving function used to get information about
state changes in other widgets. \c LcdNumber uses it, as the code
map all the clicked() signals to a QSignalMapper object. Then you connect
the file's QPushButton::clicked() signal to the QSignalMapper::map() slot.
- \snippet doc/src/snippets/signalmapper/filereader.cpp 0
+ \snippet signalmapper/filereader.cpp 0
Then, you connect the \l{QSignalMapper::}{mapped()} signal to
\c{readFile()} where a different file will be opened, depending on
which push button is pressed.
- \snippet doc/src/snippets/signalmapper/filereader.cpp 1
+ \snippet signalmapper/filereader.cpp 1
\sa {Meta-Object System}, {Qt's Property System}
You can even use both mechanisms in the same project. Just add the
following line to your qmake project (.pro) file.
- \snippet doc/src/snippets/code/doc_src_containers.cpp 22
+ \snippet code/doc_src_containers.cpp 22
It tells Qt not to define the moc keywords \c{signals}, \c{slots},
and \c{emit}, because these names will be used by a 3rd party
All other Qt modules rely on this module. To include the
definitions of the module's classes, use the following directive:
- \snippet doc/src/snippets/code/doc_src_qtcore.cpp 0
+ \snippet code/doc_src_qtcore.cpp 0
*/
player reveals that there are again things going on in parallel within one
single process. While the media player is sending music to the audio driver,
the user interface with all its bells and whistles is being constantly
- updated. This is what threads are for \mdash concurrency within one single
+ updated. This is what threads are for -- concurrency within one single
process.
So how is concurrency implemented? Parallel work on single core CPUs is an
code that generates another thread which says hello in that thread and then
exits.
- \snippet examples/tutorials/threads/hellothread/hellothread.h 1
+ \snippet tutorials/threads/hellothread/hellothread.h 1
We derive a class from QThread and reimplement the \l{QThread::}{run()}
method.
- \snippet examples/tutorials/threads/hellothread/hellothread.cpp 1
+ \snippet tutorials/threads/hellothread/hellothread.cpp 1
The run method contains the code that will be run in a separate thread. In
this example, a message containing the thread ID will be printed.
QThread::start() will call the method in another thread.
- \snippet examples/tutorials/threads/hellothread/main.cpp 1
+ \snippet tutorials/threads/hellothread/main.cpp 1
To start the thread, our thread object needs to be instantiated. The
\l{QThread::}{start()} method creates a new thread and calls the
another thread needs to be placed in the reimplemented QRunnable::run()
method.
- \snippet examples/tutorials/threads/hellothreadpool/hellothreadpool.cpp 1
+ \snippet tutorials/threads/hellothreadpool/hellothreadpool.cpp 1
We instantiate Work in main(), locate the global thread pool and use the
QThreadPool::start() method. Now the thread pool runs our worker in another
\section2 Example 2: Using QtConcurrent
- \snippet examples/tutorials/threads/helloconcurrent/helloconcurrent.cpp 1
+ \snippet tutorials/threads/helloconcurrent/helloconcurrent.cpp 1
We write a global function hello() to implement the work. QtConcurrent::run()
is used to run the function in another thread. The result is a QFuture.
Communication from the GUI to the worker thread is shown in the next
example.
- \snippet examples/tutorials/threads/clock/main.cpp 1
+ \snippet tutorials/threads/clock/main.cpp 1
We've connected the \c clockThread with the label. The connection must be a
queued signal-slot connection because we want to put the call in the event
loop.
- \snippet examples/tutorials/threads/clock/clockthread.h 1
+ \snippet tutorials/threads/clock/clockthread.h 1
We have derived a class from QThread and declared the \c sendTime() signal.
- \snippet examples/tutorials/threads/clock/clockthread.cpp 1
+ \snippet tutorials/threads/clock/clockthread.cpp 1
The trickiest part of this example is that the timer is connected to its
slot via a direct connection. A default connection would produce a queued
The \c Thread class's code is short but somewhat involved, so we only show
how to use the class.
- \snippet examples/tutorials/threads/movedobject/main.cpp 1
+ \snippet tutorials/threads/movedobject/main.cpp 1
QMetaObject::invokeMethod() calls a slot via the event loop. The worker
object's methods should not be called directly after the object has been
To create a thread, subclass QThread and reimplement its
\l{QThread::run()}{run()} function. For example:
- \snippet doc/src/snippets/threads/threads.h 0
+ \snippet threads/threads.h 0
\codeline
- \snippet doc/src/snippets/threads/threads.cpp 0
- \snippet doc/src/snippets/threads/threads.cpp 1
+ \snippet threads/threads.cpp 0
+ \snippet threads/threads.cpp 1
\dots
- \snippet doc/src/snippets/threads/threads.cpp 2
+ \snippet threads/threads.cpp 2
\section1 Starting a Thread
a member function on the \e{same} instance of the class at the
same time. For example, the \c Counter class below is reentrant:
- \snippet doc/src/snippets/threads/threads.cpp 3
- \snippet doc/src/snippets/threads/threads.cpp 4
+ \snippet threads/threads.cpp 3
+ \snippet threads/threads.cpp 4
The class isn't thread-safe, because if multiple threads try to
modify the data member \c n, the result is undefined. This is
the class thread-safe is to protect all access to the data
members with a QMutex:
- \snippet doc/src/snippets/threads/threads.cpp 5
- \snippet doc/src/snippets/threads/threads.cpp 6
+ \snippet threads/threads.cpp 5
+ \snippet threads/threads.cpp 6
The QMutexLocker class automatically locks the mutex in its
constructor and unlocks it when the destructor is invoked, at the
Qt::Alignment parameter, which means that any combination of
Qt::AlignmentFlag values,or 0, is legal:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 0
+ \snippet code/src_corelib_global_qglobal.cpp 0
If you try to pass a value from another enum or just a plain
integer other than 0, the compiler will report an error. If you
Example:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 1
+ \snippet code/src_corelib_global_qglobal.cpp 1
You can then use the \c MyClass::Options type to store
combinations of \c MyClass::Option values.
To make the flags available for these purposes, the Q_FLAGS() macro must
be used:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp meta-object flags
+ \snippet code/src_corelib_global_qglobal.cpp meta-object flags
\section1 Naming Convention
The curious user will have seen that the Qt classes derived
from QObject typically include this macro in a private section:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 43
+ \snippet code/src_corelib_global_qglobal.cpp 43
It declares a copy constructor and an assignment operator in the
private section, so that if you use them by mistake, the compiler
will report an error.
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 44
+ \snippet code/src_corelib_global_qglobal.cpp 44
But even this might not catch absolutely every case. You might be
tempted to do something like this:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 45
+ \snippet code/src_corelib_global_qglobal.cpp 45
First of all, don't do that. Most compilers will generate code that
uses the copy constructor, so the privacy violation error will be
The Q_DECLARE_FLAGS() macro expands to
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 2
+ \snippet code/src_corelib_global_qglobal.cpp 2
\a Enum is the name of an existing enum type, whereas \a Flags is
the name of the QFlags<\e{Enum}> typedef.
Example:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 3
+ \snippet code/src_corelib_global_qglobal.cpp 3
<QtGlobal> also contains functions that generate messages from the
given string argument: qCritical(), qDebug(), qFatal() and
Example:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 4
+ \snippet code/src_corelib_global_qglobal.cpp 4
The remaining functions are qRound() and qRound64(), which both
accept a \l qreal value as their argument returning the value
Convenience typedef for \c{unsigned char}.
*/
-/*!
- \fn qt_set_sequence_auto_mnemonic(bool on)
- \relates <QtGlobal>
-
- Enables automatic mnemonics on Mac if \a on is true; otherwise
- this feature is disabled.
-
- Note that this function is only available on Mac where mnemonics
- are disabled by default.
-
- To access to this function, use an extern declaration:
- extern void qt_set_sequence_auto_mnemonic(bool b);
-
- \sa {QShortcut#mnemonic}{QShortcut}
-*/
-
/*! \typedef ushort
\relates <QtGlobal>
Literals of this type can be created using the Q_INT64_C() macro:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 5
+ \snippet code/src_corelib_global_qglobal.cpp 5
\sa Q_INT64_C(), quint64, qlonglong
*/
Literals of this type can be created using the Q_UINT64_C()
macro:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 6
+ \snippet code/src_corelib_global_qglobal.cpp 6
\sa Q_UINT64_C(), qint64, qulonglong
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 8
+ \snippet code/src_corelib_global_qglobal.cpp 8
\sa qint64, Q_UINT64_C()
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 9
+ \snippet code/src_corelib_global_qglobal.cpp 9
\sa quint64, Q_INT64_C()
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 10
+ \snippet code/src_corelib_global_qglobal.cpp 10
*/
/*! \fn int qRound(qreal value)
Example:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 11
+ \snippet code/src_corelib_global_qglobal.cpp 11
*/
/*! \fn qint64 qRound64(qreal value)
Example:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 12
+ \snippet code/src_corelib_global_qglobal.cpp 12
*/
/*! \fn const T &qMin(const T &value1, const T &value2)
Example:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 13
+ \snippet code/src_corelib_global_qglobal.cpp 13
\sa qMax(), qBound()
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 14
+ \snippet code/src_corelib_global_qglobal.cpp 14
\sa qMin(), qBound()
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 15
+ \snippet code/src_corelib_global_qglobal.cpp 15
\sa qMin(), qMax()
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 16
+ \snippet code/src_corelib_global_qglobal.cpp 16
\sa QT_VERSION_STR, qVersion()
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 17
+ \snippet code/src_corelib_global_qglobal.cpp 17
If \c b is zero, the Q_ASSERT statement will output the following
message using the qFatal() function:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 18
+ \snippet code/src_corelib_global_qglobal.cpp 18
\sa Q_ASSERT_X(), qFatal(), {Debugging Techniques}
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 19
+ \snippet code/src_corelib_global_qglobal.cpp 19
If \c b is zero, the Q_ASSERT_X statement will output the following
message using the qFatal() function:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 20
+ \snippet code/src_corelib_global_qglobal.cpp 20
\sa Q_ASSERT(), qFatal(), {Debugging Techniques}
*/
conditions that it would not otherwise know about. However, there is no
guarantee that the compiler will actually use those hints.
- This macro could be considered a "lighter" version of \ref Q_ASSERT. While
+ This macro could be considered a "lighter" version of \l{Q_ASSERT}. While
Q_ASSERT will abort the program's execution if the condition is false,
Q_ASSUME will tell the compiler not to generate code for those conditions.
Therefore, it is important that the assumptions always hold, otherwise
This macro is useful to mark impossible conditions. For example, given the
following enum:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp qunreachable-enum
+ \snippet code/src_corelib_global_qglobal.cpp qunreachable-enum
One can write a switch table like so:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp qunreachable-switch
+ \snippet code/src_corelib_global_qglobal.cpp qunreachable-switch
The advantage of inserting Q_UNREACHABLE() at that point is that the
compiler is told not to generate code for a shape variable containing that
Example:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 21
+ \snippet code/src_corelib_global_qglobal.cpp 21
\sa qWarning(), {Debugging Techniques}
*/
Q_FUNC_INFO can be conveniently used with qDebug(). For example, this function:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 22
+ \snippet code/src_corelib_global_qglobal.cpp 22
when instantiated with the integer type, will with the GCC compiler produce:
Example:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 31
+ \snippet code/src_corelib_global_qglobal.cpp 31
It is equivalent to \c{for (;;)}.
If you're worried about namespace pollution, you can disable this
macro by adding the following line to your \c .pro file:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 32
+ \snippet code/src_corelib_global_qglobal.cpp 32
\sa Q_FOREVER
*/
If you're worried about namespace pollution, you can disable this
macro by adding the following line to your \c .pro file:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 33
+ \snippet code/src_corelib_global_qglobal.cpp 33
\sa Q_FOREACH()
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 34
+ \snippet code/src_corelib_global_qglobal.cpp 34
The macro QT_TR_NOOP_UTF8() is identical except that it tells lupdate
that the source string is encoded in UTF-8. Corresponding variants
Example:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 35
+ \snippet code/src_corelib_global_qglobal.cpp 35
\sa QT_TR_NOOP(), QT_TRANSLATE_NOOP3(), {Internationalization with Qt}
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 36
+ \snippet code/src_corelib_global_qglobal.cpp 36
\sa QT_TR_NOOP(), QT_TRANSLATE_NOOP(), {Internationalization with Qt}
*/
or
- \tt{\begincomment% <C string> \endcomment}
+ \tt{\\begincomment% <C string> \\endcomment}
Example:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp qttrid
+ \snippet code/src_corelib_global_qglobal.cpp qttrid
Creating QM files suitable for use with this function requires passing
the \c -idbased option to the \c lrelease tool.
Example:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp qttrid_noop
+ \snippet code/src_corelib_global_qglobal.cpp qttrid_noop
\sa qtTrId(), {Internationalization with Qt}
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp qlikely
+ \snippet code/src_corelib_global_qglobal.cpp qlikely
\sa Q_UNLIKELY()
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp qunlikely
+ \snippet code/src_corelib_global_qglobal.cpp qunlikely
\sa Q_LIKELY()
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 37
+ \snippet code/src_corelib_global_qglobal.cpp 37
\sa qDebug(), qWarning(), qCritical(), qFatal()
Example of a "primitive" type:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 38
+ \snippet code/src_corelib_global_qglobal.cpp 38
An example of a non-POD "primitive" type is QUuid: Even though
QUuid has constructors (and therefore isn't POD), every bit
Example of a movable type:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 39
+ \snippet code/src_corelib_global_qglobal.cpp 39
*/
/*!
Use this macro as in the following examples.
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 40
+ \snippet code/src_corelib_global_qglobal.cpp 40
\sa Q_BIG_ENDIAN, Q_LITTLE_ENDIAN
*/
lowest address. The other bytes follow in increasing order of
significance.
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 41
+ \snippet code/src_corelib_global_qglobal.cpp 41
\sa Q_BYTE_ORDER, Q_BIG_ENDIAN
*/
lowest address. The other bytes follow in decreasing order of
significance.
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 42
+ \snippet code/src_corelib_global_qglobal.cpp 42
\sa Q_BYTE_ORDER, Q_LITTLE_ENDIAN
*/
This macro expands to
- \snippet snippets/code/src_corelib_global_qglobal.cpp begin namespace macro
+ \snippet code/src_corelib_global_qglobal.cpp begin namespace macro
if \c QT_NAMESPACE is defined and nothing otherwise. If should always
appear in the file-level scope and be followed by \c QT_END_NAMESPACE
This macro expands to
- \snippet snippets/code/src_corelib_global_qglobal.cpp end namespace macro
+ \snippet code/src_corelib_global_qglobal.cpp end namespace macro
if \c QT_NAMESPACE is defined and nothing otherwise. It is used to cancel
the effect of \c QT_BEGIN_NAMESPACE.
Note that comparing values where either \a p1 or \a p2 is 0.0 will not work.
The solution to this is to compare against values greater than or equal to 1.0.
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 46
+ \snippet code/src_corelib_global_qglobal.cpp 46
The two numbers are compared in a relative way, where the
exactness is stronger the smaller the numbers are.
Example:
- \snippet doc/src/snippets/code/src_gui_dialogs_qmessagebox.cpp 4
+ \snippet code/src_gui_dialogs_qmessagebox.cpp 4
*/
/*!
Example:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 24
+ \snippet code/src_corelib_global_qglobal.cpp 24
If you include \c <QtDebug>, a more convenient syntax is also
available:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 25
+ \snippet code/src_corelib_global_qglobal.cpp 25
With this syntax, the function returns a QDebug object that is
configured to use the QtDebugMsg message type. It automatically
string.
Example:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 26
+ \snippet code/src_corelib_global_qglobal.cpp 26
If you include <QtDebug>, a more convenient syntax is
also available:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 27
+ \snippet code/src_corelib_global_qglobal.cpp 27
This syntax inserts a space between each item, and
appends a newline at the end.
string.
Example:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 28
+ \snippet code/src_corelib_global_qglobal.cpp 28
If you include <QtDebug>, a more convenient syntax is
also available:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 29
+ \snippet code/src_corelib_global_qglobal.cpp 29
A space is inserted between the items, and a newline is
appended at the end.
similar to the C printf() function.
Example:
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 30
+ \snippet code/src_corelib_global_qglobal.cpp 30
To suppress the output at runtime, install your own message handler
with qInstallMessageHandler().
{Debugging Techniques}
*/
-/*!
- \typedef QtMsgHandler
- \relates <QtGlobal>
- \deprecated
-
- This is a typedef for a pointer to a function with the following
- signature:
-
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 7
-
- This typedef is deprecated, you should use QMessageHandler instead.
- \sa QtMsgType, QMessageHandler, qInstallMsgHandler(), qInstallMessageHandler()
-*/
-
-/*!
- \typedef QMessageHandler
- \relates <QtGlobal>
- \since 5.0
-
- This is a typedef for a pointer to a function with the following
- signature:
-
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 49
-
- \sa QtMsgType, qInstallMessageHandler()
-*/
-
-/*!
- \fn QMessageHandler qInstallMessageHandler(QMessageHandler handler)
- \relates <QtGlobal>
- \since 5.0
-
- Installs a Qt message \a handler which has been defined
- previously. Returns a pointer to the previous message handler
- (which may be 0).
-
- The message handler is a function that prints out debug messages,
- warnings, critical and fatal error messages. The Qt library (debug
- mode) contains hundreds of warning messages that are printed
- when internal errors (usually invalid function arguments)
- occur. Qt built in release mode also contains such warnings unless
- QT_NO_WARNING_OUTPUT and/or QT_NO_DEBUG_OUTPUT have been set during
- compilation. If you implement your own message handler, you get total
- control of these messages.
-
- The default message handler prints the message to the standard
- output under X11 or to the debugger under Windows. If it is a
- fatal message, the application aborts immediately.
-
- Only one message handler can be defined, since this is usually
- done on an application-wide basis to control debug output.
-
- To restore the message handler, call \c qInstallMessageHandler(0).
-
- Example:
-
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 23
-
- \sa QMessageHandler, QtMsgType, qDebug(), qWarning(), qCritical(), qFatal(),
- {Debugging Techniques}
-*/
-
-/*!
- \fn QtMsgHandler qInstallMsgHandler(QtMsgHandler handler)
- \relates <QtGlobal>
- \deprecated
-
- Installs a Qt message \a handler which has been defined
- previously. This method is deprecated, use qInstallMessageHandler
- instead.
- \sa QtMsgHandler, qInstallMessageHandler
-*/
-
QT_END_NAMESPACE
One example of direct use is to forward errors that stem from a scripting language, e.g. QML:
- \snippet doc/src/snippets/code/qlogging/qloggingsnippet.cpp 1
+ \snippet code/qlogging/qlogging.cpp 1
\sa QMessageLogContext, qDebug(), qWarning(), qCritical(), qFatal()
*/
}
#undef qDebug
-
void QMessageLogger::debug(const char *msg, ...)
{
va_list ap;
#endif
#undef qCritical
-
void QMessageLogger::critical(const char *msg, ...)
{
va_list ap;
#endif
#undef qFatal
-
void QMessageLogger::fatal(const char *msg, ...)
{
va_list ap;
const char *str);
#endif
+/*!
+ \typedef QtMsgHandler
+ \relates <QtGlobal>
+ \deprecated
+
+ This is a typedef for a pointer to a function with the following
+ signature:
+
+ \snippet code/src_corelib_global_qglobal.cpp 7
+
+ This typedef is deprecated, you should use QMessageHandler instead.
+ \sa QtMsgType, QMessageHandler, qInstallMsgHandler(), qInstallMessageHandler()
+*/
+
+/*!
+ \fn QtMsgHandler qInstallMsgHandler(QtMsgHandler handler)
+ \relates <QtGlobal>
+ \deprecated
+
+ Installs a Qt message \a handler which has been defined
+ previously. This method is deprecated, use qInstallMessageHandler
+ instead.
+ \sa QtMsgHandler, qInstallMessageHandler
+*/
+
+/*!
+ \typedef QMessageHandler
+ \relates <QtGlobal>
+ \since 5.0
+
+ This is a typedef for a pointer to a function with the following
+ signature:
+
+ \snippet code/src_corelib_global_qglobal.cpp 49
+
+ \sa QtMsgType, qInstallMessageHandler()
+*/
+
+/*!
+ \fn QMessageHandler qInstallMessageHandler(QMessageHandler handler)
+ \relates <QtGlobal>
+ \since 5.0
+
+ Installs a Qt message \a handler which has been defined
+ previously. Returns a pointer to the previous message handler
+ (which may be 0).
+
+ The message handler is a function that prints out debug messages,
+ warnings, critical and fatal error messages. The Qt library (debug
+ mode) contains hundreds of warning messages that are printed
+ when internal errors (usually invalid function arguments)
+ occur. Qt built in release mode also contains such warnings unless
+ QT_NO_WARNING_OUTPUT and/or QT_NO_DEBUG_OUTPUT have been set during
+ compilation. If you implement your own message handler, you get total
+ control of these messages.
+
+ The default message handler prints the message to the standard
+ output under X11 or to the debugger under Windows. If it is a
+ fatal message, the application aborts immediately.
+
+ Only one message handler can be defined, since this is usually
+ done on an application-wide basis to control debug output.
+
+ To restore the message handler, call \c qInstallMessageHandler(0).
+
+ Example:
+
+ \snippet code/src_corelib_global_qglobal.cpp 23
+
+ \sa qDebug(), qWarning(), qCritical(), qFatal(), QtMsgType,
+ {Debugging Techniques}
+*/
+
QMessageHandler qInstallMessageHandler(QMessageHandler h)
{
if (!messageHandler)
actual 'Mouse Buttons', the device must be re-configured (using
the vendor's configuration tool).
- \sa KeyboardModifier Modifier
+ \sa KeyboardModifier, Modifier
*/
/*!
\note On Windows Keyboards, Qt::MetaModifier and Qt::Key_Meta are mapped
to the Windows key.
- \sa MouseButton Modifier
+ \sa MouseButton, Modifier
*/
/*!
point, not as a Qt Key.
\omitvalue MODIFIER_MASK
- \sa KeyboardModifier MouseButton
+ \sa KeyboardModifier, MouseButton
*/
/*!
arguments to store them in an event behind the scenes. If you try
to use a queued connection and get the error message:
- \snippet doc/src/snippets/code/doc_src_qnamespace.qdoc 0
+ \snippet code/doc_src_qnamespace.qdoc 0
Call qRegisterMetaType() to register the data type before you
establish the connection.
system supports it, a tool window can be decorated
with a somewhat lighter frame. It can also be
combined with Qt::FramelessWindowHint.
- \br
- \br
On Mac OS X, tool windows correspond to the
\l{http://developer.apple.com/documentation/Carbon/Conceptual/HandlingWindowsControls/hitb-wind_cont_concept/chapter_2_section_2.html}{Floating}
class of windows. This means that the window lives on a
should be taken over by the target application,
i.e., the source application should not delete
the data.
- \br
On X11 this value is used to do a move.
- \br
TargetMoveAction is not used on the Mac.
*/
for other strings (e.g.,
"\l{http://qt.nokia.com/doc/qq/qq09-mac-deployment.html}{Deploying Applications on Ma...}").
- \sa QAbstractItemView::textElideMode, QFontMetrics::elidedText(), AlignmentFlag QTabBar::elideMode
+ \sa QAbstractItemView::textElideMode, QFontMetrics::elidedText(), AlignmentFlag, QTabBar::elideMode
*/
/*!
INT_MIN, inclusive. For example, you can define custom priorities
as being relative to each other:
- \snippet doc/src/snippets/code/doc_src_qnamespace.cpp 1
+ \snippet code/doc_src_qnamespace.cpp 1
\sa QCoreApplication::postEvent()
*/
For example:
- \snippet doc/src/snippets/code/src_corelib_io_qabstractfileengine.cpp 0
+ \snippet code/src_corelib_io_qabstractfileengine.cpp 0
When the handler is destroyed, it is automatically removed from Qt.
Example:
- \snippet doc/src/snippets/code/src_corelib_io_qabstractfileengine.cpp 1
+ \snippet code/src_corelib_io_qabstractfileengine.cpp 1
\sa QAbstractFileEngine::create()
*/
This virtual function must be reimplemented by all subclasses.
- \sa setFileName() rmdir()
+ \sa setFileName(), rmdir()
*/
bool QAbstractFileEngine::remove()
{
This virtual function must be reimplemented by all subclasses.
- \sa setFileName() rmdir() isRelativePath()
+ \sa setFileName(), rmdir(), isRelativePath()
*/
bool QAbstractFileEngine::mkdir(const QString &dirName, bool createParentDirectories) const
{
This virtual function must be reimplemented by all subclasses.
- \sa setFileName() remove() mkdir() isRelativePath()
+ \sa setFileName(), remove(), mkdir(), isRelativePath()
*/
bool QAbstractFileEngine::rmdir(const QString &dirName, bool recurseParentDirectories) const
{
This virtual function must be reimplemented by all subclasses.
- \sa owner() setFileName(), FileOwner
+ \sa owner(), setFileName(), FileOwner
*/
uint QAbstractFileEngine::ownerId(FileOwner owner) const
{
This virtual function must be reimplemented by all subclasses.
- \sa ownerId() setFileName(), FileOwner
+ \sa ownerId(), setFileName(), FileOwner
*/
QString QAbstractFileEngine::owner(FileOwner owner) const
{
Example:
- \snippet doc/src/snippets/code/src_corelib_io_qabstractfileengine.cpp 2
+ \snippet code/src_corelib_io_qabstractfileengine.cpp 2
QAbstractFileEngineIterator is associated with a path, name filters, and
entry filters. The path is the directory that the iterator lists entries
Here is an example of how to implement an iterator that returns each of
three fixed entries in sequence.
- \snippet doc/src/snippets/code/src_corelib_io_qabstractfileengine.cpp 3
+ \snippet code/src_corelib_io_qabstractfileengine.cpp 3
Note: QAbstractFileEngineIterator does not deal with QDir::IteratorFlags;
it simply returns entries for a single directory.
}
/*!
- This function reads one line, terminated by a '\n' character, from the
+ This function reads one line, terminated by a '\\n' character, from the
file info \a data. At most \a maxlen characters will be read. The
end-of-line character is included.
*/
interface. The QByteArray is treated just as a standard random-accessed
file. Example:
- \snippet doc/src/snippets/buffer/buffer.cpp 0
+ \snippet buffer/buffer.cpp 0
By default, an internal QByteArray buffer is created for you when
you create a QBuffer. You can access this buffer directly by
The following code snippet shows how to write data to a
QByteArray using QDataStream and QBuffer:
- \snippet doc/src/snippets/buffer/buffer.cpp 1
+ \snippet buffer/buffer.cpp 1
Effectively, we convert the application's QPalette into a byte
array. Here's how to read the data from the QByteArray:
- \snippet doc/src/snippets/buffer/buffer.cpp 2
+ \snippet buffer/buffer.cpp 2
QTextStream and QDataStream also provide convenience constructors
that take a QByteArray and that create a QBuffer behind the
Example:
- \snippet doc/src/snippets/buffer/buffer.cpp 3
+ \snippet buffer/buffer.cpp 3
\sa open(), setBuffer(), setData()
*/
Example:
- \snippet doc/src/snippets/buffer/buffer.cpp 4
+ \snippet buffer/buffer.cpp 4
If \a byteArray is 0, the buffer creates its own internal
QByteArray to work on. This byte array is initially empty.
Example (write binary data to a stream):
- \snippet doc/src/snippets/code/src_corelib_io_qdatastream.cpp 0
+ \snippet code/src_corelib_io_qdatastream.cpp 0
Example (read binary data from a stream):
- \snippet doc/src/snippets/code/src_corelib_io_qdatastream.cpp 1
+ \snippet code/src_corelib_io_qdatastream.cpp 1
Each item written to the stream is written in a predefined binary
format that varies depending on the item's type. Supported Qt
compatibility, you can hardcode the version number in the
application:
- \snippet doc/src/snippets/code/src_corelib_io_qdatastream.cpp 2
+ \snippet code/src_corelib_io_qdatastream.cpp 2
If you are producing a new binary data format, such as a file
format for documents created by your application, you could use a
would write a brief header containing a magic string and a version
number to give yourself room for future expansion. For example:
- \snippet doc/src/snippets/code/src_corelib_io_qdatastream.cpp 3
+ \snippet code/src_corelib_io_qdatastream.cpp 3
Then read it in with:
- \snippet doc/src/snippets/code/src_corelib_io_qdatastream.cpp 4
+ \snippet code/src_corelib_io_qdatastream.cpp 4
You can select which byte order to use when serializing data. The
default setting is big endian (MSB first). Changing it to little
defined, check the \b {Related Non-Members} section of the
class's documentation page.
- \sa QTextStream QVariant
+ \sa QTextStream, QVariant
*/
/*!
\since 4.6
- \sa FloatingPointPrecision setFloatingPointPrecision()
+ \sa FloatingPointPrecision, setFloatingPointPrecision()
*/
QDataStream::FloatingPointPrecision QDataStream::floatingPointPrecision() const
{
/*!
Returns the status of the data stream.
- \sa Status setStatus() resetStatus()
+ \sa Status, setStatus(), resetStatus()
*/
QDataStream::Status QDataStream::status() const
/*!
Resets the status of the data stream.
- \sa Status status() setStatus()
+ \sa Status, status(), setStatus()
*/
void QDataStream::resetStatus()
{
Subsequent calls to setStatus() are ignored until resetStatus()
is called.
- \sa Status status() resetStatus()
+ \sa Status, status(), resetStatus()
*/
void QDataStream::setStatus(Status status)
{
The \l Version enum provides symbolic constants for the different
versions of Qt. For example:
- \snippet doc/src/snippets/code/src_corelib_io_qdatastream.cpp 5
+ \snippet code/src_corelib_io_qdatastream.cpp 5
\sa version(), Version
*/
/*!
\overload
- Reads the '\0'-terminated string \a s from the stream and returns
+ Reads the '\\0'-terminated string \a s from the stream and returns
a reference to the stream.
Space for the string is allocated using \c new -- the caller must
/*!
\overload
- Writes the '\0'-terminated string \a s to the stream and returns a
+ Writes the '\\0'-terminated string \a s to the stream and returns a
reference to the stream.
The string is serialized using writeBytes().
In the common case, it is useful to call the qDebug() function to obtain a
default QDebug object to use for writing debugging information.
- \snippet doc/src/snippets/qdebug/qdebugsnippet.cpp 1
+ \snippet qdebug/qdebugsnippet.cpp 1
This constructs a QDebug object using the constructor that accepts a QtMsgType
value of QtDebugMsg. Similarly, the qWarning(), qCritical() and qFatal()
most Qt value types. To add support for custom types, you need to implement a
streaming operator, as in the following example:
- \snippet doc/src/snippets/qdebug/qdebugsnippet.cpp 0
+ \snippet qdebug/qdebugsnippet.cpp 0
This is described in the \l{Debugging Techniques} and
\l{Creating Custom Qt Types#Making the Type Printable}{Creating Custom Qt Types}
/*!
\fn QDebug &QDebug::operator<<(const char *s)
- Writes the '\0'-terminated string, \a s, to the stream and returns a
+ Writes the '\\0'-terminated string, \a s, to the stream and returns a
reference to the stream.
*/
Examples of absolute paths:
- \snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 0
+ \snippet code/src_corelib_io_qdir.cpp 0
On Windows, the second example above will be translated to
\c{C:\Documents and Settings} when used to access files.
Examples of relative paths:
- \snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 1
+ \snippet code/src_corelib_io_qdir.cpp 1
You can use the isRelative() or isAbsolute() functions to check if
a QDir is using a relative or an absolute file path. Call
the location of the directory. However, it can also return "." if
the QDir represents the current directory.
- \snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 2
+ \snippet code/src_corelib_io_qdir.cpp 2
The path for a directory can also be changed with the cd() and cdUp()
functions, both of which operate like familiar shell commands.
file or directory. Neither of these functions checks for the
existence of files or directory; they only construct paths.
- \snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 3
+ \snippet code/src_corelib_io_qdir.cpp 3
Files can be removed by using the remove() function. Directories
cannot be removed in the same way as files; use rmdir() to remove
Check if a directory exists:
- \snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 4
+ \snippet code/src_corelib_io_qdir.cpp 4
(We could also use the static convenience function
QFile::exists().)
Traversing directories and reading a file:
- \snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 5
+ \snippet code/src_corelib_io_qdir.cpp 5
A program that lists all the files in the current directory
(excluding symbolic links), sorted by size, smallest first:
- \snippet doc/src/snippets/qdir-listfiles/main.cpp 0
+ \snippet qdir-listfiles/main.cpp 0
\sa QFileInfo, QFile, QFileDialog, QApplication::applicationDirPath(), {Find Files Example}
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 6
+ \snippet code/src_corelib_io_qdir.cpp 6
\sa path(), absolutePath(), exists(), cleanPath(), dirName(),
absoluteFilePath()
be relative. Redundant multiple separators or "." and ".."
directories in \a fileName are not removed (see cleanPath()).
- \sa dirName() absoluteFilePath(), isRelative(), canonicalPath()
+ \sa dirName(), absoluteFilePath(), isRelative(), canonicalPath()
*/
QString QDir::filePath(const QString &fileName) const
{
exists(). Redundant multiple separators or "." and ".."
directories in \a fileName are not removed (see cleanPath()).
- \sa relativeFilePath() filePath() canonicalPath()
+ \sa relativeFilePath(), filePath(), canonicalPath()
*/
QString QDir::absoluteFilePath(const QString &fileName) const
{
/*!
Returns the path to \a fileName relative to the directory.
- \snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 7
+ \snippet code/src_corelib_io_qdir.cpp 7
- \sa absoluteFilePath() filePath() canonicalPath()
+ \sa absoluteFilePath(), filePath(), canonicalPath()
*/
QString QDir::relativeFilePath(const QString &fileName) const
{
to ensure that only files with extensions typically used for C++
source files are listed:
- \snippet doc/src/snippets/qdir-namefilters/main.cpp 0
+ \snippet qdir-namefilters/main.cpp 0
\sa nameFilters(), setFilter()
*/
Qt uses this search path to locate files with a known prefix. The search
path entries are tested in order, starting with the first entry.
- \snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 8
+ \snippet code/src_corelib_io_qdir.cpp 8
File name prefix must be at least 2 characters long to avoid conflicts with
Windows drive letters.
/*!
Returns the value set by setSorting()
- \sa setSorting() SortFlag
+ \sa setSorting(), SortFlag
*/
QDir::SortFlags QDir::sorting() const
{
The \a sort is specified by OR-ing values from the enum
\l{QDir::SortFlag}.
- \sa sorting() SortFlag
+ \sa sorting(), SortFlag
*/
void QDir::setSorting(SortFlags sort)
{
this function returns false. If you want to test for this use
canonicalPath(), e.g.
- \snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 9
+ \snippet code/src_corelib_io_qdir.cpp 9
\sa root(), rootPath()
*/
Returns true if the directory's path is absolute; otherwise
returns false. See isAbsolutePath().
- \sa isRelative() makeAbsolute() cleanPath()
+ \sa isRelative(), makeAbsolute(), cleanPath()
*/
/*!
Returns true if \a path is absolute; returns false if it is
relative.
- \sa isAbsolute() isRelativePath() makeAbsolute() cleanPath()
+ \sa isAbsolute(), isRelativePath(), makeAbsolute(), cleanPath()
*/
/*!
false. (Under Unix a path is relative if it does not start with a
"/").
- \sa makeAbsolute() isAbsolute() isAbsolutePath() cleanPath()
+ \sa makeAbsolute(), isAbsolute(), isAbsolutePath(), cleanPath()
*/
bool QDir::isRelative() const
{
absolute nothing happens. Returns true if the conversion
succeeded; otherwise returns false.
- \sa isAbsolute() isAbsolutePath() isRelative() cleanPath()
+ \sa isAbsolute(), isAbsolutePath(), isRelative(), cleanPath()
*/
bool QDir::makeAbsolute()
{
Example:
- \snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 10
+ \snippet code/src_corelib_io_qdir.cpp 10
*/
bool QDir::operator==(const QDir &dir) const
{
Example:
- \snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 11
+ \snippet code/src_corelib_io_qdir.cpp 11
*/
/*!
Under Windows this function will return the directory of the
current user's profile. Typically, this is:
- \snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 12
+ \snippet code/src_corelib_io_qdir.cpp 12
Use the toNativeSeparators() function to convert the separators to
the ones that are appropriate for the underlying operating system.
patterns in the list of \a filters; otherwise returns false. The
matching is case insensitive.
- \sa {QRegExp wildcard matching}, QRegExp::exactMatch() entryList() entryInfoList()
+ \sa {QRegExp wildcard matching}, QRegExp::exactMatch(), entryList(), entryInfoList()
*/
bool QDir::match(const QStringList &filters, const QString &fileName)
{
contain multiple patterns separated by spaces or semicolons.
The matching is case insensitive.
- \sa {QRegExp wildcard matching}, QRegExp::exactMatch() entryList() entryInfoList()
+ \sa {QRegExp wildcard matching}, QRegExp::exactMatch(), entryList(), entryInfoList()
*/
bool QDir::match(const QString &filter, const QString &fileName)
{
For example, "./local" becomes "local", "local/../bin" becomes
"bin" and "/local/usr/../bin" becomes "/local/bin".
- \sa absolutePath() canonicalPath()
+ \sa absolutePath(), canonicalPath()
*/
QString QDir::cleanPath(const QString &path)
{
Returns true if \a path is relative; returns false if it is
absolute.
- \sa isRelative() isAbsolutePath() makeAbsolute()
+ \sa isRelative(), isAbsolutePath(), makeAbsolute()
*/
bool QDir::isRelativePath(const QString &path)
{
initialized at startup by adding this line to your \c main()
function:
- \snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 13
+ \snippet code/src_corelib_io_qdir.cpp 13
If the file name contains characters that cannot be part of a valid C++ function name
(such as '-'), they have to be replaced by the underscore character ('_').
main(). If that is not possible, the following workaround can be used
to init the resource \c myapp from the function \c{MyNamespace::myFunction}:
- \snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 14
+ \snippet code/src_corelib_io_qdir.cpp 14
\sa Q_CLEANUP_RESOURCE(), {The Qt Resource System}
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 15
+ \snippet code/src_corelib_io_qdir.cpp 15
\sa Q_INIT_RESOURCE(), {The Qt Resource System}
*/
argument. After construction, the iterator is located before the first
directory entry. Here's how to iterate over all the entries sequentially:
- \snippet doc/src/snippets/code/src_corelib_io_qdiriterator.cpp 0
+ \snippet code/src_corelib_io_qdiriterator.cpp 0
The next() function returns the path to the next directory entry and
advances the iterator. You can also call filePath() to get the current
The following example reads a text file line by line:
- \snippet doc/src/snippets/file/file.cpp 0
+ \snippet file/file.cpp 0
The QIODevice::Text flag passed to open() tells Qt to convert
Windows-style line terminators ("\\r\\n") into C++-style
The next example uses QTextStream to read a text file
line by line:
- \snippet doc/src/snippets/file/file.cpp 1
+ \snippet file/file.cpp 1
QTextStream takes care of converting the 8-bit data stored on
disk into a 16-bit Unicode QString. By default, it assumes that
take a QTextStream on the left and various data types (including
QString) on the right:
- \snippet doc/src/snippets/file/file.cpp 2
+ \snippet file/file.cpp 2
QDataStream is similar, in that you can use operator<<() to write
data and operator>>() to read it back. See the class
read() or readLine() repeatedly until no more data can be read. The next
example uses QTextStream to read \c /proc/modules line by line:
- \snippet doc/src/snippets/file/file.cpp 3
+ \snippet file/file.cpp 3
\section1 Signals
\e{at the time of the open()} call.
Example:
- \snippet doc/src/snippets/code/src_corelib_io_qfile.cpp 0
+ \snippet code/src_corelib_io_qfile.cpp 0
Note that the directory separator "/" works for all operating
systems supported by Qt.
file names that the user chooses. File names hard-coded into the
application should only use 7-bit ASCII filename characters.
- \sa decodeName() setEncodingFunction()
+ \sa decodeName(), setEncodingFunction()
*/
QByteArray
This is a typedef for a pointer to a function with the following
signature:
- \snippet doc/src/snippets/code/src_corelib_io_qfile.cpp 1
+ \snippet code/src_corelib_io_qfile.cpp 1
\sa setEncodingFunction(), encodeName()
*/
This is a typedef for a pointer to a function with the following
signature:
- \snippet doc/src/snippets/code/src_corelib_io_qfile.cpp 2
+ \snippet code/src_corelib_io_qfile.cpp 2
\sa setDecodingFunction()
*/
This name may not represent an existing file; it is only a string.
QFile::exists() returns true if the symlink points to an existing file.
- \sa fileName() setFileName()
+ \sa fileName(), setFileName()
*/
/*!
Returns true if successful; otherwise returns false.
Example:
- \snippet doc/src/snippets/code/src_corelib_io_qfile.cpp 3
+ \snippet code/src_corelib_io_qfile.cpp 3
When a QFile is opened using this function, behaviour of close() is
controlled by the AutoCloseHandle flag.
stdin, stdout and stderr streams at the console. To do this, add the
following declaration to your application's project file:
- \snippet doc/src/snippets/code/src_corelib_io_qfile.cpp 4
+ \snippet code/src_corelib_io_qfile.cpp 4
*/
bool QFile::open(FILE *fh, OpenMode mode, FileHandleFlags handleFlags)
{
transparently; similarly, opening a symlink using QFile
effectively opens the link's target. For example:
- \snippet doc/src/snippets/code/src_corelib_io_qfileinfo.cpp 0
+ \snippet code/src_corelib_io_qfileinfo.cpp 0
On Windows, symlinks (shortcuts) are \c .lnk files. The reported
size() is that of the symlink (not the link's target), and
opening a symlink using QFile opens the \c .lnk file. For
example:
- \snippet doc/src/snippets/code/src_corelib_io_qfileinfo.cpp 1
+ \snippet code/src_corelib_io_qfileinfo.cpp 1
Elements of the file's name can be extracted with path() and
fileName(). The fileName()'s parts can be extracted with
path relative to the current directory.
Example:
- \snippet doc/src/snippets/code/src_corelib_io_qfileinfo.cpp 2
+ \snippet code/src_corelib_io_qfileinfo.cpp 2
\sa isRelative(), QDir::setCurrent(), QDir::isRelativePath()
*/
QFileInfo will uppercase drive letters. Note that QDir does not do
this. The code snippet below shows this.
- \snippet doc/src/snippets/code/src_corelib_io_qfileinfo.cpp newstuff
+ \snippet code/src_corelib_io_qfileinfo.cpp newstuff
This function returns the same as filePath(), unless isRelative()
is true. In contrast to canonicalFilePath(), symbolic links or
Returns the name of the file, excluding the path.
Example:
- \snippet doc/src/snippets/code/src_corelib_io_qfileinfo.cpp 3
+ \snippet code/src_corelib_io_qfileinfo.cpp 3
Note that, if this QFileInfo object is given a path ending in a
slash, the name of the file is considered empty.
path isBundle(). On all other platforms an empty QString is returned.
Example:
- \snippet doc/src/snippets/code/src_corelib_io_qfileinfo.cpp 4
+ \snippet code/src_corelib_io_qfileinfo.cpp 4
\sa isBundle(), filePath(), baseName(), extension()
*/
not including) the \e first '.' character.
Example:
- \snippet doc/src/snippets/code/src_corelib_io_qfileinfo.cpp 5
+ \snippet code/src_corelib_io_qfileinfo.cpp 5
The base name of a file is computed equally on all platforms, independent
to (but not including) the \e last '.' character.
Example:
- \snippet doc/src/snippets/code/src_corelib_io_qfileinfo.cpp 6
+ \snippet code/src_corelib_io_qfileinfo.cpp 6
\sa fileName(), suffix(), completeSuffix(), baseName()
*/
(but not including) the first '.'.
Example:
- \snippet doc/src/snippets/code/src_corelib_io_qfileinfo.cpp 7
+ \snippet code/src_corelib_io_qfileinfo.cpp 7
\sa fileName(), suffix(), baseName(), completeBaseName()
*/
including) the last '.'.
Example:
- \snippet doc/src/snippets/code/src_corelib_io_qfileinfo.cpp 8
+ \snippet code/src_corelib_io_qfileinfo.cpp 8
The suffix of a file is computed equally on all platforms, independent of
file naming conventions (e.g., ".bashrc" on Unix has an empty base name,
For each of the following, dir() returns a QDir for
\c{"~/examples/191697"}.
- \snippet doc/src/snippets/fileinfo/main.cpp 0
+ \snippet fileinfo/main.cpp 0
For each of the following, dir() returns a QDir for
\c{"."}.
- \snippet doc/src/snippets/fileinfo/main.cpp 1
+ \snippet fileinfo/main.cpp 1
\sa absolutePath(), filePath(), fileName(), isRelative(), absoluteDir()
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_io_qfileinfo.cpp 9
+ \snippet code/src_corelib_io_qfileinfo.cpp 9
\note If the symlink points to a non existing file, exists() returns
false.
always returns true.
Example:
- \snippet doc/src/snippets/code/src_corelib_io_qfileinfo.cpp 10
+ \snippet code/src_corelib_io_qfileinfo.cpp 10
\sa isReadable(), isWritable(), isExecutable()
*/
If neither creation time nor "last status change" time are not
available, returns the same as lastModified().
- \sa lastModified() lastRead()
+ \sa lastModified(), lastRead()
*/
QDateTime QFileInfo::created() const
{
/*!
Returns the date and time when the file was last modified.
- \sa created() lastRead()
+ \sa created(), lastRead()
*/
QDateTime QFileInfo::lastModified() const
{
On platforms where this information is not available, returns the
same as lastModified().
- \sa created() lastModified()
+ \sa created(), lastModified()
*/
QDateTime QFileInfo::lastRead() const
{
Calling these functions from the main, GUI thread, may cause your
user interface to freeze. Example:
- \snippet doc/src/snippets/code/src_corelib_io_qiodevice.cpp 0
+ \snippet code/src_corelib_io_qiodevice.cpp 0
By subclassing QIODevice, you can provide the same interface to
your own I/O devices. Subclasses of QIODevice are only required to
subclassing QIODevice, remember to bypass any buffer you may use
when the device is open in Unbuffered mode.
- \sa QBuffer QFile QTcpSocket
+ \sa QBuffer, QFile, QTcpSocket
*/
/*!
\value Truncate If possible, the device is truncated before it is opened.
All earlier contents of the device are lost.
\value Text When reading, the end-of-line terminators are
- translated to '\n'. When writing, the end-of-line
+ translated to '\\n'. When writing, the end-of-line
terminators are translated to the local encoding, for
- example '\r\n' for Win32.
+ example '\\r\\n' for Win32.
\value Unbuffered Any buffer in the device is bypassed.
Certain flags, such as \c Unbuffered and \c Truncate, are
function to set the open mode if the flags change after the device
has been opened.
- \sa openMode() OpenMode
+ \sa openMode(), OpenMode
*/
void QIODevice::setOpenMode(OpenMode openMode)
{
default, this function returns false if openMode() returns
\c NotOpen.
- \sa openMode() OpenMode
+ \sa openMode(), OpenMode
*/
bool QIODevice::isOpen() const
{
This is a convenience function which checks if the OpenMode of the
device contains the ReadOnly flag.
- \sa openMode() OpenMode
+ \sa openMode(), OpenMode
*/
bool QIODevice::isReadable() const
{
This is a convenience function which checks if the OpenMode of the
device contains the WriteOnly flag.
- \sa openMode() OpenMode
+ \sa openMode(), OpenMode
*/
bool QIODevice::isWritable() const
{
otherwise returns false. This function should be called from any
reimplementations of open() or other functions that open the device.
- \sa openMode() OpenMode
+ \sa openMode(), OpenMode
*/
bool QIODevice::open(OpenMode mode)
{
First emits aboutToClose(), then closes the device and sets its
OpenMode to NotOpen. The error string is also reset.
- \sa setOpenMode() OpenMode
+ \sa setOpenMode(), OpenMode
*/
void QIODevice::close()
{
Subclasses that reimplement this function must call the base
implementation in order to include the size of QIODevices' buffer. Example:
- \snippet doc/src/snippets/code/src_corelib_io_qiodevice.cpp 1
+ \snippet code/src_corelib_io_qiodevice.cpp 1
\sa bytesToWrite(), readyRead(), isSequential()
*/
function returns -1 in those cases (that is, reading on a closed
socket or after a process has died).
- \sa readData() readLine() write()
+ \sa readData(), readLine(), write()
*/
qint64 QIODevice::read(char *data, qint64 maxSize)
{
occurs, this function returns the length of what could be read, or
-1 if nothing was read.
- A terminating '\0' byte is always appended to \a data, so \a
+ A terminating '\\0' byte is always appended to \a data, so \a
maxSize must be larger than 1.
Data is read until either of the following conditions are met:
\list
- \li The first '\n' character is read.
+ \li The first '\\n' character is read.
\li \a maxSize - 1 bytes are read.
\li The end of the device data is detected.
\endlist
For example, the following code reads a line of characters from a
file:
- \snippet doc/src/snippets/code/src_corelib_io_qiodevice.cpp 2
+ \snippet code/src_corelib_io_qiodevice.cpp 2
- The newline character ('\n') is included in the buffer. If a
+ The newline character ('\\n') is included in the buffer. If a
newline is not encountered before maxSize - 1 bytes are read, a
newline will not be inserted into the buffer. On windows newline
- characters are replaced with '\n'.
+ characters are replaced with '\\n'.
This function calls readLineData(), which is implemented using
repeated calls to getChar(). You can provide a more efficient
implementation, using getChar(). Buffered devices can improve the
performance of readLine() by reimplementing this function.
- readLine() appends a '\0' byte to \a data; readLineData() does not
+ readLine() appends a '\\0' byte to \a data; readLineData() does not
need to do this.
If you reimplement this function, be careful to return the correct
Subclasses that reimplement this function must call the base
implementation in order to include the contents of the QIODevice's buffer. Example:
- \snippet doc/src/snippets/code/src_corelib_io_qiodevice.cpp 3
+ \snippet code/src_corelib_io_qiodevice.cpp 3
\sa readyRead(), readLine()
*/
device. Returns the number of bytes that were actually written, or
-1 if an error occurred.
- \sa read() writeData()
+ \sa read(), writeData()
*/
qint64 QIODevice::write(const char *data, qint64 maxSize)
{
...
\endcode
- \sa read() writeData()
+ \sa read(), writeData()
*/
qint64 QIODevice::write(const char *data)
{
Writes the content of \a byteArray to the device. Returns the number of
bytes that were actually written, or -1 if an error occurred.
- \sa read() writeData()
+ \sa read(), writeData()
*/
/*!
Writes the character \a c to the device. Returns true on success;
otherwise returns false.
- \sa write() getChar() ungetChar()
+ \sa write(), getChar(), ungetChar()
*/
bool QIODevice::putChar(char c)
{
is 0, the character is discarded. Returns true on success;
otherwise returns false.
- \sa read() putChar() ungetChar()
+ \sa read(), putChar(), ungetChar()
*/
bool QIODevice::getChar(char *c)
{
Example:
- \snippet doc/src/snippets/code/src_corelib_io_qiodevice.cpp 4
+ \snippet code/src_corelib_io_qiodevice.cpp 4
\sa read()
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_io_qiodevice.cpp 5
+ \snippet code/src_corelib_io_qiodevice.cpp 5
This function has no way of reporting errors; returning an empty
QByteArray() can mean either that no data was currently available
all the requested information was read and therefore does not retry reading
if there was a problem.
- \sa read() readLine() writeData()
+ \sa read(), readLine(), writeData()
*/
/*!
all the information was written and therefore does not retry writing if
there was a problem.
- \sa read() write()
+ \sa read(), write()
*/
containing "-style" and "motif" as two items in the list of
arguments:
- \snippet doc/src/snippets/qprocess/qprocess-simpleexecution.cpp 0
+ \snippet qprocess/qprocess-simpleexecution.cpp 0
\dots
- \snippet doc/src/snippets/qprocess/qprocess-simpleexecution.cpp 1
- \snippet doc/src/snippets/qprocess/qprocess-simpleexecution.cpp 2
+ \snippet qprocess/qprocess-simpleexecution.cpp 1
+ \snippet qprocess/qprocess-simpleexecution.cpp 2
QProcess then enters the \l Starting state, and when the program
has started, QProcess enters the \l Running state and emits
The following example runs \c gzip to compress the string "Qt
rocks!", without an event loop:
- \snippet doc/src/snippets/process/process.cpp 0
+ \snippet process/process.cpp 0
\section1 Notes for Windows Users
error channels to the \a mode specified.
This mode will be used the next time start() is called. For example:
- \snippet doc/src/snippets/code/src_corelib_io_qprocess.cpp 0
+ \snippet code/src_corelib_io_qprocess.cpp 0
\sa processChannelMode(), ProcessChannelMode, setReadChannel()
*/
Unix and Windows. But it will not display the text data until
QProcess's write channel has been closed. Example:
- \snippet doc/src/snippets/code/src_corelib_io_qprocess.cpp 1
+ \snippet code/src_corelib_io_qprocess.cpp 1
The write channel is implicitly opened when start() is called.
destination process' standard input.
The following shell command:
- \snippet doc/src/snippets/code/src_corelib_io_qprocess.cpp 2
+ \snippet code/src_corelib_io_qprocess.cpp 2
Can be accomplished with QProcesses with the following code:
- \snippet doc/src/snippets/code/src_corelib_io_qprocess.cpp 3
+ \snippet code/src_corelib_io_qprocess.cpp 3
*/
void QProcess::setStandardOutputProcess(QProcess *destination)
{
For example, the following code adds the \c{C:\\BIN} directory to the list of
executable paths (\c{PATHS}) on Windows:
- \snippet doc/src/snippets/qprocess-environment/main.cpp 0
+ \snippet qprocess-environment/main.cpp 0
\note This function is less efficient than the setProcessEnvironment()
function.
For example, the following code adds the \c{C:\\BIN} directory to the list of
executable paths (\c{PATHS}) on Windows and sets \c{TMPDIR}:
- \snippet doc/src/snippets/qprocess-environment/main.cpp 1
+ \snippet qprocess-environment/main.cpp 1
Note how, on Windows, environment variable names are case-insensitive.
\e execve()). Reimplement this function to do last minute initialization
of the child process. Example:
- \snippet doc/src/snippets/code/src_corelib_io_qprocess.cpp 4
+ \snippet code/src_corelib_io_qprocess.cpp 4
You cannot exit the process (by calling exit(), for instance) from
this function. If you need to stop the program before it starts
program name and its arguments. The arguments are separated by one or
more spaces. For example:
- \snippet doc/src/snippets/code/src_corelib_io_qprocess.cpp 5
+ \snippet code/src_corelib_io_qprocess.cpp 5
The \a program string can also contain quotes, to ensure that arguments
containing spaces are correctly supplied to the new process. For example:
- \snippet doc/src/snippets/code/src_corelib_io_qprocess.cpp 6
+ \snippet code/src_corelib_io_qprocess.cpp 6
If the QProcess object is already running a process, a warning may be
printed at the console, and the existing process will continue running.
way to ensure that \c{"My Documents"} is used as the argument to
the \c dir executable:
- \snippet doc/src/snippets/code/src_corelib_io_qprocess.cpp 7
+ \snippet code/src_corelib_io_qprocess.cpp 7
The OpenMode is set to \a mode.
*/
Returns the environment of the calling process as a list of
key=value pairs. Example:
- \snippet doc/src/snippets/code/src_corelib_io_qprocess.cpp 8
+ \snippet code/src_corelib_io_qprocess.cpp 8
This function does not cache the system environment. Therefore, it's
possible to obtain an updated version of the environment if low-level C
Returns the current search path list. This list is consulted when
creating a relative resource.
- \sa QDir::addSearchPath() QDir::setSearchPaths()
+ \sa QDir::addSearchPath(), QDir::setSearchPaths()
*/
QStringList
company is called MySoft, you would construct the QSettings
object as follows:
- \snippet doc/src/snippets/settings/settings.cpp 0
+ \snippet settings/settings.cpp 0
QSettings objects can be created either on the stack or on
the heap (i.e. using \c new). Constructing and destroying a
QCoreApplication::setApplicationName(), and then use the default
QSettings constructor:
- \snippet doc/src/snippets/settings/settings.cpp 1
- \snippet doc/src/snippets/settings/settings.cpp 2
- \snippet doc/src/snippets/settings/settings.cpp 3
+ \snippet settings/settings.cpp 1
+ \snippet settings/settings.cpp 2
+ \snippet settings/settings.cpp 3
\dots
- \snippet doc/src/snippets/settings/settings.cpp 4
+ \snippet settings/settings.cpp 4
(Here, we also specify the organization's Internet domain. When
the Internet domain is set, it is used on Mac OS X instead of the
that stores the data associated with the key. To write a setting,
use setValue(). For example:
- \snippet doc/src/snippets/settings/settings.cpp 5
+ \snippet settings/settings.cpp 5
If there already exists a setting with the same key, the existing
value is overwritten by the new value. For efficiency, the
You can get a setting's value back using value():
- \snippet doc/src/snippets/settings/settings.cpp 6
+ \snippet settings/settings.cpp 6
If there is no setting with the specified name, QSettings
returns a null QVariant (which can be converted to the integer 0).
You can specify another default value by passing a second
argument to value():
- \snippet doc/src/snippets/settings/settings.cpp 7
+ \snippet settings/settings.cpp 7
To test whether a given key exists, call contains(). To remove
the setting associated with a key, call remove(). To obtain the
Instead, you can use the QVariant::value() or the qVariantValue()
template function. For example:
- \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 0
+ \snippet code/src_corelib_io_qsettings.cpp 0
The inverse conversion (e.g., from QColor to QVariant) is
automatic for all data types supported by QVariant, including
GUI-related types:
- \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 1
+ \snippet code/src_corelib_io_qsettings.cpp 1
Custom types registered using qRegisterMetaType() and
qRegisterMetaTypeStreamOperators() can be stored using QSettings.
You can form hierarchical keys using the '/' character as a
separator, similar to Unix file paths. For example:
- \snippet doc/src/snippets/settings/settings.cpp 8
- \snippet doc/src/snippets/settings/settings.cpp 9
- \snippet doc/src/snippets/settings/settings.cpp 10
+ \snippet settings/settings.cpp 8
+ \snippet settings/settings.cpp 9
+ \snippet settings/settings.cpp 10
If you want to save or restore many settings with the same
prefix, you can specify the prefix using beginGroup() and call
endGroup() at the end. Here's the same example again, but this
time using the group mechanism:
- \snippet doc/src/snippets/settings/settings.cpp 11
+ \snippet settings/settings.cpp 11
\codeline
- \snippet doc/src/snippets/settings/settings.cpp 12
+ \snippet settings/settings.cpp 12
If a group is set using beginGroup(), the behavior of most
functions changes consequently. Groups can be set recursively.
Let's see with an example:
- \snippet doc/src/snippets/settings/settings.cpp 13
- \snippet doc/src/snippets/settings/settings.cpp 14
+ \snippet settings/settings.cpp 13
+ \snippet settings/settings.cpp 14
The table below summarizes which QSettings objects access
which location. "\b{X}" means that the location is the main
argument to the QSettings constructor, followed by the scope, the
organization name, and the application name:
- \snippet doc/src/snippets/settings/settings.cpp 15
+ \snippet settings/settings.cpp 15
The \l{tools/settingseditor}{Settings Editor} example lets you
experiment with different settings location and with fallbacks
application. The following example illustrates how to use QSettings
to save and restore the geometry of an application's main window.
- \snippet doc/src/snippets/settings/settings.cpp 16
+ \snippet settings/settings.cpp 16
\codeline
- \snippet doc/src/snippets/settings/settings.cpp 17
+ \snippet settings/settings.cpp 17
See \l{Window Geometry} for a discussion on why it is better to
call QWidget::resize() and QWidget::move() rather than QWidget::setGeometry()
called from the main window's constructor and close event handler
as follows:
- \snippet doc/src/snippets/settings/settings.cpp 18
+ \snippet settings/settings.cpp 18
\dots
- \snippet doc/src/snippets/settings/settings.cpp 19
- \snippet doc/src/snippets/settings/settings.cpp 20
+ \snippet settings/settings.cpp 19
+ \snippet settings/settings.cpp 20
\codeline
- \snippet doc/src/snippets/settings/settings.cpp 21
+ \snippet settings/settings.cpp 21
See the \l{mainwindows/application}{Application} example for a
self-contained example that uses QSettings.
takes a file name as first argument and pass QSettings::IniFormat
as second argument. For example:
- \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 2
+ \snippet code/src_corelib_io_qsettings.cpp 2
You can then use the QSettings object to read and write settings
in the file.
On Mac OS X, you can access XML-based \c .plist files by passing
QSettings::NativeFormat as second argument. For example:
- \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 3
+ \snippet code/src_corelib_io_qsettings.cpp 3
\section2 Accessing the Windows Registry Directly
For example:
- \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 4
+ \snippet code/src_corelib_io_qsettings.cpp 4
All the registry entries that appear under the specified path can
be read or written through the QSettings object as usual (using
forward slashes instead of backslashes). For example:
- \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 5
+ \snippet code/src_corelib_io_qsettings.cpp 5
Note that the backslash character is, as mentioned, used by
QSettings to separate subkeys. As a result, you cannot read or
Its default value is accessed by using "Default" or "." in
place of a subkey:
- \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 6
+ \snippet code/src_corelib_io_qsettings.cpp 6
On other platforms than Windows, "Default" and "." would be
treated as regular subkeys.
Another solution is to use preprocessor directives, for
example:
- \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 7
+ \snippet code/src_corelib_io_qsettings.cpp 7
\li On Unix and Mac OS X systems, the advisory file locking is disabled
if NFS (or AutoFS or CacheFS) is detected to work around a bug in the
(e.g., QPoint, QRect, and QSize), Qt uses an \c{@}-based
syntax to encode the type. For example:
- \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 8
+ \snippet code/src_corelib_io_qsettings.cpp 8
To minimize compatibility issues, any \c @ that doesn't
appear at the first position in the value or that isn't
Windows applications don't escape backslashes (\c{\}) in file
paths:
- \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 9
+ \snippet code/src_corelib_io_qsettings.cpp 9
QSettings always treats backslash as a special character and
provides no API for reading or writing such entries.
organization, and with parent \a parent.
Example:
- \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 10
+ \snippet code/src_corelib_io_qsettings.cpp 10
The scope is set to QSettings::UserScope, and the format is
set to QSettings::NativeFormat (i.e. calling setDefaultFormat()
The code
- \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 11
+ \snippet code/src_corelib_io_qsettings.cpp 11
is equivalent to
- \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 12
+ \snippet code/src_corelib_io_qsettings.cpp 12
If QCoreApplication::setOrganizationName() and
QCoreApplication::setApplicationName() has not been previously
Groups are useful to avoid typing in the same setting paths over
and over. For example:
- \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 13
+ \snippet code/src_corelib_io_qsettings.cpp 13
This will set the value of three settings:
Example:
- \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 14
+ \snippet code/src_corelib_io_qsettings.cpp 14
\sa beginGroup(), group()
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 15
+ \snippet code/src_corelib_io_qsettings.cpp 15
Use beginWriteArray() to write the array in the first place.
that you want to save a variable-length list of user names and
passwords. You could then write:
- \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 16
+ \snippet code/src_corelib_io_qsettings.cpp 16
The generated keys will have the form
Example:
- \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 17
+ \snippet code/src_corelib_io_qsettings.cpp 17
If a group is set using beginGroup(), only the keys in the group
are returned, without the group prefix:
- \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 18
+ \snippet code/src_corelib_io_qsettings.cpp 18
\sa childGroups(), childKeys()
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 19
+ \snippet code/src_corelib_io_qsettings.cpp 19
If a group is set using beginGroup(), the top-level keys in that
group are returned, without the group prefix:
- \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 20
+ \snippet code/src_corelib_io_qsettings.cpp 20
You can navigate through the entire setting hierarchy using
childKeys() and childGroups() recursively.
Example:
- \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 21
+ \snippet code/src_corelib_io_qsettings.cpp 21
If a group is set using beginGroup(), the first-level keys in
that group are returned, without the group prefix.
- \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 22
+ \snippet code/src_corelib_io_qsettings.cpp 22
You can navigate through the entire setting hierarchy using
childKeys() and childGroups() recursively.
Example:
- \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 23
+ \snippet code/src_corelib_io_qsettings.cpp 23
\sa value(), remove(), contains()
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 24
+ \snippet code/src_corelib_io_qsettings.cpp 24
Be aware that if one of the fallback locations contains a setting
with the same key, that setting will be visible after calling
If \a key is an empty string, all keys in the current group() are
removed. For example:
- \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 25
+ \snippet code/src_corelib_io_qsettings.cpp 25
Note that the Windows registry and INI files use case-insensitive
keys, whereas the Carbon Preferences API on Mac OS X uses
Example:
- \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 26
+ \snippet code/src_corelib_io_qsettings.cpp 26
\sa setValue(), contains(), remove()
*/
Typedef for a pointer to a function with the following signature:
- \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 27
+ \snippet code/src_corelib_io_qsettings.cpp 27
\c ReadFunc is used in \c registerFormat() as a pointer to a function
that reads a set of key/value pairs. \c ReadFunc should read all the
Typedef for a pointer to a function with the following signature:
- \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 28
+ \snippet code/src_corelib_io_qsettings.cpp 28
\c WriteFunc is used in \c registerFormat() as a pointer to a function
that writes a set of key/value pairs. \c WriteFunc is only called once,
Example:
- \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 29
+ \snippet code/src_corelib_io_qsettings.cpp 29
\sa setPath()
*/
\value DownloadLocation Returns a directory for user's downloaded files.
- \sa writableLocation() standardLocations() displayName() locate() locateAll()
+ \sa writableLocation(), standardLocations(), displayName(), locate(), locateAll()
*/
/*!
Example:
- \snippet doc/src/snippets/code/src_corelib_io_qtemporarydir.cpp 0
+ \snippet code/src_corelib_io_qtemporarydir.cpp 0
It is very important to test that the temporary directory could be
created, using isValid(). Do not use exists(), since a default-constructed
Example:
- \snippet doc/src/snippets/code/src_corelib_io_qtemporaryfile.cpp 0
+ \snippet code/src_corelib_io_qtemporaryfile.cpp 0
Reopening a QTemporaryFile after calling close() is safe. For as long as
the QTemporaryFile object itself is not destroyed, the unique temporary
generating text, QTextStream supports formatting options for field
padding and alignment, and formatting of numbers. Example:
- \snippet doc/src/snippets/code/src_corelib_io_qtextstream.cpp 0
+ \snippet code/src_corelib_io_qtextstream.cpp 0
It's also common to use QTextStream to read console input and write
console output. QTextStream is locale aware, and will automatically decode
standard input using the correct codec. Example:
- \snippet doc/src/snippets/code/src_corelib_io_qtextstream.cpp 1
+ \snippet code/src_corelib_io_qtextstream.cpp 1
Besides using QTextStream's constructors, you can also set the
device or string QTextStream operates on by calling setDevice() or
the integer base, thereby disabling the automatic detection, by
calling setIntegerBase(). Example:
- \snippet doc/src/snippets/code/src_corelib_io_qtextstream.cpp 2
+ \snippet code/src_corelib_io_qtextstream.cpp 2
QTextStream supports many formatting options for generating text.
You can set the field width and pad character by calling
\row \li \c left \li Same as setFieldAlignment(AlignLeft).
\row \li \c right \li Same as setFieldAlignment(AlignRight).
\row \li \c center \li Same as setFieldAlignment(AlignCenter).
- \row \li \c endl \li Same as operator<<('\n') and flush().
+ \row \li \c endl \li Same as operator<<('\\n') and flush().
\row \li \c flush \li Same as flush().
\row \li \c reset \li Same as reset().
\row \li \c ws \li Same as skipWhiteSpace().
This constructor is convenient for working on constant
strings. Example:
- \snippet doc/src/snippets/code/src_corelib_io_qtextstream.cpp 3
+ \snippet code/src_corelib_io_qtextstream.cpp 3
*/
QTextStream::QTextStream(const QByteArray &array, QIODevice::OpenMode openMode)
: d_ptr(new QTextStreamPrivate(this))
This constructor is useful for working directly with the common
FILE based input and output streams: stdin, stdout and stderr. Example:
- \snippet doc/src/snippets/code/src_corelib_io_qtextstream.cpp 4
+ \snippet code/src_corelib_io_qtextstream.cpp 4
*/
QTextStream::QTextStream(FILE *fileHandle, QIODevice::OpenMode openMode)
Example:
- \snippet doc/src/snippets/code/src_corelib_io_qtextstream.cpp 5
+ \snippet code/src_corelib_io_qtextstream.cpp 5
The string \c s contains:
- \snippet doc/src/snippets/code/src_corelib_io_qtextstream.cpp 6
+ \snippet code/src_corelib_io_qtextstream.cpp 6
\sa padChar(), setFieldWidth()
*/
Subsequent calls to setStatus() are ignored until resetStatus()
is called.
- \sa Status status() resetStatus()
+ \sa Status, status(), resetStatus()
*/
void QTextStream::setStatus(Status status)
{
reference to the QTextStream, so several operators can be
nested. Example:
- \snippet doc/src/snippets/code/src_corelib_io_qtextstream.cpp 7
+ \snippet code/src_corelib_io_qtextstream.cpp 7
Whitespace is \e not skipped.
*/
/*!
\overload
- Stores the word in \a c, terminated by a '\0' character. If no word is
- available, only the '\0' character is stored.
+ Stores the word in \a c, terminated by a '\\0' character. If no word is
+ available, only the '\\0' character is stored.
Warning: Although convenient, this operator is dangerous and must
be used with care. QTextStream assumes that \a c points to a
string is assumed to be in ISO-8859-1 encoding. This operator
is convenient when working with constant string data. Example:
- \snippet doc/src/snippets/code/src_corelib_io_qtextstream.cpp 8
+ \snippet code/src_corelib_io_qtextstream.cpp 8
Warning: QTextStream assumes that \a string points to a string of
- text, terminated by a '\0' character. If there is no terminating
- '\0' character, your application may crash.
+ text, terminated by a '\\0' character. If there is no terminating
+ '\\0' character, your application may crash.
*/
QTextStream &QTextStream::operator<<(const char *string)
{
/*!
\relates QTextStream
- Writes '\n' to the \a stream and flushes the stream.
+ Writes '\\n' to the \a stream and flushes the stream.
Equivalent to
- \snippet doc/src/snippets/code/src_corelib_io_qtextstream.cpp 9
+ \snippet code/src_corelib_io_qtextstream.cpp 9
- Note: On Windows, all '\n' characters are written as '\r\n' if
+ Note: On Windows, all '\\n' characters are written as '\\r\\n' if
QTextStream's device or string is opened using the QIODevice::Text flag.
\sa flush(), reset(), {QTextStream manipulators}
Example:
- \snippet doc/src/snippets/code/src_corelib_io_qtextstream.cpp 10
+ \snippet code/src_corelib_io_qtextstream.cpp 10
\sa QTextCodec::codecForName(), setLocale()
*/
unencoded representation is suitable for showing to users, but
the encoded representation is typically what you would send to
a web server. For example, the unencoded URL
- "http://b\uuml\c{}hler.example.com" would be sent to the server as
+ "http://b\\uuml\c{}hler.example.com" would be sent to the server as
"http://xn--bhler-kva.example.com/List%20of%20applicants.xml".
A URL can also be constructed piece by piece by calling
*/
/*!
- \enum QUrl::FormattingOption
+ \enum QUrl::FormattingOptions
The formatting options define how the URL is formatted when written out
as text.
Example:
- \snippet doc/src/snippets/code/src_corelib_io_qurl.cpp 0
+ \snippet code/src_corelib_io_qurl.cpp 0
To construct a URL from an encoded string, call fromEncoded():
- \snippet doc/src/snippets/code/src_corelib_io_qurl.cpp 1
+ \snippet code/src_corelib_io_qurl.cpp 1
\sa setUrl(), setEncodedUrl(), fromEncoded(), TolerantMode
*/
must conform to the standard encoding rules of the URI standard
for the URL to be reported as valid.
- \snippet doc/src/snippets/code/src_corelib_io_qurl.cpp 2
+ \snippet code/src_corelib_io_qurl.cpp 2
*/
bool QUrl::isValid() const
{
and is followed by a ':'. The following example shows a URL where
the scheme is "ftp":
- \img qurl-authority2.png
+ \image qurl-authority2.png
The scheme can also be empty, in which case the URL is interpreted
as relative.
The following example shows a valid authority string:
- \img qurl-authority.png
+ \image qurl-authority.png
*/
void QUrl::setAuthority(const QString &authority)
{
separated by a ':'. If the password is empty, the colon must be
omitted. The following example shows a valid user info string:
- \img qurl-authority3.png
+ \image qurl-authority3.png
\sa userInfo(), setUserName(), setPassword(), setAuthority()
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_io_qurl.cpp 3
+ \snippet code/src_corelib_io_qurl.cpp 3
*/
int QUrl::port(int defaultPort) const
{
Sets the path of the URL to \a path. The path is the part of the
URL that comes after the authority but before the query string.
- \img qurl-ftppath.png
+ \image qurl-ftppath.png
For non-hierarchical schemes, the path will be everything
following the scheme declaration, as in the following example:
- \img qurl-mailtopath.png
+ \image qurl-mailtopath.png
\sa path()
*/
characters. It is typically used in HTTP for referring to a
certain link or point on a page:
- \img qurl-fragment.png
+ \image qurl-fragment.png
The fragment is sometimes also referred to as the URL "reference".
the base URL, but with the merged path, as in the following
example:
- \snippet doc/src/snippets/code/src_corelib_io_qurl.cpp 5
+ \snippet code/src_corelib_io_qurl.cpp 5
Calling resolved() with ".." returns a QUrl whose directory is
one level higher than the original. Similarly, calling resolved()
Unreserved is defined as:
ALPHA / DIGIT / "-" / "." / "_" / "~"
- \snippet doc/src/snippets/code/src_corelib_io_qurl.cpp 6
+ \snippet code/src_corelib_io_qurl.cpp 6
*/
QByteArray QUrl::toPercentEncoding(const QString &input, const QByteArray &exclude, const QByteArray &include)
{
Returns the parent QModelIndex for this persistent index, or an invalid
QModelIndex if it has no parent.
- \sa child() sibling() model()
+ \sa child(), sibling(), model()
*/
QModelIndex QPersistentModelIndex::parent() const
{
Returns the sibling at \a row and \a column or an invalid QModelIndex if
there is no sibling at this position.
- \sa parent() child()
+ \sa parent(), child()
*/
QModelIndex QPersistentModelIndex::sibling(int row, int column) const
Returns the child of the model index that is stored in the given \a row
and \a column.
- \sa parent() sibling()
+ \sa parent(), sibling()
*/
QModelIndex QPersistentModelIndex::child(int row, int column) const
Creates a new empty model index. This type of model index is used to
indicate that the position in the model is invalid.
- \sa isValid() QAbstractItemModel
+ \sa isValid(), QAbstractItemModel
*/
/*!
Returns true if the column is inserted; otherwise returns false.
- \sa insertColumns() insertRow() removeColumn()
+ \sa insertColumns(), insertRow(), removeColumn()
*/
/*!
Returns true if the row is inserted; otherwise returns false.
- \sa insertRows() insertColumn() removeRow()
+ \sa insertRows(), insertColumn(), removeRow()
*/
/*!
For example:
- \snippet examples/itemviews/simpledommodel/dommodel.cpp 2
+ \snippet itemviews/simpledommodel/dommodel.cpp 2
\note When implementing a table based model, columnCount() should return 0
when the parent is valid.
Use rowCount() on the parent to find out the number of children.
- \sa parent() index()
+ \sa parent(), index()
*/
bool QAbstractItemModel::hasChildren(const QModelIndex &parent) const
{
Roles that are not in \a roles will not be modified.
- \sa setData() data() itemData()
+ \sa setData(), data(), itemData()
*/
bool QAbstractItemModel::setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles)
{
}
/*!
+ \fn void QAbstractItemModel::setRoleNames(const QHash<int,QByteArray> &theRoleNames)
\since 4.6
\obsolete
For example, as shown in the diagram, we insert three rows before
row 2, so \a first is 2 and \a last is 4:
- \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 0
+ \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 0
This inserts the three new rows as rows 2, 3, and 4.
\row
collection of 4 existing rows (ending in row 3), so \a first is 4
and \a last is 5:
- \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 1
+ \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 1
This appends the two new rows as rows 4 and 5.
\endtable
For example, as shown in the diagram, we remove the two rows from
row 2 to row 3, so \a first is 2 and \a last is 3:
- \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 2
+ \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 2
\endtable
\note This function emits the rowsAboutToBeRemoved() signal which connected
row 2 to 4 in the source, so \a sourceFirst is 2 and \a sourceLast is 4.
We move those items to above row 2 in the destination, so \a destinationChild is 2.
- \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 6
+ \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 6
This moves the three rows rows 2, 3, and 4 in the source to become 2, 3 and 4 in
the destination. Other affected siblings are displaced accordingly.
For example, as shown in the diagram, we move three rows to a
collection of 6 existing rows (ending in row 5), so \a destinationChild is 6:
- \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 7
+ \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 7
This moves the target rows to the end of the target parent as 6, 7 and 8.
\row
For example, as shown in the diagram, we move one item from row 2 to row 0,
so \a sourceFirst and \a sourceLast are 2 and \a destinationChild is 0.
- \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 8
+ \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 8
Note that other rows may be displaced accordingly. Note also that when moving
items within the same parent you should not attempt invalid or no-op moves. In
For example, as shown in the diagram, we move one item from row 2 to row 4,
so \a sourceFirst and \a sourceLast are 2 and \a destinationChild is 4.
- \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 9
+ \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 9
Note that other rows may be displaced accordingly.
\endtable
For example, as shown in the diagram, we insert three columns
before column 4, so \a first is 4 and \a last is 6:
- \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 3
+ \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 3
This inserts the three new columns as columns 4, 5, and 6.
\row
collection of six existing columns (ending in column 5), so
\a first is 6 and \a last is 8:
- \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 4
+ \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 4
This appends the two new columns as columns 6, 7, and 8.
\endtable
For example, as shown in the diagram, we remove the three columns
from column 4 to column 6, so \a first is 4 and \a last is 6:
- \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 5
+ \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 5
\endtable
\note This function emits the columnsAboutToBeRemoved() signal which
}
/*!
+ \fn void QAbstractItemModel::reset()
\obsolete
Resets the model to its original state in any attached views.
For example, in this code both signals modelAboutToBeReset() and modelReset()
are emitted \e after the data changes:
- \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 10
+ \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 10
Instead you should use:
- \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 11
+ \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 11
*/
/*!
Returns the parent of the model item with the given \a index.
- \sa index() hasChildren()
+ \sa index(), hasChildren()
*/
QModelIndex QAbstractTableModel::parent(const QModelIndex &) const
/*!
Returns the parent of the model item with the given \a index.
- \sa index() hasChildren()
+ \sa index(), hasChildren()
*/
QModelIndex QAbstractListModel::parent(const QModelIndex & /* index */) const
This also provides a way to change the data in the case where a source model is supplied by a third party which can not be modified.
- \snippet doc/src/snippets/code/src_gui_itemviews_qidentityproxymodel.cpp 0
+ \snippet code/src_gui_itemviews_qidentityproxymodel.cpp 0
\sa QAbstractProxyModel, {Model/View Programming}, QAbstractItemModel
a selection that contains a range of items from the given \c model,
beginning at the \c topLeft, and ending at the \c bottomRight.
- \snippet doc/src/snippets/code/src_gui_itemviews_qitemselectionmodel.cpp 0
+ \snippet code/src_gui_itemviews_qitemselectionmodel.cpp 0
An empty item selection can be constructed, and later populated as
required. So, if the model is going to be unavailable when we construct
the item selection, we can rewrite the above code in the following way:
- \snippet doc/src/snippets/code/src_gui_itemviews_qitemselectionmodel.cpp 1
+ \snippet code/src_gui_itemviews_qitemselectionmodel.cpp 1
QItemSelection saves memory, and avoids unnecessary work, by working with
selection ranges rather than recording the model item index for each
Note that this signal will not be emitted when the item model is reset.
- \sa currentIndex() setCurrentIndex() selectionChanged()
+ \sa currentIndex(), setCurrentIndex(), selectionChanged()
*/
/*!
Note that this signal will not be emitted when the item model is reset.
- \sa currentChanged() currentRowChanged() currentIndex() setCurrentIndex()
+ \sa currentChanged(), currentRowChanged(), currentIndex(), setCurrentIndex()
*/
/*!
Note that this signal will not be emitted when the item model is reset.
- \sa currentChanged() currentColumnChanged() currentIndex() setCurrentIndex()
+ \sa currentChanged(), currentColumnChanged(), currentIndex(), setCurrentIndex()
*/
/*!
Note the that the current index changes independently from the selection.
Also note that this signal will not be emitted when the item model is reset.
- \sa select() currentChanged()
+ \sa select(), currentChanged()
*/
/*!
model. The code to set up the model and the view, \e without sorting and
filtering, would look like this:
- \snippet doc/src/snippets/qsortfilterproxymodel-details/main.cpp 1
+ \snippet qsortfilterproxymodel-details/main.cpp 1
To add sorting and filtering support to \c MyItemModel, we need to create
a QSortFilterProxyModel, call setSourceModel() with the \c MyItemModel as
argument, and install the QSortFilterProxyModel on the view:
- \snippet doc/src/snippets/qsortfilterproxymodel-details/main.cpp 0
- \snippet doc/src/snippets/qsortfilterproxymodel-details/main.cpp 2
+ \snippet qsortfilterproxymodel-details/main.cpp 0
+ \snippet qsortfilterproxymodel-details/main.cpp 2
At this point, neither sorting nor filtering is enabled; the original data
is displayed in the view. Any changes made through the
whether the user can sort the view by clicking the view's horizontal
header. For example:
- \snippet doc/src/snippets/qsortfilterproxymodel-details/main.cpp 3
+ \snippet qsortfilterproxymodel-details/main.cpp 3
When this feature is on (the default is off), clicking on a header section
sorts the items according to that column. By clicking repeatedly, the user
QSortFilterProxyModel and reimplementing lessThan(), which is
used to compare items. For example:
- \snippet examples/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp 5
+ \snippet itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp 5
(This code snippet comes from the
\l{itemviews/customsortfiltermodel}{Custom Sort/Filter Model}
QSortFilterProxyModel (or on the original model if it implements sort()).
For example:
- \snippet doc/src/snippets/qsortfilterproxymodel-details/main.cpp 4
+ \snippet qsortfilterproxymodel-details/main.cpp 4
QSortFilterProxyModel can be sorted by column -1, in which case it returns
to the sort order of the underlying source model.
each item, for a given column. The QRegExp object can be used to match a
regular expression, a wildcard pattern, or a fixed string. For example:
- \snippet doc/src/snippets/qsortfilterproxymodel-details/main.cpp 5
+ \snippet qsortfilterproxymodel-details/main.cpp 5
For hierarchical models, the filter is applied recursively to all children.
If a parent item doesn't match the filter, none of its children will be
the \l{QSortFilterProxyModel::filterKeyColumn}{filterKeyColumn} property
and performs filtering on columns 0, 1, and 2:
- \snippet examples/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp 3
+ \snippet itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp 3
(This code snippet comes from the
\l{itemviews/customsortfiltermodel}{Custom Sort/Filter Model}
An example usage of QStringListModel:
- \snippet doc/src/snippets/qstringlistmodel/main.cpp 0
+ \snippet qstringlistmodel/main.cpp 0
\sa QAbstractListModel, QAbstractItemModel, {Model Classes}
*/
\sa constBegin(), end()
*/
-/*! \fn void QJsonArray::push_back(const T &value)
+/*! \fn void QJsonArray::push_back(const QJsonValue &value)
This function is provided for STL compatibility. It is equivalent
to \l{QJsonArray::append()}{append(\a value)}.
*/
-/*! \fn void QJsonArray::push_front(const T &value)
+/*! \fn void QJsonArray::push_front(const QJsonValue &value)
This function is provided for STL compatibility. It is equivalent
to \l{QJsonArray::prepend()}{prepend(\a value)}.
on an uninitialized iterator. Use operator=() to assign a value
to it before using it.
- \sa QJsonArray::begin() QJsonArray::end()
-*/
-
-/*! \fn QJsonArray::iterator::iterator(const iterator &other)
-
- Constructs a copy of \a other.
+ \sa QJsonArray::begin(), QJsonArray::end()
*/
/*! \fn QJsonValueRef QJsonArray::iterator::operator*() const
on an uninitialized iterator. Use operator=() to assign a value
to it before using it.
- \sa QJsonArray::constBegin() QJsonArray::constEnd()
+ \sa QJsonArray::constBegin(), QJsonArray::constEnd()
*/
/*! \typedef QJsonArray::const_iterator::iterator_category
Returns a QJsonDocument representing the data.
- \sa rawData fromBinaryData isNull DataValidation
+ \sa rawData, fromBinaryData, isNull, DataValidation
*/
QJsonDocument QJsonDocument::fromRawData(const char *data, int size, DataValidation validation)
{
By default the data is validated. If the \a data is not valid, the method returns
a null document.
- \sa toBinaryData fromRawData isNull DataValidation
+ \sa toBinaryData, fromRawData, isNull, DataValidation
*/
QJsonDocument QJsonDocument::fromBinaryData(const QByteArray &data, DataValidation validation)
{
/*!
Returns true if the document contains an array.
- \sa array() isObject()
+ \sa array(), isObject()
*/
bool QJsonDocument::isArray() const
{
/*!
Returns true if the document contains an object.
- \sa object() isArray()
+ \sa object(), isArray()
*/
bool QJsonDocument::isObject() const
{
Returns an empty object if the document contains an
array.
- \sa isObject array setObject
+ \sa isObject, array, setObject
*/
QJsonObject QJsonDocument::object() const
{
Returns an empty array if the document contains an
object.
- \sa isArray object setArray
+ \sa isArray, object, setArray
*/
QJsonArray QJsonDocument::array() const
{
/*!
Sets \a object as the main object of this document.
- \sa setArray object
+ \sa setArray, object
*/
void QJsonDocument::setObject(const QJsonObject &object)
{
/*!
Sets \a array as the main object of this document.
- \sa setObject array
+ \sa setObject, array
*/
void QJsonDocument::setArray(const QJsonArray &array)
{
/*!
Constructs an empty JSON object
- \sa isEmpty
+ \sa isEmpty()
*/
QJsonObject::QJsonObject()
: d(0), o(0)
The keys in \a map will be used as the keys in the JSON object,
and the QVariant values will be converted to JSON values.
- \sa toVariantMap, QJsonValue::fromVariant
+ \sa toVariantMap(), QJsonValue::fromVariant()
*/
QJsonObject QJsonObject::fromVariantMap(const QVariantMap &map)
{
/*!
Returns \c true if the object is empty. This is the same as size() == 0.
- \sa size
+ \sa size()
*/
bool QJsonObject::isEmpty() const
{
The returned QJsonValue is \c Undefined, if the key does not exist.
- \sa setValue, QJsonValue, QJsonValue::isUndefined
+ \sa QJsonValue, QJsonValue::isUndefined()
*/
QJsonValue QJsonObject::value(const QString &key) const
{
The returned QJsonValue is \c Undefined, if the key does not exist.
- \sa value, setValue, QJsonValue, QJsonValue::isUndefined
+ \sa value(), QJsonValue, QJsonValue::isUndefined()
*/
QJsonValue QJsonObject::operator [](const QString &key) const
{
the assignment will apply to the character in the QJsonArray of QJsonObject
from which you got the reference.
- \sa setValue, value
+ \sa value()
*/
QJsonValueRef QJsonObject::operator [](const QString &key)
{
If the value is QJsonValue::Undefined, it will cause the key to get removed
from the object. The returned iterator will then point to end()
- \sa remove, take, QJsonObject::iterator, end
+ \sa remove(), take(), QJsonObject::iterator, end()
*/
QJsonObject::iterator QJsonObject::insert(const QString &key, const QJsonValue &value)
{
/*!
Removes \a key from the object.
- \sa insert, take
+ \sa insert(), take()
*/
void QJsonObject::remove(const QString &key)
{
If \a key was not contained in the object, the returned QJsonValue
is Undefined.
- \sa insert, remove, QJsonValue
+ \sa insert(), remove(), QJsonValue
*/
QJsonValue QJsonObject::take(const QString &key)
{
/*!
Returns \c true if the object contains key \a key.
- \sa insert, remove, take
+ \sa insert(), remove(), take()
*/
bool QJsonObject::contains(const QString &key) const
{
return iterator(this, index);
}
-/*! \fn QJsonObject::const_iterator QJsonObject::find(const Key &key) const
+/*! \fn QJsonObject::const_iterator QJsonObject::find(const QString &key) const
\overload
*/
*/
/*! \class QJsonObject::iterator
+ \ingroup json
+ \reentrant
+ \since 5.0
+
\brief The QJsonObject::iterator class provides an STL-style non-const iterator for QJsonObject.
QJsonObject::iterator allows you to iterate over a QJsonObject
called on an uninitialized iterator. Use operator=() to assign a
value to it before using it.
- \sa QJsonObject::begin() QJsonObject::end()
+ \sa QJsonObject::begin(), QJsonObject::end()
*/
/*! \fn QString QJsonObject::iterator::key() const
\sa operator+=(), operator-()
*/
-/*! \class QJsonObject::const_iterator
+/*!
+ \class QJsonObject::const_iterator
\brief The QJsonObject::const_iterator class provides an STL-style const iterator for QJsonObject.
QJsonObject::const_iterator allows you to iterate over a QJsonObject.
called on an uninitialized iterator. Use operator=() to assign a
value to it before using it.
- \sa QJsonObject::constBegin() QJsonObject::constEnd()
+ \sa QJsonObject::constBegin(), QJsonObject::constEnd()
*/
/*! \fn QJsonObject::const_iterator::const_iterator(const iterator &other)
Qt-style synonym for QJsonObject::const_iterator.
*/
-
-/*! \class QJsonObject::iterator
- \ingroup json
- \reentrant
- \since 5.0
-
- \brief The QJsonDocument::iterator class provides a way to iterate over q QJsonObject
-
-
- */
-
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug dbg, const QJsonObject &o)
{
Typedef for a function with the signature
- \snippet doc/src/snippets/code/src_corelib_kernel_qabstracteventdispatcher.cpp 0
+ \snippet code/src_corelib_kernel_qabstracteventdispatcher.cpp 0
Note that the type of the \a message is platform dependent. The
following table shows the \a {message}'s type on Windows, Mac, and
This signal is emitted after the event loop returns from a
function that could block.
- \sa wakeUp() aboutToBlock()
+ \sa wakeUp(), aboutToBlock()
*/
/*! \fn void QAbstractEventDispatcher::aboutToBlock()
Returns true if the timer is running and has not been stopped; otherwise
returns false.
- \sa start() stop()
+ \sa start(), stop()
*/
/*!
The given \a object will receive timer events.
- \sa stop() isActive() QObject::timerEvent() Qt::CoarseTimer
+ \sa stop(), isActive(), QObject::timerEvent(), Qt::CoarseTimer
*/
void QBasicTimer::start(int msec, QObject *obj)
{
The given \a object will receive timer events.
- \sa stop() isActive() QObject::timerEvent() Qt::TimerType
+ \sa stop(), isActive(), QObject::timerEvent(), Qt::TimerType
*/
void QBasicTimer::start(int msec, Qt::TimerType timerType, QObject *obj)
{
/*!
Stops the timer.
- \sa start() isActive()
+ \sa start(), isActive()
*/
void QBasicTimer::stop()
{
The event is \e not deleted when the event has been sent. The normal
approach is to create the event on the stack, for example:
- \snippet doc/src/snippets/code/src_corelib_kernel_qcoreapplication.cpp 0
+ \snippet code/src_corelib_kernel_qcoreapplication.cpp 0
\sa postEvent(), notify()
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_kernel_qcoreapplication.cpp 1
+ \snippet code/src_corelib_kernel_qcoreapplication.cpp 1
\sa exit(), aboutToQuit(), QApplication::lastWindowClosed()
*/
The function returns true on success and false on failure.
- \sa removeTranslator() translate() QTranslator::load() {Dynamic Translation}
+ \sa removeTranslator(), translate(), QTranslator::load(), {Dynamic Translation}
*/
bool QCoreApplication::installTranslator(QTranslator *translationFile)
so will most likely result in crashes or other undesirable
behavior.
- \sa QObject::tr() installTranslator()
+ \sa QObject::tr(), installTranslator()
*/
organizationName(). On all other platforms, QSettings uses
organizationName() as the organization.
- \sa organizationDomain applicationName
+ \sa organizationDomain, applicationName
*/
void QCoreApplication::setOrganizationName(const QString &orgName)
On all other platforms, QSettings uses organizationName() as the
organization.
- \sa organizationName applicationName applicationVersion
+ \sa organizationName, applicationName, applicationVersion
*/
void QCoreApplication::setOrganizationDomain(const QString &orgDomain)
{
If not set, the application name defaults to the executable name (since 5.0).
- \sa organizationName organizationDomain applicationVersion applicationFilePath
+ \sa organizationName, organizationDomain, applicationVersion, applicationFilePath
*/
void QCoreApplication::setApplicationName(const QString &application)
{
\since 4.4
\brief the version of this application
- \sa applicationName organizationName organizationDomain
+ \sa applicationName, organizationName, organizationDomain
*/
void QCoreApplication::setApplicationVersion(const QString &version)
{
If you want to iterate over the list, you can use the \l foreach
pseudo-keyword:
- \snippet doc/src/snippets/code/src_corelib_kernel_qcoreapplication.cpp 2
+ \snippet code/src_corelib_kernel_qcoreapplication.cpp 2
\sa setLibraryPaths(), addLibraryPath(), removeLibraryPath(), QLibrary,
{How to Create Qt Plugins}
A function with the following signature that can be used as an
event filter:
- \snippet doc/src/snippets/code/src_corelib_kernel_qcoreapplication.cpp 3
+ \snippet code/src_corelib_kernel_qcoreapplication.cpp 3
\sa setEventFilter()
*/
The function specified by \a ptr should take no arguments and should
return nothing. For example:
- \snippet doc/src/snippets/code/src_corelib_kernel_qcoreapplication.cpp 4
+ \snippet code/src_corelib_kernel_qcoreapplication.cpp 4
Note that for an application- or module-wide cleanup,
qAddPostRoutine() is often not suitable. For example, if the
parent-child mechanism to call a cleanup function at the right
time:
- \snippet doc/src/snippets/code/src_corelib_kernel_qcoreapplication.cpp 5
+ \snippet code/src_corelib_kernel_qcoreapplication.cpp 5
By selecting the right parent object, this can often be made to
clean up the module's data at the right moment.
translation functions, \c tr() and \c trUtf8(), with these
signatures:
- \snippet doc/src/snippets/code/src_corelib_kernel_qcoreapplication.cpp 6
+ \snippet code/src_corelib_kernel_qcoreapplication.cpp 6
This macro is useful if you want to use QObject::tr() or
QObject::trUtf8() in classes that don't inherit from QObject.
class definition (before the first \c{public:} or \c{protected:}).
For example:
- \snippet doc/src/snippets/code/src_corelib_kernel_qcoreapplication.cpp 7
+ \snippet code/src_corelib_kernel_qcoreapplication.cpp 7
The \a context parameter is normally the class name, but it can
be any string.
false. The event loop is considered running from the time when
exec() is called until exit() is called.
- \sa exec() exit()
+ \sa exec(), exit()
*/
bool QEventLoop::isRunning() const
{
Use code like the following to obtain a QStringList containing the methods
specific to a given class:
- \snippet doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp methodCount
+ \snippet code/src_corelib_kernel_qmetaobject.cpp methodCount
\sa method(), methodOffset(), indexOfMethod()
*/
Use code like the following to obtain a QStringList containing the properties
specific to a given class:
- \snippet doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp propertyCount
+ \snippet code/src_corelib_kernel_qmetaobject.cpp propertyCount
\sa property(), propertyOffset(), indexOfProperty()
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp 0
+ \snippet code/src_corelib_kernel_qmetaobject.cpp 0
\sa classInfoCount(), classInfoOffset(), indexOfClassInfo()
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp 1
+ \snippet code/src_corelib_kernel_qmetaobject.cpp 1
\sa normalizedSignature()
*/
the \l{QPushButton::animateClick()}{animateClick()} slot on a
QPushButton, use the following code:
- \snippet doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp 2
+ \snippet code/src_corelib_kernel_qmetaobject.cpp 2
With asynchronous method invocations, the parameters must be of
types that are known to Qt's meta-object system, because Qt needs
scenes. If you try to use a queued connection and get the error
message
- \snippet doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp 3
+ \snippet code/src_corelib_kernel_qmetaobject.cpp 3
call qRegisterMetaType() to register the data type before you
call invokeMethod().
To synchronously invoke the \c compute(QString, int, double) slot on
some arbitrary object \c obj retrieve its return value:
- \snippet doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp 4
+ \snippet code/src_corelib_kernel_qmetaobject.cpp 4
If the "compute" slot does not take exactly one QString, one int
and one double in the specified order, the call will fail.
\l{QPushButton::animateClick()}{animateClick()} slot on a
QPushButton:
- \snippet doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp 6
+ \snippet code/src_corelib_kernel_qmetaobject.cpp 6
With asynchronous method invocations, the parameters must be of
types that are known to Qt's meta-object system, because Qt needs
scenes. If you try to use a queued connection and get the error
message
- \snippet doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp 7
+ \snippet code/src_corelib_kernel_qmetaobject.cpp 7
call qRegisterMetaType() to register the data type before you
call QMetaMethod::invoke().
To synchronously invoke the \c compute(QString, int, double) slot on
some arbitrary object \c obj retrieve its return value:
- \snippet doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp 8
+ \snippet code/src_corelib_kernel_qmetaobject.cpp 8
QMetaObject::normalizedSignature() is used here to ensure that the format
of the signature is what invoke() expects. E.g. extra whitespace is
are specified using Q_CLASSINFO() in the source code. The
information can be retrieved using name() and value(). For example:
- \snippet doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp 5
+ \snippet code/src_corelib_kernel_qmetaobject.cpp 5
This mechanism is free for you to use in your Qt applications. Qt
doesn't use it for any of its classes.
\a name. Returns an object that can be used to adjust
the other attributes of the enumerator.
- \sa enumerator(), enumeratorCount(), removeEnumerator(),
+ \sa enumerator(), enumeratorCount(), removeEnumerator()
\sa indexOfEnumerator()
*/
QMetaEnumBuilder QMetaObjectBuilder::addEnumerator(const QByteArray& name)
QMetaObject. Returns an object that can be used to adjust the
attributes of the enumerator.
- \sa enumerator(), enumeratorCount(), removeEnumerator(),
+ \sa enumerator(), enumeratorCount(), removeEnumerator()
\sa indexOfEnumerator()
*/
QMetaEnumBuilder QMetaObjectBuilder::addEnumerator(const QMetaEnum& prototype)
This example shows a typical use case of Q_DECLARE_METATYPE():
- \snippet doc/src/snippets/code/src_corelib_kernel_qmetatype.cpp 0
+ \snippet code/src_corelib_kernel_qmetatype.cpp 0
If \c MyStruct is in a namespace, the Q_DECLARE_METATYPE() macro
has to be outside the namespace:
- \snippet doc/src/snippets/code/src_corelib_kernel_qmetatype.cpp 1
+ \snippet code/src_corelib_kernel_qmetatype.cpp 1
Since \c{MyStruct} is now known to QMetaType, it can be used in QVariant:
- \snippet doc/src/snippets/code/src_corelib_kernel_qmetatype.cpp 2
+ \snippet code/src_corelib_kernel_qmetatype.cpp 2
\sa qRegisterMetaType()
*/
\value User Base value for user types
\value UnknownType This is an invalid type id. It is returned from QMetaType for types that are not registered
- \omitvalue FirstGuiType
- \omitvalue FirstWidgetsType
- \omitvalue LastCoreType
- \omitvalue LastGuiType
- \omitvalue LastWidgetsType
- \omitvalue QReal
- \omitvalue HighestInternalId
-
Additional types can be registered using Q_DECLARE_METATYPE().
\sa type(), typeName()
*/
/*!
- \enum QMetaType::TypeFlags
+ \enum QMetaType::TypeFlag
The enum describes attributes of a type supported by QMetaType.
The following code allocates and destructs an instance of
\c{MyClass}:
- \snippet doc/src/snippets/code/src_corelib_kernel_qmetatype.cpp 3
+ \snippet code/src_corelib_kernel_qmetatype.cpp 3
If we want the stream operators \c operator<<() and \c
operator>>() to work on QVariant objects that store custom types,
This example registers the class \c{MyClass}:
- \snippet doc/src/snippets/code/src_corelib_kernel_qmetatype.cpp 4
+ \snippet code/src_corelib_kernel_qmetatype.cpp 4
This function is useful to register typedefs so they can be used
by QMetaProperty, or in QueuedConnections
- \snippet doc/src/snippets/code/src_corelib_kernel_qmetatype.cpp 9
+ \snippet code/src_corelib_kernel_qmetatype.cpp 9
\sa qRegisterMetaTypeStreamOperators(), QMetaType::isRegistered(),
Q_DECLARE_METATYPE()
QMetaType::save(). These functions are used when streaming a
QVariant.
- \snippet doc/src/snippets/code/src_corelib_kernel_qmetatype.cpp 5
+ \snippet code/src_corelib_kernel_qmetatype.cpp 5
The stream operators should have the following signatures:
- \snippet doc/src/snippets/code/src_corelib_kernel_qmetatype.cpp 6
+ \snippet code/src_corelib_kernel_qmetatype.cpp 6
\sa qRegisterMetaType(), QMetaType::isRegistered(), Q_DECLARE_METATYPE()
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_kernel_qmetatype.cpp 7
+ \snippet code/src_corelib_kernel_qmetatype.cpp 7
To use the type \c T in QVariant, using Q_DECLARE_METATYPE() is
sufficient. To use the type \c T in queued signal and slot connections,
Typical usage:
- \snippet doc/src/snippets/code/src_corelib_kernel_qmetatype.cpp 8
+ \snippet code/src_corelib_kernel_qmetatype.cpp 8
QMetaType::type() returns the same ID as qMetaTypeId(), but does
a lookup at runtime based on the name of the type.
FlagsEx = 0x100
};
public:
+#ifndef Q_QDOC
+ // The code that actually gets compiled.
enum Type {
// these are merged with QVariant
QT_FOR_EACH_STATIC_TYPE(QT_DEFINE_METATYPE_ID)
UnknownType = 0,
User = 1024
};
+#else
+ // If we are using QDoc it fakes the Type enum looks like this.
+ enum Type {
+ Void = 0, Bool = 1, Int = 2, UInt = 3, LongLong = 4, ULongLong = 5,
+ Double = 6, Long = 32, Short = 33, Char = 34, ULong = 35, UShort = 36,
+ UChar = 37, Float = 38,
+ VoidStar = 31,
+ QChar = 7, QString = 10, QStringList = 11, QByteArray = 12,
+ QBitArray = 13, QDate = 14, QTime = 15, QDateTime = 16, QUrl = 17,
+ QLocale = 18, QRect = 19, QRectF = 20, QSize = 21, QSizeF = 22,
+ QLine = 23, QLineF = 24, QPoint = 25, QPointF = 26, QRegExp = 27,
+ QEasingCurve = 29, QUuid = 30, QVariant = 41, QModelIndex = 42,
+ QObjectStar = 39, QWidgetStar = 40,
+ QVariantMap = 8, QVariantList = 9, QVariantHash = 28,
+ QFont = 64, QPixmap = 65, QBrush = 66, QColor = 67, QPalette = 68,
+ QImage = 69, QPolygon = 70, QRegion = 71, QBitmap = 72, QCursor = 73,
+ QKeySequence = 74, QPen = 75, QTextLength = 76, QTextFormat = 77,
+ QMatrix = 78, QTransform = 79, QMatrix4x4 = 80, QVector2D = 81,
+ QVector3D = 82, QVector4D = 83, QQuaternion = 84, QPolygonF = 85,
+ QIcon = 120, QSizePolicy = 121,
+ User = 256
+ };
+#endif
enum TypeFlag {
NeedsConstruction = 0x1,
For example, if your write a widget that accepts URL drags, you
would end up writing code like this:
- \snippet doc/src/snippets/code/src_corelib_kernel_qmimedata.cpp 0
+ \snippet code/src_corelib_kernel_qmimedata.cpp 0
There are three approaches for storing custom data in a QMimeData
object:
\li Custom data can be stored directly in a QMimeData object as a
QByteArray using setData(). For example:
- \snippet doc/src/snippets/code/src_corelib_kernel_qmimedata.cpp 1
+ \snippet code/src_corelib_kernel_qmimedata.cpp 1
\li We can subclass QMimeData and reimplement hasFormat(),
formats(), and retrieveData().
it, and use a qobject_cast() in the receiver's drop event
handler. For example:
- \snippet doc/src/snippets/code/src_corelib_kernel_qmimedata.cpp 2
+ \snippet code/src_corelib_kernel_qmimedata.cpp 2
\endlist
\section1 Platform-Specific MIME Types
indicate that they represent data in non-standard formats.
The formats will take the following form:
- \snippet doc/src/snippets/code/src_corelib_kernel_qmimedata.cpp 3
+ \snippet code/src_corelib_kernel_qmimedata.cpp 3
The following are examples of custom MIME types:
- \snippet doc/src/snippets/code/src_corelib_kernel_qmimedata.cpp 4
+ \snippet code/src_corelib_kernel_qmimedata.cpp 4
The \c value declaration of each format describes the way in which the
data is encoded.
library, whereas QImage belongs to \l QtGui. To convert the
QVariant to a QImage, simply use qvariant_cast(). For example:
- \snippet doc/src/snippets/code/src_corelib_kernel_qmimedata.cpp 5
+ \snippet code/src_corelib_kernel_qmimedata.cpp 5
\sa hasImage()
*/
library, whereas QImage belongs to \l QtGui. The conversion
from QImage to QVariant is implicit. For example:
- \snippet doc/src/snippets/code/src_corelib_kernel_qmimedata.cpp 6
+ \snippet code/src_corelib_kernel_qmimedata.cpp 6
\sa hasImage(), setData()
*/
library, whereas QColor belongs to \l QtGui. To convert the
QVariant to a QColor, simply use qvariant_cast(). For example:
- \snippet doc/src/snippets/code/src_corelib_kernel_qmimedata.cpp 7
+ \snippet code/src_corelib_kernel_qmimedata.cpp 7
\sa hasColor(), setColorData(), data()
*/
\l uic generates code that invokes this function to enable
auto-connection to be performed between widgets on forms created
- with \QD. More information about using auto-connection with \QD is
+ with \e{Qt Designer}. More information about using auto-connection with \e{Qt Designer} is
given in the \l{Using a Designer UI File in Your Application} section of
- the \QD manual.
+ the \e{Qt Designer} manual.
\section1 Dynamic Properties
Returns 0 if there is no such child.
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 0
+ \snippet code/src_corelib_kernel_qobject.cpp 0
*/
void *qt_find_obj_child(QObject *parent, const char *type, const QString &name)
Constructs an object with parent object \a parent.
The parent of an object may be viewed as the object's owner. For
- instance, a \l{QDialog}{dialog box} is the parent of the \gui OK
- and \gui Cancel buttons it contains.
+ instance, a \l{QDialog}{dialog box} is the parent of the \uicontrol{OK}
+ and \uicontrol{Cancel} buttons it contains.
The destructor of a parent object destroys all child objects.
Example:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 1
+ \snippet code/src_corelib_kernel_qobject.cpp 1
\sa staticMetaObject
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 2
+ \snippet code/src_corelib_kernel_qobject.cpp 2
\sa metaObject()
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 3
+ \snippet code/src_corelib_kernel_qobject.cpp 3
The qobject_cast() function behaves similarly to the standard C++
\c dynamic_cast(), with the advantages that it doesn't require
Example:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 4
+ \snippet code/src_corelib_kernel_qobject.cpp 4
If you need to determine whether an object is an instance of a particular
class for the purpose of casting it, consider using qobject_cast<Type *>(object)
You can find an object by name (and type) using findChild().
You can find a set of objects with findChildren().
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 5
+ \snippet code/src_corelib_kernel_qobject.cpp 5
By default, this property contains an empty string.
true; otherwise return false.
Example:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 6
+ \snippet code/src_corelib_kernel_qobject.cpp 6
Notice in the example above that unhandled events are passed to
the base class's eventFilter() function, since the base class
QApplication::thread() to retrieve the thread in which the
application lives. For example:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 7
+ \snippet code/src_corelib_kernel_qobject.cpp 7
If \a targetThread is zero, all event processing for this object
and its children stops.
Example:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 8
+ \snippet code/src_corelib_kernel_qobject.cpp 8
Note that QTimer's accuracy depends on the underlying operating system and
hardware. The \a timerType argument allows you to customize the accuracy of
The QObjectList class is defined in the \c{<QObject>} header
file as the following:
- \quotefromfile src/corelib/kernel/qobject.h
+ \quotefromfile kernel/qobject.h
\skipto /typedef .*QObjectList/
\printuntil QObjectList
named \c{"button1"}, even if the button isn't a direct child of
the parent:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 10
+ \snippet code/src_corelib_kernel_qobject.cpp 10
This example returns a \l{QListWidget} child of \c{parentWidget}:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 11
+ \snippet code/src_corelib_kernel_qobject.cpp 11
This example returns a child \l{QPushButton} of \c{parentWidget}
(its direct parent) named \c{"button1"}:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 41
+ \snippet code/src_corelib_kernel_qobject.cpp 41
This example returns a \l{QListWidget} child of \c{parentWidget},
its direct parent:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 42
+ \snippet code/src_corelib_kernel_qobject.cpp 42
\sa findChildren()
*/
The following example shows how to find a list of child \l{QWidget}s of
the specified \c{parentWidget} named \c{widgetname}:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 12
+ \snippet code/src_corelib_kernel_qobject.cpp 12
This example returns all \c{QPushButton}s that are children of \c{parentWidget}:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 13
+ \snippet code/src_corelib_kernel_qobject.cpp 13
This example returns all \c{QPushButton}s that are immediate children of \c{parentWidget}:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 43
+ \snippet code/src_corelib_kernel_qobject.cpp 43
\sa findChild()
*/
\fn void QObject::installEventFilter(QObject *filterObj)
Installs an event filter \a filterObj on this object. For example:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 14
+ \snippet code/src_corelib_kernel_qobject.cpp 14
An event filter is an object that receives all events that are
sent to this object. The filter can either stop the event or
Here's a \c KeyPressEater class that eats the key presses of its
monitored objects:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 15
+ \snippet code/src_corelib_kernel_qobject.cpp 15
And here's how to install it on two widgets:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 16
+ \snippet code/src_corelib_kernel_qobject.cpp 16
The QShortcut class, for example, uses this technique to intercept
shortcut key presses.
Example:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 17
+ \snippet code/src_corelib_kernel_qobject.cpp 17
\dots
See \l{Writing Source Code for Translation} for a detailed description of
escape sequences for specifying non-ASCII characters in string
literals to trUtf8(). For example:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 20
+ \snippet code/src_corelib_kernel_qobject.cpp 20
\sa tr(), QApplication::translate(), {Internationalization with Qt}
*/
When calling this function, you can use the \c SIGNAL() macro to
pass a specific signal:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 21
+ \snippet code/src_corelib_kernel_qobject.cpp 21
As the code snippet above illustrates, you can use this function
to avoid emitting a signal that nobody listens to.
You must use the \c SIGNAL() and \c SLOT() macros when specifying
the \a signal and the \a method, for example:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 22
+ \snippet code/src_corelib_kernel_qobject.cpp 22
This example ensures that the label always displays the current
scroll bar value. Note that the signal and slots parameters must not
contain any variable names, only the type. E.g. the following would
not work and return false:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 23
+ \snippet code/src_corelib_kernel_qobject.cpp 23
A signal can also be connected to another signal:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 24
+ \snippet code/src_corelib_kernel_qobject.cpp 24
In this example, the \c MyWidget constructor relays a signal from
a private member variable, and makes it available under a name
scenes. If you try to use a queued connection and get the error
message
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 25
+ \snippet code/src_corelib_kernel_qobject.cpp 25
call qRegisterMetaType() to register the data type before you
establish the connection.
\list 1
\li Disconnect everything connected to an object's signals:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 26
+ \snippet code/src_corelib_kernel_qobject.cpp 26
equivalent to the non-static overloaded function
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 27
+ \snippet code/src_corelib_kernel_qobject.cpp 27
\li Disconnect everything connected to a specific signal:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 28
+ \snippet code/src_corelib_kernel_qobject.cpp 28
equivalent to the non-static overloaded function
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 29
+ \snippet code/src_corelib_kernel_qobject.cpp 29
\li Disconnect a specific receiver:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 30
+ \snippet code/src_corelib_kernel_qobject.cpp 30
equivalent to the non-static overloaded function
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 31
+ \snippet code/src_corelib_kernel_qobject.cpp 31
\endlist
If you want to compare \a signal with a specific signal, use
QLatin1String and the \c SIGNAL() macro as follows:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 32
+ \snippet code/src_corelib_kernel_qobject.cpp 32
If the signal contains multiple parameters or parameters that
contain spaces, call QMetaObject::normalizedSignature() on
Searches recursively for all child objects of the given \a object, and connects
matching signals from them to slots of \a object that follow the following form:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 33
+ \snippet code/src_corelib_kernel_qobject.cpp 33
Let's assume our object has a child object of type QPushButton with
the \l{QObject::objectName}{object name} \c{button1}. The slot to catch the
button's \c{clicked()} signal would be:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 34
+ \snippet code/src_corelib_kernel_qobject.cpp 34
\sa QObject::setObjectName()
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 35
+ \snippet code/src_corelib_kernel_qobject.cpp 35
\sa QMetaObject::classInfo()
*/
Example:
- \snippet examples/tools/plugandpaintplugins/basictools/basictoolsplugin.h 1
+ \snippet tools/plugandpaintplugins/basictools/basictoolsplugin.h 1
\dots
- \snippet examples/tools/plugandpaintplugins/basictools/basictoolsplugin.h 3
+ \snippet tools/plugandpaintplugins/basictools/basictoolsplugin.h 3
See the \l{tools/plugandpaintplugins/basictools}{Plug & Paint
Basic Tools} example for details.
they have additional features accessible through the \l
{Meta-Object System}.
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 36
+ \snippet code/src_corelib_kernel_qobject.cpp 36
The property name and type and the \c READ function are required.
The type can be any type supported by QVariant, or it can be a
For example:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 37
+ \snippet code/src_corelib_kernel_qobject.cpp 37
For more details about how to use this macro, and a more detailed
example of its use, see the discussion on \l {Qt's Property System}.
For example:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 38
+ \snippet code/src_corelib_kernel_qobject.cpp 38
If you want to register an enum that is declared in another class,
the enum must be fully qualified with the name of the class
For example, in QLibrary, the \l{QLibrary::LoadHints}{LoadHints} flag is
declared in the following way:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 39a
+ \snippet code/src_corelib_kernel_qobject.cpp 39a
The declaration of the flags themselves is performed in the public section
of the QLibrary class itself, using the \l Q_DECLARE_FLAGS() macro:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 39b
+ \snippet code/src_corelib_kernel_qobject.cpp 39b
\note This macro takes care of registering individual flag values
with the meta-object system, so it is unnecessary to use Q_ENUMS()
For example:
- \snippet doc/src/snippets/signalsandslots/signalsandslots.h 1
+ \snippet signalsandslots/signalsandslots.h 1
\codeline
- \snippet doc/src/snippets/signalsandslots/signalsandslots.h 2
- \snippet doc/src/snippets/signalsandslots/signalsandslots.h 3
+ \snippet signalsandslots/signalsandslots.h 2
+ \snippet signalsandslots/signalsandslots.h 3
\note This macro requires the class to be a subclass of QObject. Use
Q_GADGET instead of Q_OBJECT to enable the meta object system's support
be invoked via the meta-object system. The macro is written before
the return type, as shown in the following example:
- \snippet snippets/qmetaobject-invokable/window.h Window class with invokable method
+ \snippet qmetaobject-invokable/window.h Window class with invokable method
The \c invokableMethod() function is marked up using Q_INVOKABLE, causing
it to be registered with the meta-object system and enabling it to be
Example:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 44
+ \snippet code/src_corelib_kernel_qobject.cpp 44
This example ensures that the label always displays the current
line edit text.
scenes. If you try to use a queued connection and get the error
message
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 25
+ \snippet code/src_corelib_kernel_qobject.cpp 25
make sure to declare the argument type with Q_DECLARE_METATYPE
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 45
+ \snippet code/src_corelib_kernel_qobject.cpp 45
If your compiler support C++11 lambda expressions, you can use them:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 46
+ \snippet code/src_corelib_kernel_qobject.cpp 46
The connection will automatically disconnect if the sender is destroyed.
*/
\list 1
\li Disconnect everything connected to an object's signals:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 26
+ \snippet code/src_corelib_kernel_qobject.cpp 26
\li Disconnect everything connected to a specific signal:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 47
+ \snippet code/src_corelib_kernel_qobject.cpp 47
\li Disconnect a specific receiver:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 30
+ \snippet code/src_corelib_kernel_qobject.cpp 30
\li Disconnect a connection from one specific signal to a specific slot:
- \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 48
+ \snippet code/src_corelib_kernel_qobject.cpp 48
\endlist
Returns true if this cleanup handler is empty or if all objects in
this cleanup handler have been destroyed; otherwise return false.
- \sa add() remove() clear()
+ \sa add(), remove(), clear()
*/
bool QObjectCleanupHandler::isEmpty() const
{
Example:
- \snippet doc/src/snippets/pointer/pointer.cpp 0
+ \snippet pointer/pointer.cpp 0
\dots
- \snippet doc/src/snippets/pointer/pointer.cpp 1
- \snippet doc/src/snippets/pointer/pointer.cpp 2
+ \snippet pointer/pointer.cpp 1
+ \snippet pointer/pointer.cpp 2
If the QLabel is deleted in the meantime, the \c label variable
will hold 0 instead of an invalid address, and the last line will
the shared memory segment, the detach() operation destroys the
shared memory segment.
- \sa detach() isAttached()
+ \sa detach(), isAttached()
*/
QSharedMemory::~QSharedMemory()
{
segment, it will \l {detach()} {detach} from it before setting the new key.
This function does not do an attach().
- \sa key() nativeKey() isAttached()
+ \sa key(), nativeKey(), isAttached()
*/
void QSharedMemory::setKey(const QString &key)
{
The application will not be portable if you set a native key.
- \sa nativeKey() key() isAttached()
+ \sa nativeKey(), key(), isAttached()
*/
void QSharedMemory::setNativeKey(const QString &key)
{
You can find the native, platform specific, key used by the operating system
by calling nativeKey().
- \sa setKey() setNativeKey()
+ \sa setKey(), setNativeKey()
*/
QString QSharedMemory::key() const
{
You can use the native key to access shared memory segments that have not
been created by Qt, or to grant shared memory access to non-Qt applications.
- \sa setKey() setNativeKey()
+ \sa setKey(), setNativeKey()
*/
QString QSharedMemory::nativeKey() const
{
Returns the size of the attached shared memory segment. If no shared
memory segment is attached, 0 is returned.
- \sa create() attach()
+ \sa create(), attach()
*/
int QSharedMemory::size() const
{
the shared memory, and remember to release the lock with unlock()
after you are done.
- \sa attach() create()
+ \sa attach(), create()
*/
const void* QSharedMemory::constData() const
{
signal, \c clicked(), which is emitted with the text of the button
that was clicked:
- \snippet doc/src/snippets/qsignalmapper/buttonwidget.h 0
- \snippet doc/src/snippets/qsignalmapper/buttonwidget.h 1
+ \snippet qsignalmapper/buttonwidget.h 0
+ \snippet qsignalmapper/buttonwidget.h 1
The only function that we need to implement is the constructor:
- \snippet doc/src/snippets/qsignalmapper/buttonwidget.cpp 0
- \snippet doc/src/snippets/qsignalmapper/buttonwidget.cpp 1
- \snippet doc/src/snippets/qsignalmapper/buttonwidget.cpp 2
+ \snippet qsignalmapper/buttonwidget.cpp 0
+ \snippet qsignalmapper/buttonwidget.cpp 1
+ \snippet qsignalmapper/buttonwidget.cpp 2
A list of texts is passed to the constructor. A signal mapper is
constructed and for each text in the list a QPushButton is
can use to use the same semaphore.
Example: Create a system semaphore
- \snippet doc/src/snippets/code/src_corelib_kernel_qsystemsemaphore.cpp 0
+ \snippet code/src_corelib_kernel_qsystemsemaphore.cpp 0
A typical application of system semaphores is for controlling access
to a circular buffer shared by a producer process and a consumer
Example: Create a system semaphore having five resources; acquire
them all and then release them all.
- \snippet doc/src/snippets/code/src_corelib_kernel_qsystemsemaphore.cpp 1
+ \snippet code/src_corelib_kernel_qsystemsemaphore.cpp 1
This function can also "create" resources. For example, immediately
following the sequence of statements above, suppose we add the
statement:
- \snippet doc/src/snippets/code/src_corelib_kernel_qsystemsemaphore.cpp 2
+ \snippet code/src_corelib_kernel_qsystemsemaphore.cpp 2
Ten new resources are now guarded by the semaphore, in addition to
the five that already existed. You would not normally use this
Example for a one second (1000 millisecond) timer (from the
\l{widgets/analogclock}{Analog Clock} example):
- \snippet examples/widgets/analogclock/analogclock.cpp 4
- \snippet examples/widgets/analogclock/analogclock.cpp 5
- \snippet examples/widgets/analogclock/analogclock.cpp 6
+ \snippet widgets/analogclock/analogclock.cpp 4
+ \snippet widgets/analogclock/analogclock.cpp 5
+ \snippet widgets/analogclock/analogclock.cpp 6
From then on, the \c update() slot is called every second.
QTimer::singleShot() function to call a slot after a specified
interval:
- \snippet doc/src/snippets/timers/timers.cpp 3
+ \snippet timers/timers.cpp 3
In multithreaded applications, you can use QTimer in any thread
that has an event loop. To start an event loop from a non-GUI
been processed. This can be used to do heavy work while providing
a snappy user interface:
- \snippet doc/src/snippets/timers/timers.cpp 4
- \snippet doc/src/snippets/timers/timers.cpp 5
- \snippet doc/src/snippets/timers/timers.cpp 6
+ \snippet timers/timers.cpp 4
+ \snippet timers/timers.cpp 5
+ \snippet timers/timers.cpp 6
\c processOneThing() will from then on be called repeatedly. It
should be written in such a way that it always returns quickly
create a local QTimer object.
Example:
- \snippet doc/src/snippets/code/src_corelib_kernel_qtimer.cpp 0
+ \snippet code/src_corelib_kernel_qtimer.cpp 0
This sample program automatically terminates after 10 minutes
(600,000 milliseconds).
it via QObject::tr(). Here's the \c main() function from the
\l{linguist/hellotr}{Hello tr()} example:
- \snippet examples/linguist/hellotr/main.cpp 2
+ \snippet linguist/hellotr/main.cpp 2
Note that the translator must be created \e before the
application's widgets.
Here is some example code to demonstrate the use of QVariant:
- \snippet doc/src/snippets/code/src_corelib_kernel_qvariant.cpp 0
+ \snippet code/src_corelib_kernel_qvariant.cpp 0
You can even store QList<QVariant> and QMap<QString, QVariant>
values in a variant, so you can easily construct arbitrarily
have a defined type with no value set. However, note that QVariant
types can only be cast when they have had a value set.
- \snippet doc/src/snippets/code/src_corelib_kernel_qvariant.cpp 1
+ \snippet code/src_corelib_kernel_qvariant.cpp 1
QVariant can be extended to support other types than those
mentioned in the \l Type enum. See the \l QMetaType documentation
toColor() function. Instead, you can use the QVariant::value() or
the qvariant_cast() template function. For example:
- \snippet doc/src/snippets/code/src_corelib_kernel_qvariant.cpp 2
+ \snippet code/src_corelib_kernel_qvariant.cpp 2
The inverse conversion (e.g., from QColor to QVariant) is
automatic for all data types supported by QVariant, including
GUI-related types:
- \snippet doc/src/snippets/code/src_corelib_kernel_qvariant.cpp 3
+ \snippet code/src_corelib_kernel_qvariant.cpp 3
\section1 Using canConvert() and convert() Consecutively
}
/*!
- \fn convert(const int type, void *ptr) const
+ \fn bool QVariant::convert(const int type, void *ptr) const
\internal
Created for qvariant_cast() usage
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_kernel_qvariant.cpp 4
+ \snippet code/src_corelib_kernel_qvariant.cpp 4
\sa value(), fromValue(), canConvert()
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_kernel_qvariant.cpp 5
+ \snippet code/src_corelib_kernel_qvariant.cpp 5
\sa setValue(), fromValue(), canConvert()
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_kernel_qvariant.cpp 6
+ \snippet code/src_corelib_kernel_qvariant.cpp 6
\sa convert()
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_kernel_qvariant.cpp 7
+ \snippet code/src_corelib_kernel_qvariant.cpp 7
\note If you are working with custom types, you should use
the Q_DECLARE_METATYPE() macro to register your custom type.
For example, a QObject pointer can be stored in a variant with the
following code:
- \snippet doc/src/snippets/code/src_corelib_kernel_qvariant.cpp 8
+ \snippet code/src_corelib_kernel_qvariant.cpp 8
\sa QVariant::fromValue()
*/
\threadsafe
- \snippet doc/src/snippets/code/src_corelib_mimetype_qmimedatabase.cpp 0
+ \snippet code/src_corelib_mimetype_qmimedatabase.cpp 0
\sa QMimeType
*/
symbol is not defined, the function pointer will be 0 and won't be
called.
- \snippet doc/src/snippets/code/src_corelib_plugin_qlibrary.cpp 0
+ \snippet code/src_corelib_plugin_qlibrary.cpp 0
The symbol must be exported as a C function from the library for
resolve() to work. This means that the function must be wrapped in
use if you just want to call a function in a library without
explicitly loading the library first:
- \snippet doc/src/snippets/code/src_corelib_plugin_qlibrary.cpp 1
+ \snippet code/src_corelib_plugin_qlibrary.cpp 1
\sa QPluginLoader
*/
not be resolved or if the library could not be loaded.
Example:
- \snippet doc/src/snippets/code/src_corelib_plugin_qlibrary.cpp 2
+ \snippet code/src_corelib_plugin_qlibrary.cpp 2
The symbol must be exported as a C function from the library. This
means that the function must be wrapped in an \c{extern "C"} if
also explicitly export the function from the DLL using the
\c{__declspec(dllexport)} compiler directive, for example:
- \snippet doc/src/snippets/code/src_corelib_plugin_qlibrary.cpp 3
+ \snippet code/src_corelib_plugin_qlibrary.cpp 3
with \c MY_EXPORT defined as
- \snippet doc/src/snippets/code/src_corelib_plugin_qlibrary.cpp 4
+ \snippet code/src_corelib_plugin_qlibrary.cpp 4
*/
QFunctionPointer QLibrary::resolve(const char *symbol)
{
to the interface class called \a ClassName. The \a Identifier must
be unique. For example:
- \snippet examples/tools/plugandpaint/interfaces.h 3
+ \snippet tools/plugandpaint/interfaces.h 3
This macro is normally used right after the class definition for
\a ClassName, in a header file. See the
If you want to use Q_DECLARE_INTERFACE with interface classes
declared in a namespace then you have to make sure the Q_DECLARE_INTERFACE
is not inside a namespace though. For example:
- \snippet doc/src/snippets/code/doc_src_qplugin.cpp 0
+ \snippet code/doc_src_qplugin.cpp 0
\sa Q_INTERFACES(), Q_EXPORT_PLUGIN2(), {How to Create Qt Plugins}
*/
Example:
- \snippet doc/src/snippets/code/doc_src_qplugin.cpp 1
+ \snippet code/doc_src_qplugin.cpp 1
See the \l{tools/plugandpaint}{Plug & Paint} example for details.
Example:
- \snippet doc/src/snippets/code/doc_src_qplugin.cpp 2
+ \snippet code/doc_src_qplugin.cpp 2
Static plugins must also be included by the linker when your
application is built. For Qt's predefined plugins,
you can use the \c QTPLUGIN to add
the required plugins to your build. For example:
- \snippet doc/src/snippets/code/doc_src_qplugin.pro 3
+ \snippet code/doc_src_qplugin.pro 3
\sa {Static Plugins}, {How to Create Qt Plugins}, {Using qmake}
*/
b8.
Example:
- \snippet doc/src/snippets/code/src_corelib_plugin_quuid.cpp 0
+ \snippet code/src_corelib_plugin_quuid.cpp 0
*/
#ifndef QT_NO_QUUID_STRING
/*!
\since 5.0
- \fn QUuid::createUuidV3()
+ \fn QUuid QUuid::createUuidV3(const QUuid &ns, const QByteArray &baseData);
This functions returns a new UUID with variant QUuid::DCE and version QUuid::MD5.
\a ns is the namespace and \a name is the name as described by RFC 4122.
/*!
\since 5.0
- \fn QUuid::createUuidV5()
+ \fn QUuid QUuid::createUuidV5(const QUuid &ns, const QByteArray &baseData);
This functions returns a new UUID with variant QUuid::DCE and version QUuid::SHA1.
\a ns is the namespace and \a name is the name as described by RFC 4122.
The following snippet shows a state machine that will finish when a button
is clicked:
- \snippet doc/src/snippets/code/src_corelib_statemachine_qstatemachine.cpp simple state machine
+ \snippet code/src_corelib_statemachine_qstatemachine.cpp simple state machine
This code example uses QState, which inherits QAbstractState. The
QState class provides a state that you can use to set properties
\value RestoreProperties The state machine should save the initial values of properties
and restore them later.
- \sa QStateMachine::globalRestorePolicy QState::assignProperty()
+ \sa QStateMachine::globalRestorePolicy, QState::assignProperty()
*/
functions allow you to implement your own implicitly shared
classes.
- \snippet doc/src/snippets/code/src_corelib_thread_qatomic.cpp 0
+ \snippet code/src_corelib_thread_qatomic.cpp 0
\section2 Memory ordering
nothing and return false. This operation equates to the following
code:
- \snippet doc/src/snippets/code/src_corelib_thread_qatomic.cpp 1
+ \snippet code/src_corelib_thread_qatomic.cpp 1
There are 4 test-and-set functions: testAndSetRelaxed(),
testAndSetAcquire(), testAndSetRelease(), and
QAtomicInt and then assign a new value, returning the original
value. This operation equates to the following code:
- \snippet doc/src/snippets/code/src_corelib_thread_qatomic.cpp 2
+ \snippet code/src_corelib_thread_qatomic.cpp 2
There are 4 fetch-and-store functions: fetchAndStoreRelaxed(),
fetchAndStoreAcquire(), fetchAndStoreRelease(), and
returning the original value. This operation equates to the
following code:
- \snippet doc/src/snippets/code/src_corelib_thread_qatomic.cpp 3
+ \snippet code/src_corelib_thread_qatomic.cpp 3
There are 4 fetch-and-add functions: fetchAndAddRelaxed(),
fetchAndAddAcquire(), fetchAndAddRelease(), and
Constructs a copy of \a other.
*/
-/*! \fn QAtomicInt &QAtomicInt::operator=(int value)
-
- Assigns the \a value to this QAtomicInt and returns a reference to
- this QAtomicInt.
-*/
-
/*! \fn QAtomicInt &QAtomicInt::operator=(const QAtomicInt &other)
Assigns \a other to this QAtomicInt and returns a reference to
this QAtomicInt.
*/
-/*! \fn bool QAtomicInt::operator==(int value) const
-
- Returns true if the \a value is equal to the value in this
- QAtomicInt; otherwise returns false.
-*/
-
-/*! \fn bool QAtomicInt::operator!=(int value) const
-
- Returns true if the value of this QAtomicInt is not equal to \a
- value; otherwise returns false.
-*/
-
-/*! \fn bool QAtomicInt::operator!() const
-
- Returns true is the value of this QAtomicInt is zero; otherwise
- returns false.
-*/
-
-/*! \fn QAtomicInt::operator int() const
-
- Returns the value stored by the QAtomicInt object as an integer.
-*/
-
/*! \fn bool QAtomicInt::isReferenceCountingNative()
Returns true if reference counting is implemented using atomic
these functions do nothing and return false. This operation
equates to the following code:
- \snippet doc/src/snippets/code/src_corelib_thread_qatomic.cpp 4
+ \snippet code/src_corelib_thread_qatomic.cpp 4
There are 4 test-and-set functions: testAndSetRelaxed(),
testAndSetAcquire(), testAndSetRelease(), and
QAtomicPointer and then assign a new value, returning the original
value. This operation equates to the following code:
- \snippet doc/src/snippets/code/src_corelib_thread_qatomic.cpp 5
+ \snippet code/src_corelib_thread_qatomic.cpp 5
There are 4 fetch-and-store functions: fetchAndStoreRelaxed(),
fetchAndStoreAcquire(), fetchAndStoreRelease(), and
returning the original value. This operation equates to the
following code:
- \snippet doc/src/snippets/code/src_corelib_thread_qatomic.cpp 6
+ \snippet code/src_corelib_thread_qatomic.cpp 6
There are 4 fetch-and-add functions: fetchAndAddRelaxed(),
fetchAndAddAcquire(), fetchAndAddRelease(), and
Constructs a copy of \a other.
*/
-/*! \fn QAtomicPointer<T> &QAtomicPointer::operator=(T *value)
-
- Assigns the \a value to this QAtomicPointer and returns a
- reference to this QAtomicPointer.
-*/
-
/*! \fn QAtomicPointer<T> &QAtomicPointer::operator=(const QAtomicPointer<T> &other)
Assigns \a other to this QAtomicPointer and returns a reference to
this QAtomicPointer.
*/
-/*! \fn bool QAtomicPointer::operator==(T *value) const
-
- Returns true if the \a value is equal to the value in this
- QAtomicPointer; otherwise returns false.
-*/
-
-/*! \fn bool QAtomicPointer::operator!=(T *value) const
-
- Returns true if the value of this QAtomicPointer is not equal to
- \a value; otherwise returns false.
-*/
-
-/*! \fn bool QAtomicPointer::operator!() const
-
- Returns true is the current value of this QAtomicPointer is zero;
- otherwise returns false.
-*/
-
-/*! \fn QAtomicPointer::operator T *() const
-
- Returns the current pointer value stored by this QAtomicPointer
- object.
-*/
-
-/*! \fn T *QAtomicPointer::operator->() const
-
-*/
-
/*! \fn bool QAtomicPointer::isTestAndSetNative()
Returns true if test-and-set is implemented using atomic processor
This is a helper for the assignment operators of implicitly
shared classes. Your assignment operator should look like this:
- \snippet doc/src/snippets/code/src.corelib.thread.qatomic.h 0
+ \snippet code/src.corelib.thread.qatomic.h 0
*/
template <typename T>
inline void qAtomicAssign(T *&d, T *x)
the members and sets the refcount to 1. After that, your detach
function should look like this:
- \snippet doc/src/snippets/code/src.corelib.thread.qatomic.h 1
+ \snippet code/src.corelib.thread.qatomic.h 1
*/
template <typename T>
inline void qAtomicDetach(T *&d)
QT_BEGIN_NAMESPACE
-/*!
+/*
\class QBasicMutex
\brief QMutex POD
\internal
For example, say there is a method that prints a message to the
user on two lines:
- \snippet doc/src/snippets/code/src_corelib_thread_qmutex.cpp 0
+ \snippet code/src_corelib_thread_qmutex.cpp 0
If these two methods are called in succession, the following happens:
- \snippet doc/src/snippets/code/src_corelib_thread_qmutex.cpp 1
+ \snippet code/src_corelib_thread_qmutex.cpp 1
If these two methods are called simultaneously from two threads then the
following sequence could result:
- \snippet doc/src/snippets/code/src_corelib_thread_qmutex.cpp 2
+ \snippet code/src_corelib_thread_qmutex.cpp 2
If we add a mutex, we should get the result we want:
- \snippet doc/src/snippets/code/src_corelib_thread_qmutex.cpp 3
+ \snippet code/src_corelib_thread_qmutex.cpp 3
Then only one thread can modify \c number at any given time and
the result is correct. This is a trivial example, of course, but
\sa unlock()
*/
-/*!\fn bool QMutex::trylock()
- Attempts to lock the mutex. If the lock was obtained, this function
- returns true. If another thread has locked the mutex, this
- function returns false immediately.
-
- If the lock was obtained, the mutex must be unlocked with unlock()
- before another thread can successfully lock it.
-
- Calling this function multiple times on the same mutex from the
- same thread is allowed if this mutex is a
- \l{QMutex::Recursive}{recursive mutex}. If this mutex is a
- \l{QMutex::NonRecursive}{non-recursive mutex}, this function will
- \e always return false when attempting to lock the mutex
- recursively.
-
- \sa lock(), unlock()
-*/
-
/*! \fn bool QMutex::tryLock(int timeout)
- \overload
Attempts to lock the mutex. This function returns true if the lock
was obtained; otherwise it returns false. If another thread has
For example, this complex function locks a QMutex upon entering
the function and unlocks the mutex at all the exit points:
- \snippet doc/src/snippets/code/src_corelib_thread_qmutex.cpp 4
+ \snippet code/src_corelib_thread_qmutex.cpp 4
This example function will get more complicated as it is
developed, which increases the likelihood that errors will occur.
Using QMutexLocker greatly simplifies the code, and makes it more
readable:
- \snippet doc/src/snippets/code/src_corelib_thread_qmutex.cpp 5
+ \snippet code/src_corelib_thread_qmutex.cpp 5
Now, the mutex will always be unlocked when the QMutexLocker
object is destroyed (when the function returns since \c locker is
for code that needs access to the mutex, such as
QWaitCondition::wait(). For example:
- \snippet doc/src/snippets/code/src_corelib_thread_qmutex.cpp 6
+ \snippet code/src_corelib_thread_qmutex.cpp 6
\sa QReadLocker, QWriteLocker, QMutex
*/
*/
/*!
- \fn QMutex *QMutexLocker::mutex() const
-
- Returns a pointer to the mutex that was locked in the
- constructor.
-*/
-
-/*!
\fn void QMutexLocker::unlock()
Unlocks this mutex locker. You can use \c relock() to lock
#else // QT_NO_THREAD or qdoc
-
class Q_CORE_EXPORT QMutex
{
public:
For example, consider this simple class:
- \snippet doc/src/snippets/code/src_corelib_thread_qmutexpool.cpp 0
+ \snippet code/src_corelib_thread_qmutexpool.cpp 0
Adding a QMutex member to the Number class does not make sense,
because it is so small. However, in order to ensure that access to
Code to calculate the square of a number would then look something
like this:
- \snippet doc/src/snippets/code/src_corelib_thread_qmutexpool.cpp 1
+ \snippet code/src_corelib_thread_qmutexpool.cpp 1
This function will safely calculate the square of a number, since
it uses a mutex from a QMutexPool. The mutex is locked and
Example:
- \snippet doc/src/snippets/code/src_corelib_thread_qreadwritelock.cpp 0
+ \snippet code/src_corelib_thread_qreadwritelock.cpp 0
To ensure that writers aren't blocked forever by readers, readers
attempting to obtain a lock will not succeed if there is a blocked
thread if any thread (including the current) has locked for
writing.
- \sa unlock() lockForWrite() tryLockForRead()
+ \sa unlock(), lockForWrite(), tryLockForRead()
*/
void QReadWriteLock::lockForRead()
{
If the lock was obtained, the lock must be unlocked with unlock()
before another thread can successfully lock it.
- \sa unlock() lockForRead()
+ \sa unlock(), lockForRead()
*/
bool QReadWriteLock::tryLockForRead()
{
If the lock was obtained, the lock must be unlocked with unlock()
before another thread can successfully lock it.
- \sa unlock() lockForRead()
+ \sa unlock(), lockForRead()
*/
bool QReadWriteLock::tryLockForRead(int timeout)
{
Locks the lock for writing. This function will block the current
thread if another thread has locked for reading or writing.
- \sa unlock() lockForRead() tryLockForWrite()
+ \sa unlock(), lockForRead(), tryLockForWrite()
*/
void QReadWriteLock::lockForWrite()
{
If the lock was obtained, the lock must be unlocked with unlock()
before another thread can successfully lock it.
- \sa unlock() lockForWrite()
+ \sa unlock(), lockForWrite()
*/
bool QReadWriteLock::tryLockForWrite()
{
If the lock was obtained, the lock must be unlocked with unlock()
before another thread can successfully lock it.
- \sa unlock() lockForWrite()
+ \sa unlock(), lockForWrite()
*/
bool QReadWriteLock::tryLockForWrite(int timeout)
{
Attempting to unlock a lock that is not locked is an error, and will result
in program termination.
- \sa lockForRead() lockForWrite() tryLockForRead() tryLockForWrite()
+ \sa lockForRead(), lockForWrite(), tryLockForRead(), tryLockForWrite()
*/
void QReadWriteLock::unlock()
{
Here's an example that uses QReadLocker to lock and unlock a
read-write lock for reading:
- \snippet doc/src/snippets/code/src_corelib_thread_qreadwritelock.cpp 1
+ \snippet code/src_corelib_thread_qreadwritelock.cpp 1
It is equivalent to the following code:
- \snippet doc/src/snippets/code/src_corelib_thread_qreadwritelock.cpp 2
+ \snippet code/src_corelib_thread_qreadwritelock.cpp 2
The QMutexLocker documentation shows examples where the use of a
locker object greatly simplifies programming.
Here's an example that uses QWriteLocker to lock and unlock a
read-write lock for writing:
- \snippet doc/src/snippets/code/src_corelib_thread_qreadwritelock.cpp 3
+ \snippet code/src_corelib_thread_qreadwritelock.cpp 3
It is equivalent to the following code:
- \snippet doc/src/snippets/code/src_corelib_thread_qreadwritelock.cpp 4
+ \snippet code/src_corelib_thread_qreadwritelock.cpp 4
The QMutexLocker documentation shows examples where the use of a
locker object greatly simplifies programming.
Example:
- \snippet doc/src/snippets/code/src_corelib_thread_qsemaphore.cpp 0
+ \snippet code/src_corelib_thread_qsemaphore.cpp 0
A typical application of semaphores is for controlling access to
a circular buffer shared by a producer thread and a consumer
This function can be used to "create" resources as well. For
example:
- \snippet doc/src/snippets/code/src_corelib_thread_qsemaphore.cpp 1
+ \snippet code/src_corelib_thread_qsemaphore.cpp 1
\sa acquire(), available()
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_thread_qsemaphore.cpp 2
+ \snippet code/src_corelib_thread_qsemaphore.cpp 2
\sa acquire()
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_thread_qsemaphore.cpp 3
+ \snippet code/src_corelib_thread_qsemaphore.cpp 3
\sa acquire()
*/
below). To create your own threads, subclass QThread and
reimplement run(). For example:
- \snippet doc/src/snippets/code/src_corelib_thread_qthread.cpp 0
+ \snippet code/src_corelib_thread_qthread.cpp 0
This will create a QTcpSocket in the thread and then execute the
thread's event loop. Use the start() method to begin execution.
is not running then the next call to QThread::exec() will also return
immediately.
- \sa quit() QEventLoop
+ \sa quit(), QEventLoop
*/
void QThread::exit(int returnCode)
{
This function does nothing if the thread does not have an event
loop.
- \sa exit() QEventLoop
+ \sa exit(), QEventLoop
*/
void QThread::quit()
{ exit(); }
work. Returning from this method will end the execution of the
thread.
- \sa start() wait()
+ \sa start(), wait()
*/
void QThread::run()
{
(such as on Linux, see http://linux.die.net/man/2/sched_setscheduler
for more details).
- \sa Priority priority() start()
+ \sa Priority, priority(), start()
*/
/*!
Returns the priority for a running thread. If the thread is not
running, this function returns \c InheritPriority.
- \sa Priority setPriority() start()
+ \sa Priority, setPriority(), start()
*/
QThread::Priority QThread::priority() const
{
}
}
-/*! \internal
+/*
This function loops and waits for native adopted threads to finish.
When this happens it derefs the QThreadData for the adopted thread
to make sure it gets cleaned up properly.
the run() virtual function. Then create an object of that class and pass
it to QThreadPool::start().
- \snippet doc/src/snippets/code/src_corelib_concurrent_qthreadpool.cpp 0
+ \snippet code/src_corelib_concurrent_qthreadpool.cpp 0
QThreadPool deletes the QRunnable automatically by default. Use
QRunnable::setAutoDelete() to change the auto-deletion flag.
removeFromCache() functions. The cache is automatically
deleted when the calling thread exits.
- \snippet doc/src/snippets/threads/threads.cpp 7
- \snippet doc/src/snippets/threads/threads.cpp 8
- \snippet doc/src/snippets/threads/threads.cpp 9
+ \snippet threads/threads.cpp 7
+ \snippet threads/threads.cpp 8
+ \snippet threads/threads.cpp 9
\section1 Caveats
split into a thread, each of which would have a
\l{QThread::run()}{run()} body like this:
- \snippet doc/src/snippets/code/src_corelib_thread_qwaitcondition_unix.cpp 0
+ \snippet code/src_corelib_thread_qwaitcondition_unix.cpp 0
Here, the \c keyPressed variable is a global variable of type
QWaitCondition.
A fourth thread would read key presses and wake the other three
threads up every time it receives one, like this:
- \snippet doc/src/snippets/code/src_corelib_thread_qwaitcondition_unix.cpp 1
+ \snippet code/src_corelib_thread_qwaitcondition_unix.cpp 1
The order in which the three threads are woken up is undefined.
Also, if some of the threads are still in \c do_something() when
counter and a QMutex to guard it. For example, here's the new
code for the worker threads:
- \snippet doc/src/snippets/code/src_corelib_thread_qwaitcondition_unix.cpp 2
+ \snippet code/src_corelib_thread_qwaitcondition_unix.cpp 2
Here's the code for the fourth thread:
- \snippet doc/src/snippets/code/src_corelib_thread_qwaitcondition_unix.cpp 3
+ \snippet code/src_corelib_thread_qwaitcondition_unix.cpp 3
The mutex is necessary because the results of two threads
attempting to change the value of the same variable
a particular value. If you need that functionality, you can use
qFill():
- \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 0
+ \snippet code/doc_src_qalgorithms.cpp 0
qFill() takes a begin iterator, an end iterator, and a value.
In the example above, we pass \c list.begin() and \c list.end()
as the begin and end iterators, but this doesn't have to be
the case:
- \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 1
+ \snippet code/doc_src_qalgorithms.cpp 1
Different algorithms can have different requirements for the
iterators they accept. For example, qFill() accepts two
name_table array and return the corresponding Unicode value from
the \c value_table if the entity is recognized:
- \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 2
+ \snippet code/doc_src_qalgorithms.cpp 2
This kind of code is for advanced users only; for most
applications, a QMap- or QHash-based approach would work just as
well:
- \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 3
+ \snippet code/doc_src_qalgorithms.cpp 3
\section1 Types of Iterators
position \a begin2 + 1; and so on.
Example:
- \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 4
+ \snippet code/doc_src_qalgorithms.cpp 4
\sa qCopyBackward(), {input iterators}, {output iterators}
*/
at position \a end2 - 2; and so on.
Example:
- \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 5
+ \snippet code/doc_src_qalgorithms.cpp 5
\sa qCopy(), {bidirectional iterators}
*/
items compare equal; otherwise returns false.
Example:
- \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 6
+ \snippet code/doc_src_qalgorithms.cpp 6
This function requires the item type (in the example above,
QString) to implement \c operator==().
Fills the range [\a begin, \a end) with \a value.
Example:
- \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 7
+ \snippet code/doc_src_qalgorithms.cpp 7
\sa qCopy(), {forward iterators}
*/
value isn't found.
Example:
- \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 8
+ \snippet code/doc_src_qalgorithms.cpp 8
This function requires the item type (in the example above,
QString) to implement \c operator==().
Example:
- \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 9
+ \snippet code/doc_src_qalgorithms.cpp 9
This function requires the item type (in the example above,
\c int) to implement \c operator==().
Exchanges the values of variables \a var1 and \a var2.
Example:
- \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 10
+ \snippet code/doc_src_qalgorithms.cpp 10
*/
/*! \fn void qSort(RandomAccessIterator begin, RandomAccessIterator end)
using the quicksort algorithm.
Example:
- \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 11
+ \snippet code/doc_src_qalgorithms.cpp 11
The sort algorithm is efficient on large data sets. It operates
in \l {linear-logarithmic time}, O(\e{n} log \e{n}).
For example, here's how to sort the strings in a QStringList
in case-insensitive alphabetical order:
- \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 12
+ \snippet code/doc_src_qalgorithms.cpp 12
To sort values in reverse order, pass
\l{qGreater()}{qGreater<T>()} as the \a lessThan parameter. For
example:
- \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 13
+ \snippet code/doc_src_qalgorithms.cpp 13
If neither of the two items is "less than" the other, the items are
taken to be equal. It is then undefined which one of the two
following code shows how to sort a list of strings case
insensitively using QMap:
- \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 14
+ \snippet code/doc_src_qalgorithms.cpp 14
\sa QMap
*/
property is often useful when sorting user-visible data.
Example:
- \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 15
+ \snippet code/doc_src_qalgorithms.cpp 15
The sort algorithm is efficient on large data sets. It operates
in \l {linear-logarithmic time}, O(\e{n} log \e{n}).
For example, here's how to sort the strings in a QStringList
in case-insensitive alphabetical order:
- \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 16
+ \snippet code/doc_src_qalgorithms.cpp 16
Note that earlier versions of Qt allowed using a lessThan function that took its
arguments by non-const reference. From 4.3 and on this is no longer possible,
\l{qGreater()}{qGreater<T>()} as the \a lessThan parameter. For
example:
- \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 17
+ \snippet code/doc_src_qalgorithms.cpp 17
If neither of the two items is "less than" the other, the items are
taken to be equal. The item that appeared before the other in the
ascending order; see qSort().
Example:
- \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 18
+ \snippet code/doc_src_qalgorithms.cpp 18
This function requires the item type (in the example above,
\c{int}) to implement \c operator<().
qLowerBound() can be used in conjunction with qUpperBound() to
iterate over all occurrences of the same value:
- \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 19
+ \snippet code/doc_src_qalgorithms.cpp 19
\sa qUpperBound(), qBinaryFind()
*/
ascending order; see qSort().
Example:
- \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 20
+ \snippet code/doc_src_qalgorithms.cpp 20
This function requires the item type (in the example above,
\c{int}) to implement \c operator<().
qUpperBound() can be used in conjunction with qLowerBound() to
iterate over all occurrences of the same value:
- \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 21
+ \snippet code/doc_src_qalgorithms.cpp 21
\sa qLowerBound(), qBinaryFind()
*/
finer control.
Example:
- \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 22
+ \snippet code/doc_src_qalgorithms.cpp 22
This function requires the item type (in the example above,
QString) to implement \c operator<().
example, \c{QWidget *}).
Example:
- \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 23
+ \snippet code/doc_src_qalgorithms.cpp 23
Notice that qDeleteAll() doesn't remove the items from the
container; it merely calls \c delete on them. In the example
Example:
- \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 24
+ \snippet code/doc_src_qalgorithms.cpp 24
\sa {qGreater()}{qGreater<T>()}
*/
Example:
- \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 25
+ \snippet code/doc_src_qalgorithms.cpp 25
\sa {qLess()}{qLess<T>()}
*/
The following code constructs a QBitArray containing 200 bits
initialized to false (0):
- \snippet doc/src/snippets/code/src_corelib_tools_qbitarray.cpp 0
+ \snippet code/src_corelib_tools_qbitarray.cpp 0
To initialize the bits to true, either pass \c true as second
argument to the constructor, or call fill() later on.
bit that can be used on the left side of an assignment. For
example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbitarray.cpp 1
+ \snippet code/src_corelib_tools_qbitarray.cpp 1
For technical reasons, it is more efficient to use testBit() and
setBit() to access bits in the array than operator[](). For
example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbitarray.cpp 2
+ \snippet code/src_corelib_tools_qbitarray.cpp 2
QBitArray supports \c{&} (\link operator&() AND\endlink), \c{|}
(\link operator|() OR\endlink), \c{^} (\link operator^()
as the built-in C++ bitwise operators of the same name. For
example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbitarray.cpp 3
+ \snippet code/src_corelib_tools_qbitarray.cpp 3
For historical reasons, QBitArray distinguishes between a null
bit array and an empty bit array. A \e null bit array is a bit
array is always empty, but an empty bit array isn't necessarily
null:
- \snippet doc/src/snippets/code/src_corelib_tools_qbitarray.cpp 4
+ \snippet code/src_corelib_tools_qbitarray.cpp 4
All functions except isNull() treat null bit arrays the same as
empty bit arrays; for example, QBitArray() compares equal to
Returns true if this bit array is null; otherwise returns false.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbitarray.cpp 5
+ \snippet code/src_corelib_tools_qbitarray.cpp 5
Qt makes a distinction between null bit arrays and empty bit
arrays for historical reasons. For most applications, what
the bit array is resized to \a size beforehand.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbitarray.cpp 6
+ \snippet code/src_corelib_tools_qbitarray.cpp 6
\sa resize()
*/
\a i < size()).
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbitarray.cpp 7
+ \snippet code/src_corelib_tools_qbitarray.cpp 7
The return value is of type QBitRef, a helper class for QBitArray.
When you get an object of type QBitRef, you can assign to
taken to be 0.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbitarray.cpp 8
+ \snippet code/src_corelib_tools_qbitarray.cpp 8
\sa operator&(), operator|=(), operator^=(), operator~()
*/
taken to be 0.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbitarray.cpp 9
+ \snippet code/src_corelib_tools_qbitarray.cpp 9
\sa operator|(), operator&=(), operator^=(), operator~()
*/
taken to be 0.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbitarray.cpp 10
+ \snippet code/src_corelib_tools_qbitarray.cpp 10
\sa operator^(), operator&=(), operator|=(), operator~()
*/
array.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbitarray.cpp 11
+ \snippet code/src_corelib_tools_qbitarray.cpp 11
\sa operator&(), operator|(), operator^()
*/
taken to be 0.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbitarray.cpp 12
+ \snippet code/src_corelib_tools_qbitarray.cpp 12
\sa QBitArray::operator&=(), operator|(), operator^()
*/
taken to be 0.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbitarray.cpp 13
+ \snippet code/src_corelib_tools_qbitarray.cpp 13
\sa QBitArray::operator|=(), operator&(), operator^()
*/
taken to be 0.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbitarray.cpp 14
+ \snippet code/src_corelib_tools_qbitarray.cpp 14
\sa QBitArray::operator^=(), operator&(), operator|()
*/
Writes bit array \a ba to stream \a out.
- \sa \link datastreamformat.html Format of the QDataStream operators \endlink
+ \sa {Serializing Qt Data Types}{Format of the QDataStream operators}
*/
QDataStream &operator<<(QDataStream &out, const QBitArray &ba)
Reads a bit array into \a ba from stream \a in.
- \sa \link datastreamformat.html Format of the QDataStream operators \endlink
+ \sa {Serializing Qt Data Types}{Format of the QDataStream operators}
*/
QDataStream &operator>>(QDataStream &in, QBitArray &ba)
char *} to its constructor. For example, the following code
creates a byte array of size 5 containing the data "Hello":
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 0
+ \snippet code/src_corelib_tools_qbytearray.cpp 0
Although the size() is 5, the byte array also maintains an extra
'\\0' character at the end so that if a function is used that
arrays, operator[]() returns a reference to a byte that can be
used on the left side of an assignment. For example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 1
+ \snippet code/src_corelib_tools_qbytearray.cpp 1
For read-only access, an alternative syntax is to use at():
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 2
+ \snippet code/src_corelib_tools_qbytearray.cpp 2
at() can be faster than operator[](), because it never causes a
\l{deep copy} to occur.
the byte data: append(), prepend(), insert(), replace(), and
remove(). For example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 3
+ \snippet code/src_corelib_tools_qbytearray.cpp 3
The replace() and remove() functions' first two arguments are the
position from which to start erasing and the number of bytes that
For example, here's a typical loop that finds all occurrences of a
particular substring:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 4
+ \snippet code/src_corelib_tools_qbytearray.cpp 4
If you simply want to check whether a QByteArray contains a
particular character or substring, use contains(). If you want to
array is always empty, but an empty byte array isn't necessarily
null:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 5
+ \snippet code/src_corelib_tools_qbytearray.cpp 5
All functions except isNull() treat null byte arrays the same as
empty byte arrays. For example, data() returns a pointer to a
automaticall unless the \l{deep copy} is created.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 6
+ \snippet code/src_corelib_tools_qbytearray.cpp 6
\sa isEmpty(), resize()
*/
Returns true if the byte array has size 0; otherwise returns false.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 7
+ \snippet code/src_corelib_tools_qbytearray.cpp 7
\sa size()
*/
'\\0' terminator.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 8
+ \snippet code/src_corelib_tools_qbytearray.cpp 8
The pointer remains valid as long as the byte array isn't
reallocated or destroyed. For read-only access, constData() is
data(), but it will corrupt the heap and cause a crash because it
does not allocate a byte for the '\\0' at the end:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 46
+ \snippet code/src_corelib_tools_qbytearray.cpp 46
This one allocates the correct amount of space:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 47
+ \snippet code/src_corelib_tools_qbytearray.cpp 47
Note: A QByteArray can store any byte values including '\\0's,
but most functions that take \c{char *} arguments assume that the
place.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 9
+ \snippet code/src_corelib_tools_qbytearray.cpp 9
The return value is of type QByteRef, a helper class for
QByteArray. When you get an object of type QByteRef, you can use
If \a pos is beyond the end of the array, nothing happens.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 10
+ \snippet code/src_corelib_tools_qbytearray.cpp 10
\sa chop(), resize(), left()
*/
array.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 11
+ \snippet code/src_corelib_tools_qbytearray.cpp 11
\sa truncate(), resize(), left()
*/
returns a reference to this byte array.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 12
+ \snippet code/src_corelib_tools_qbytearray.cpp 12
Note: QByteArray is an \l{implicitly shared} class. Consequently,
if \e this is an empty QByteArray, then \e this will just share
Returns true if this byte array is null; otherwise returns false.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 13
+ \snippet code/src_corelib_tools_qbytearray.cpp 13
Qt makes a distinction between null byte arrays and empty byte
arrays for historical reasons. For most applications, what
size \a size beforehand.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 14
+ \snippet code/src_corelib_tools_qbytearray.cpp 14
\sa resize()
*/
reference to this byte array.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 15
+ \snippet code/src_corelib_tools_qbytearray.cpp 15
This is the same as insert(0, \a ba).
Appends the byte array \a ba onto the end of this byte array.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 16
+ \snippet code/src_corelib_tools_qbytearray.cpp 16
This is the same as insert(size(), \a ba).
reference to this byte array.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 17
+ \snippet code/src_corelib_tools_qbytearray.cpp 17
\sa append(), prepend(), replace(), remove()
*/
array is truncated at position \a pos.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 18
+ \snippet code/src_corelib_tools_qbytearray.cpp 18
\sa insert(), replace()
*/
array \a after, and returns a reference to this byte array.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 19
+ \snippet code/src_corelib_tools_qbytearray.cpp 19
\sa insert(), remove()
*/
\overload
Replaces \a len bytes from index position \a pos with \a alen bytes
- from the string \a after. \a after is allowed to have '\0' characters.
+ from the string \a after. \a after is allowed to have '\\0' characters.
\since 4.7
*/
byte array \a after.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 20
+ \snippet code/src_corelib_tools_qbytearray.cpp 20
*/
QByteArray &QByteArray::replace(const QByteArray &before, const QByteArray &after)
position \a from. Returns -1 if \a ba could not be found.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 21
+ \snippet code/src_corelib_tools_qbytearray.cpp 21
\sa lastIndexOf(), contains(), count()
*/
position \a from. Returns -1 if \a ch could not be found.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 22
+ \snippet code/src_corelib_tools_qbytearray.cpp 22
\sa lastIndexOf(), contains()
*/
starts at the last byte. Returns -1 if \a ba could not be found.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 23
+ \snippet code/src_corelib_tools_qbytearray.cpp 23
\sa indexOf(), contains(), count()
*/
last (size() - 1) byte. Returns -1 if \a ch could not be found.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 24
+ \snippet code/src_corelib_tools_qbytearray.cpp 24
\sa indexOf(), contains()
*/
otherwise returns false.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 25
+ \snippet code/src_corelib_tools_qbytearray.cpp 25
\sa endsWith(), left()
*/
otherwise returns false.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 26
+ \snippet code/src_corelib_tools_qbytearray.cpp 26
\sa startsWith(), right()
*/
size().
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 27
+ \snippet code/src_corelib_tools_qbytearray.cpp 27
\sa right(), mid(), startsWith(), truncate()
*/
size().
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 28
+ \snippet code/src_corelib_tools_qbytearray.cpp 28
\sa endsWith(), left(), mid()
*/
pos until the end of the byte array.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 29
+ \snippet code/src_corelib_tools_qbytearray.cpp 29
\sa left(), right()
*/
interpreted as a Latin-1 encoded string.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 30
+ \snippet code/src_corelib_tools_qbytearray.cpp 30
\sa toUpper(), {8-bit Character Comparisons}
*/
interpreted as a Latin-1 encoded string.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 31
+ \snippet code/src_corelib_tools_qbytearray.cpp 31
\sa toLower(), {8-bit Character Comparisons}
*/
characters '\\t', '\\n', '\\v', '\\f', '\\r', and ' '.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 32
+ \snippet code/src_corelib_tools_qbytearray.cpp 32
\sa trimmed()
*/
characters '\\t', '\\n', '\\v', '\\f', '\\r', and ' '.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 33
+ \snippet code/src_corelib_tools_qbytearray.cpp 33
Unlike simplified(), trimmed() leaves internal whitespace alone.
after position \a width are removed, and the copy is returned.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 34
+ \snippet code/src_corelib_tools_qbytearray.cpp 34
\sa rightJustified()
*/
position \a width.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 35
+ \snippet code/src_corelib_tools_qbytearray.cpp 35
\sa leftJustified()
*/
If \a ok is not 0: if a conversion error occurs, *\a{ok} is set to
false; otherwise *\a{ok} is set to true.
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 36
+ \snippet code/src_corelib_tools_qbytearray.cpp 36
\note The conversion of the number is performed in the default C locale,
irrespective of the user's locale.
If \a ok is not 0: if a conversion error occurs, *\a{ok} is set to
false; otherwise *\a{ok} is set to true.
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 37
+ \snippet code/src_corelib_tools_qbytearray.cpp 37
\note The conversion of the number is performed in the default C locale,
irrespective of the user's locale.
If \a ok is not 0: if a conversion error occurs, *\a{ok} is set to
false; otherwise *\a{ok} is set to true.
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 38
+ \snippet code/src_corelib_tools_qbytearray.cpp 38
\note The conversion of the number is performed in the default C locale,
irrespective of the user's locale.
/*!
Returns a copy of the byte array, encoded as Base64.
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 39
+ \snippet code/src_corelib_tools_qbytearray.cpp 39
The algorithm used to encode Base64-encoded data is defined in \l{RFC 2045}.
be any value between 2 and 36.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 40
+ \snippet code/src_corelib_tools_qbytearray.cpp 40
\note The format of the number is not localized; the default C locale
is used irrespective of the user's locale.
any value between 2 and 36.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 41
+ \snippet code/src_corelib_tools_qbytearray.cpp 41
\note The format of the number is not localized; the default C locale
is used irrespective of the user's locale.
decimal point. With 'g' and 'G', \a prec is the maximum number of
significant digits (trailing zeroes are omitted).
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 42
+ \snippet code/src_corelib_tools_qbytearray.cpp 42
\note The format of the number is not localized; the default C locale
is used irrespective of the user's locale.
Here is an example of how to read data using a QDataStream on raw
data in memory without copying the raw data into a QByteArray:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 43
+ \snippet code/src_corelib_tools_qbytearray.cpp 43
\warning A byte array created with fromRawData() is \e not
null-terminated, unless the raw data contains a 0 character at
For example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 44
+ \snippet code/src_corelib_tools_qbytearray.cpp 44
The algorithm used to decode Base64-encoded data is defined in \l{RFC 2045}.
For example:
- \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 45
+ \snippet code/src_corelib_tools_qbytearray.cpp 45
\sa toHex()
*/
definition of a cache that stores objects of type Employee
associated with an integer key:
- \snippet doc/src/snippets/code/doc_src_qcache.cpp 0
+ \snippet code/doc_src_qcache.cpp 0
Here's how to insert an object in the cache:
- \snippet doc/src/snippets/code/doc_src_qcache.cpp 1
+ \snippet code/doc_src_qcache.cpp 1
The advantage of using QCache over some other key-based data
structure (such as QMap or QHash) is that QCache automatically
By default, QCache's maxCost() is 100. You can specify a
different value in the QCache constructor:
- \snippet doc/src/snippets/code/doc_src_qcache.cpp 2
+ \snippet code/doc_src_qcache.cpp 2
Each time you call insert(), you can specify a cost as third
argument (after the key and a pointer to the object to insert).
range 0 to 9999. This restriction may apply to locale-aware
formats as well, depending on the locale settings.
- \sa QDateTime::toString() QTime::toString()
+ \sa QDateTime::toString(), QTime::toString()
*/
QString QDate::toString(const QString& format) const
#endif //QT_NO_DATESTRING
/*!
- \fn bool setYMD(int y, int m, int d)
+ \fn bool QDate::setYMD(int y, int m, int d)
\deprecated in 5.0, use setDate() instead.
Returns a null date if the current date is invalid or the new date is
out-of-range.
- \sa addMonths() addYears() daysTo()
+ \sa addMonths(), addYears(), daysTo()
*/
QDate QDate::addDays(qint64 ndays) const
resulting month/year, this function will return a date that is the
latest valid date.
- \sa addDays() addYears()
+ \sa addDays(), addYears()
*/
QDate QDate::addMonths(int nmonths) const
Returns 0 if either date is invalid.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qdatetime.cpp 0
+ \snippet code/src_corelib_tools_qdatetime.cpp 0
\sa addDays()
*/
of characters that are enclosed in single quotes will also be
treated as text and will not be used as an expression. For example:
- \snippet doc/src/snippets/code/src_corelib_tools_qdatetime.cpp 1
+ \snippet code/src_corelib_tools_qdatetime.cpp 1
If the format is not satisfied, an invalid QDate is returned. The
expressions that don't expect leading zeroes (d, M) will be
string could have meant January 30 but the M will grab two
digits, resulting in an invalid date:
- \snippet doc/src/snippets/code/src_corelib_tools_qdatetime.cpp 2
+ \snippet code/src_corelib_tools_qdatetime.cpp 2
For any field that is not represented in the format the following
defaults are used:
The following examples demonstrate the default values:
- \snippet doc/src/snippets/code/src_corelib_tools_qdatetime.cpp 3
+ \snippet code/src_corelib_tools_qdatetime.cpp 3
\sa QDateTime::fromString(), QTime::fromString(), QDate::toString(),
QDateTime::toString(), QTime::toString()
day) is valid; otherwise returns false.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qdatetime.cpp 4
+ \snippet code/src_corelib_tools_qdatetime.cpp 4
\sa isNull(), setDate()
*/
return (y % 4 == 0 && y % 100 != 0) || y % 400 == 0;
}
-/*! \fn static QDate QDate::fromJulianDay(int jd)
+/*! \fn static QDate QDate::fromJulianDay(qint64 jd)
Converts the Julian day \a jd to a QDate.
If the datetime is invalid, an empty string will be returned.
If \a format is empty, the default format "hh:mm:ss" is used.
- \sa QDate::toString() QDateTime::toString()
+ \sa QDate::toString(), QDateTime::toString()
*/
QString QTime::toString(const QString& format) const
{
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qdatetime.cpp 5
+ \snippet code/src_corelib_tools_qdatetime.cpp 5
\sa addMSecs(), secsTo(), QDateTime::addSecs()
*/
of characters that are enclosed in single quotes will also be
treated as text and not be used as an expression.
- \snippet doc/src/snippets/code/src_corelib_tools_qdatetime.cpp 6
+ \snippet code/src_corelib_tools_qdatetime.cpp 6
If the format is not satisfied an invalid QTime is returned.
Expressions that do not expect leading zeroes to be given (h, m, s
could have meant 00:07:10, but the m will grab two digits, resulting
in an invalid time:
- \snippet doc/src/snippets/code/src_corelib_tools_qdatetime.cpp 7
+ \snippet code/src_corelib_tools_qdatetime.cpp 7
Any field that is not represented in the format will be set to zero.
For example:
- \snippet doc/src/snippets/code/src_corelib_tools_qdatetime.cpp 8
+ \snippet code/src_corelib_tools_qdatetime.cpp 8
- \sa QDateTime::fromString() QDate::fromString() QDate::toString()
- QDateTime::toString() QTime::toString()
+ \sa QDateTime::fromString(), QDate::fromString(), QDate::toString(),
+ QDateTime::toString(), QTime::toString()
*/
QTime QTime::fromString(const QString &string, const QString &format)
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qdatetime.cpp 9
+ \snippet code/src_corelib_tools_qdatetime.cpp 9
*/
bool QTime::isValid(int h, int m, int s, int ms)
/*!
Sets this time to the current time. This is practical for timing:
- \snippet doc/src/snippets/code/src_corelib_tools_qdatetime.cpp 10
+ \snippet code/src_corelib_tools_qdatetime.cpp 10
\sa restart(), elapsed(), currentTime()
*/
time zone before 1970, even if the system's time zone database
supports that information.
- \sa QDate QTime QDateTimeEdit
+ \sa QDate, QTime, QDateTimeEdit
*/
/*!
range 0 to 9999. This restriction may apply to locale-aware
formats as well, depending on the locale settings.
- \sa QDate::toString() QTime::toString() Qt::DateFormat
+ \sa QDate::toString(), QTime::toString(), Qt::DateFormat
*/
QString QDateTime::toString(Qt::DateFormat f) const
If the datetime is invalid, an empty string will be returned.
- \sa QDate::toString() QTime::toString()
+ \sa QDate::toString(), QTime::toString()
*/
QString QDateTime::toString(const QString& format) const
{
Returns 0 if either time is invalid.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qdatetime.cpp 11
+ \snippet code/src_corelib_tools_qdatetime.cpp 11
\sa addSecs(), daysTo(), QTime::secsTo()
*/
of characters that are enclosed in singlequotes will also be
treated as text and not be used as an expression.
- \snippet doc/src/snippets/code/src_corelib_tools_qdatetime.cpp 12
+ \snippet code/src_corelib_tools_qdatetime.cpp 12
If the format is not satisfied an invalid QDateTime is returned.
The expressions that don't have leading zeroes (d, M, h, m, s, z) will be
put them outside the range and/or leave too few digits for other
sections.
- \snippet doc/src/snippets/code/src_corelib_tools_qdatetime.cpp 13
+ \snippet code/src_corelib_tools_qdatetime.cpp 13
This could have meant 1 January 00:30.00 but the M will grab
two digits.
For example:
- \snippet doc/src/snippets/code/src_corelib_tools_qdatetime.cpp 14
+ \snippet code/src_corelib_tools_qdatetime.cpp 14
- \sa QDate::fromString() QTime::fromString() QDate::toString()
- QDateTime::toString() QTime::toString()
+ \sa QDate::fromString(), QTime::fromString(), QDate::toString(),
+ QDateTime::toString(), QTime::toString()
*/
QDateTime QDateTime::fromString(const QString &string, const QString &format)
\class QEasingCurve
\since 4.6
\ingroup animation
- \brief The QEasingCurve class provides easing curves for controlling animation.
+ \captionief The QEasingCurve class provides easing curves for controlling animation.
Easing curves describe a function that controls how the speed of the interpolation
between 0 and 1 should be. Easing curves allow transitions from
The type of easing curve.
- \value Linear \inlineimage qeasingcurve-linear.png
- \br
- Easing curve for a linear (t) function:
+ \value Linear \image qeasingcurve-linear.png
+ \caption Easing curve for a linear (t) function:
velocity is constant.
- \value InQuad \inlineimage qeasingcurve-inquad.png
- \br
- Easing curve for a quadratic (t^2) function:
+ \value InQuad \image qeasingcurve-inquad.png
+ \caption Easing curve for a quadratic (t^2) function:
accelerating from zero velocity.
- \value OutQuad \inlineimage qeasingcurve-outquad.png
- \br
- Easing curve for a quadratic (t^2) function:
+ \value OutQuad \image qeasingcurve-outquad.png
+ \caption Easing curve for a quadratic (t^2) function:
decelerating to zero velocity.
- \value InOutQuad \inlineimage qeasingcurve-inoutquad.png
- \br
- Easing curve for a quadratic (t^2) function:
+ \value InOutQuad \image qeasingcurve-inoutquad.png
+ \caption Easing curve for a quadratic (t^2) function:
acceleration until halfway, then deceleration.
- \value OutInQuad \inlineimage qeasingcurve-outinquad.png
- \br
- Easing curve for a quadratic (t^2) function:
+ \value OutInQuad \image qeasingcurve-outinquad.png
+ \caption Easing curve for a quadratic (t^2) function:
deceleration until halfway, then acceleration.
- \value InCubic \inlineimage qeasingcurve-incubic.png
- \br
- Easing curve for a cubic (t^3) function:
+ \value InCubic \image qeasingcurve-incubic.png
+ \caption Easing curve for a cubic (t^3) function:
accelerating from zero velocity.
- \value OutCubic \inlineimage qeasingcurve-outcubic.png
- \br
- Easing curve for a cubic (t^3) function:
+ \value OutCubic \image qeasingcurve-outcubic.png
+ \caption Easing curve for a cubic (t^3) function:
decelerating to zero velocity.
- \value InOutCubic \inlineimage qeasingcurve-inoutcubic.png
- \br
- Easing curve for a cubic (t^3) function:
+ \value InOutCubic \image qeasingcurve-inoutcubic.png
+ \caption Easing curve for a cubic (t^3) function:
acceleration until halfway, then deceleration.
- \value OutInCubic \inlineimage qeasingcurve-outincubic.png
- \br
- Easing curve for a cubic (t^3) function:
+ \value OutInCubic \image qeasingcurve-outincubic.png
+ \caption Easing curve for a cubic (t^3) function:
deceleration until halfway, then acceleration.
- \value InQuart \inlineimage qeasingcurve-inquart.png
- \br
- Easing curve for a quartic (t^4) function:
+ \value InQuart \image qeasingcurve-inquart.png
+ \caption Easing curve for a quartic (t^4) function:
accelerating from zero velocity.
- \value OutQuart \inlineimage qeasingcurve-outquart.png
- \br
+ \value OutQuart \image qeasingcurve-outquart.png
+ \caption
Easing curve for a quartic (t^4) function:
decelerating to zero velocity.
- \value InOutQuart \inlineimage qeasingcurve-inoutquart.png
- \br
+ \value InOutQuart \image qeasingcurve-inoutquart.png
+ \caption
Easing curve for a quartic (t^4) function:
acceleration until halfway, then deceleration.
- \value OutInQuart \inlineimage qeasingcurve-outinquart.png
- \br
+ \value OutInQuart \image qeasingcurve-outinquart.png
+ \caption
Easing curve for a quartic (t^4) function:
deceleration until halfway, then acceleration.
- \value InQuint \inlineimage qeasingcurve-inquint.png
- \br
+ \value InQuint \image qeasingcurve-inquint.png
+ \caption
Easing curve for a quintic (t^5) easing
in: accelerating from zero velocity.
- \value OutQuint \inlineimage qeasingcurve-outquint.png
- \br
+ \value OutQuint \image qeasingcurve-outquint.png
+ \caption
Easing curve for a quintic (t^5) function:
decelerating to zero velocity.
- \value InOutQuint \inlineimage qeasingcurve-inoutquint.png
- \br
+ \value InOutQuint \image qeasingcurve-inoutquint.png
+ \caption
Easing curve for a quintic (t^5) function:
acceleration until halfway, then deceleration.
- \value OutInQuint \inlineimage qeasingcurve-outinquint.png
- \br
+ \value OutInQuint \image qeasingcurve-outinquint.png
+ \caption
Easing curve for a quintic (t^5) function:
deceleration until halfway, then acceleration.
- \value InSine \inlineimage qeasingcurve-insine.png
- \br
+ \value InSine \image qeasingcurve-insine.png
+ \caption
Easing curve for a sinusoidal (sin(t)) function:
accelerating from zero velocity.
- \value OutSine \inlineimage qeasingcurve-outsine.png
- \br
+ \value OutSine \image qeasingcurve-outsine.png
+ \caption
Easing curve for a sinusoidal (sin(t)) function:
decelerating from zero velocity.
- \value InOutSine \inlineimage qeasingcurve-inoutsine.png
- \br
+ \value InOutSine \image qeasingcurve-inoutsine.png
+ \caption
Easing curve for a sinusoidal (sin(t)) function:
acceleration until halfway, then deceleration.
- \value OutInSine \inlineimage qeasingcurve-outinsine.png
- \br
+ \value OutInSine \image qeasingcurve-outinsine.png
+ \caption
Easing curve for a sinusoidal (sin(t)) function:
deceleration until halfway, then acceleration.
- \value InExpo \inlineimage qeasingcurve-inexpo.png
- \br
+ \value InExpo \image qeasingcurve-inexpo.png
+ \caption
Easing curve for an exponential (2^t) function:
accelerating from zero velocity.
- \value OutExpo \inlineimage qeasingcurve-outexpo.png
- \br
+ \value OutExpo \image qeasingcurve-outexpo.png
+ \caption
Easing curve for an exponential (2^t) function:
decelerating from zero velocity.
- \value InOutExpo \inlineimage qeasingcurve-inoutexpo.png
- \br
+ \value InOutExpo \image qeasingcurve-inoutexpo.png
+ \caption
Easing curve for an exponential (2^t) function:
acceleration until halfway, then deceleration.
- \value OutInExpo \inlineimage qeasingcurve-outinexpo.png
- \br
+ \value OutInExpo \image qeasingcurve-outinexpo.png
+ \caption
Easing curve for an exponential (2^t) function:
deceleration until halfway, then acceleration.
- \value InCirc \inlineimage qeasingcurve-incirc.png
- \br
+ \value InCirc \image qeasingcurve-incirc.png
+ \caption
Easing curve for a circular (sqrt(1-t^2)) function:
accelerating from zero velocity.
- \value OutCirc \inlineimage qeasingcurve-outcirc.png
- \br
+ \value OutCirc \image qeasingcurve-outcirc.png
+ \caption
Easing curve for a circular (sqrt(1-t^2)) function:
decelerating from zero velocity.
- \value InOutCirc \inlineimage qeasingcurve-inoutcirc.png
- \br
+ \value InOutCirc \image qeasingcurve-inoutcirc.png
+ \caption
Easing curve for a circular (sqrt(1-t^2)) function:
acceleration until halfway, then deceleration.
- \value OutInCirc \inlineimage qeasingcurve-outincirc.png
- \br
+ \value OutInCirc \image qeasingcurve-outincirc.png
+ \caption
Easing curve for a circular (sqrt(1-t^2)) function:
deceleration until halfway, then acceleration.
- \value InElastic \inlineimage qeasingcurve-inelastic.png
- \br
+ \value InElastic \image qeasingcurve-inelastic.png
+ \caption
Easing curve for an elastic
(exponentially decaying sine wave) function:
accelerating from zero velocity. The peak amplitude
can be set with the \e amplitude parameter, and the
period of decay by the \e period parameter.
- \value OutElastic \inlineimage qeasingcurve-outelastic.png
- \br
+ \value OutElastic \image qeasingcurve-outelastic.png
+ \caption
Easing curve for an elastic
(exponentially decaying sine wave) function:
decelerating from zero velocity. The peak amplitude
can be set with the \e amplitude parameter, and the
period of decay by the \e period parameter.
- \value InOutElastic \inlineimage qeasingcurve-inoutelastic.png
- \br
+ \value InOutElastic \image qeasingcurve-inoutelastic.png
+ \caption
Easing curve for an elastic
(exponentially decaying sine wave) function:
acceleration until halfway, then deceleration.
- \value OutInElastic \inlineimage qeasingcurve-outinelastic.png
- \br
+ \value OutInElastic \image qeasingcurve-outinelastic.png
+ \caption
Easing curve for an elastic
(exponentially decaying sine wave) function:
deceleration until halfway, then acceleration.
- \value InBack \inlineimage qeasingcurve-inback.png
- \br
+ \value InBack \image qeasingcurve-inback.png
+ \caption
Easing curve for a back (overshooting
cubic function: (s+1)*t^3 - s*t^2) easing in:
accelerating from zero velocity.
- \value OutBack \inlineimage qeasingcurve-outback.png
- \br
+ \value OutBack \image qeasingcurve-outback.png
+ \caption
Easing curve for a back (overshooting
cubic function: (s+1)*t^3 - s*t^2) easing out:
decelerating to zero velocity.
- \value InOutBack \inlineimage qeasingcurve-inoutback.png
- \br
+ \value InOutBack \image qeasingcurve-inoutback.png
+ \caption
Easing curve for a back (overshooting
cubic function: (s+1)*t^3 - s*t^2) easing in/out:
acceleration until halfway, then deceleration.
- \value OutInBack \inlineimage qeasingcurve-outinback.png
- \br
+ \value OutInBack \image qeasingcurve-outinback.png
+ \caption
Easing curve for a back (overshooting
cubic easing: (s+1)*t^3 - s*t^2) easing out/in:
deceleration until halfway, then acceleration.
- \value InBounce \inlineimage qeasingcurve-inbounce.png
- \br
+ \value InBounce \image qeasingcurve-inbounce.png
+ \caption
Easing curve for a bounce (exponentially
decaying parabolic bounce) function: accelerating
from zero velocity.
- \value OutBounce \inlineimage qeasingcurve-outbounce.png
- \br
+ \value OutBounce \image qeasingcurve-outbounce.png
+ \caption
Easing curve for a bounce (exponentially
decaying parabolic bounce) function: decelerating
from zero velocity.
- \value InOutBounce \inlineimage qeasingcurve-inoutbounce.png
- \br
+ \value InOutBounce \image qeasingcurve-inoutbounce.png
+ \caption
Easing curve for a bounce (exponentially
decaying parabolic bounce) function easing in/out:
acceleration until halfway, then deceleration.
- \value OutInBounce \inlineimage qeasingcurve-outinbounce.png
- \br
+ \value OutInBounce \image qeasingcurve-outinbounce.png
+ \caption
Easing curve for a bounce (exponentially
decaying parabolic bounce) function easing out/in:
deceleration until halfway, then acceleration.
This is a typedef for a pointer to a function with the following
signature:
- \snippet doc/src/snippets/code/src_corelib_tools_qeasingcurve.cpp 0
+ \snippet code/src_corelib_tools_qeasingcurve.cpp 0
*/
#include "qeasingcurve.h"
/*!
\fn QDataStream &operator>>(QDataStream &stream, QEasingCurve &easing)
- \relates QQuaternion
+ \relates QEasingCurve
Reads an easing curve from the given \a stream into the given \a
easing curve and returns a reference to the stream.
spent in a slow operation. The simplest example of such a case is for
debugging purposes, as in the following example:
- \snippet doc/src/snippets/qelapsedtimer/main.cpp 0
+ \snippet qelapsedtimer/main.cpp 0
In this example, the timer is started by a call to start() and the
elapsed timer is calculated by the elapsed() function.
subclasses are good examples of such need. In that case, the code could
be as follows:
- \snippet doc/src/snippets/qelapsedtimer/main.cpp 1
+ \snippet qelapsedtimer/main.cpp 1
Another use-case is to execute a certain operation for a specific
timeslice. For this, QElapsedTimer provides the hasExpired() convenience
function, which can be used to determine if a certain number of
milliseconds has already elapsed:
- \snippet doc/src/snippets/qelapsedtimer/main.cpp 2
+ \snippet qelapsedtimer/main.cpp 2
\section1 Reference clocks
Starts this timer. Once started, a timer value can be checked with elapsed() or msecsSinceReference().
Normally, a timer is started just before a lengthy operation, such as:
- \snippet doc/src/snippets/qelapsedtimer/main.cpp 0
+ \snippet qelapsedtimer/main.cpp 0
Also, starting a timer makes it valid again.
parameter to a slow operation (for example, an iteration count) so that
this operation takes at least 250 milliseconds:
- \snippet doc/src/snippets/qelapsedtimer/main.cpp 3
+ \snippet qelapsedtimer/main.cpp 3
\sa start(), invalidate(), elapsed()
*/
\endlist
Here's an example QHash with QString keys and \c int values:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 0
+ \snippet code/src_corelib_tools_qhash.cpp 0
To insert a (key, value) pair into the hash, you can use operator[]():
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 1
+ \snippet code/src_corelib_tools_qhash.cpp 1
This inserts the following three (key, value) pairs into the
QHash: ("one", 1), ("three", 3), and ("seven", 7). Another way to
insert items into the hash is to use insert():
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 2
+ \snippet code/src_corelib_tools_qhash.cpp 2
To look up a value, use operator[]() or value():
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 3
+ \snippet code/src_corelib_tools_qhash.cpp 3
If there is no item with the specified key in the hash, these
functions return a \l{default-constructed value}.
If you want to check whether the hash contains a particular key,
use contains():
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 4
+ \snippet code/src_corelib_tools_qhash.cpp 4
There is also a value() overload that uses its second argument as
a default value if there is no item with the specified key:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 5
+ \snippet code/src_corelib_tools_qhash.cpp 5
In general, we recommend that you use contains() and value()
rather than operator[]() for looking up a key in a hash. The
const). For example, the following code snippet will create 1000
items in memory:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 6
+ \snippet code/src_corelib_tools_qhash.cpp 6
To avoid this problem, replace \c hash[i] with \c hash.value(i)
in the code above.
QHash::iterator). Here's how to iterate over a QHash<QString,
int> using a Java-style iterator:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 7
+ \snippet code/src_corelib_tools_qhash.cpp 7
Here's the same code, but using an STL-style iterator:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 8
+ \snippet code/src_corelib_tools_qhash.cpp 8
QHash is unordered, so an iterator's sequence cannot be assumed
to be predictable. If ordering by key is required, use a QMap.
insert() with a key that already exists in the QHash, the
previous value is erased. For example:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 9
+ \snippet code/src_corelib_tools_qhash.cpp 9
However, you can store multiple values per key by using
insertMulti() instead of insert() (or using the convenience
the values for a single key, you can use values(const Key &key),
which returns a QList<T>:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 10
+ \snippet code/src_corelib_tools_qhash.cpp 10
The items that share the same key are available from most
recently to least recently inserted. A more efficient approach is
to call find() to get the iterator for the first item with a key
and iterate from there:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 11
+ \snippet code/src_corelib_tools_qhash.cpp 11
If you only need to extract the values from a hash (not the keys),
you can also use \l{foreach}:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 12
+ \snippet code/src_corelib_tools_qhash.cpp 12
Items can be removed from the hash in several ways. One way is to
call remove(); this will remove any item with the given key.
This function is useful for code that needs to build a huge hash
and wants to avoid repeated reallocation. For example:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 14
+ \snippet code/src_corelib_tools_qhash.cpp 14
Ideally, \a size should be slightly more than the maximum number
of items expected in the hash. \a size doesn't have to be prime,
be called while iterating, and won't affect the order of items in
the hash. For example:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 15
+ \snippet code/src_corelib_tools_qhash.cpp 15
\sa remove(), take(), find()
*/
the iterator. For example, here's some code that iterates over all
the items with the same key:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 16
+ \snippet code/src_corelib_tools_qhash.cpp 16
\sa value(), values(), QMultiHash::find()
*/
start iterating. Here's a typical loop that prints all the (key,
value) pairs stored in a hash:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 17
+ \snippet code/src_corelib_tools_qhash.cpp 17
Unlike QMap, which orders its items by key, QHash stores its
items in an arbitrary order. The only guarantee is that items that
Here's an example that increments every value stored in the QHash
by 2:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 18
+ \snippet code/src_corelib_tools_qhash.cpp 18
Here's an example that removes all the items whose key is a
string that starts with an underscore character:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 19
+ \snippet code/src_corelib_tools_qhash.cpp 19
The call to QHash::erase() removes the item pointed to by the
iterator from the hash, and returns an iterator to the next item.
Here's another way of removing an item while iterating:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 20
+ \snippet code/src_corelib_tools_qhash.cpp 20
It might be tempting to write code like this:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 21
+ \snippet code/src_corelib_tools_qhash.cpp 21
However, this will potentially crash in \c{++i}, because \c i is
a dangling iterator after the call to erase().
called on an uninitialized iterator. Use operator=() to assign a
value to it before using it.
- \sa QHash::begin() QHash::end()
+ \sa QHash::begin(), QHash::end()
*/
/*! \fn QHash::iterator::iterator(void *node)
You can change the value of an item by using value() on
the left side of an assignment, for example:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 22
+ \snippet code/src_corelib_tools_qhash.cpp 22
\sa key(), operator*()
*/
QHash::find() before you can start iterating. Here's a typical
loop that prints all the (key, value) pairs stored in a hash:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 23
+ \snippet code/src_corelib_tools_qhash.cpp 23
Unlike QMap, which orders its items by key, QHash stores its
items in an arbitrary order. The only guarantee is that items that
called on an uninitialized iterator. Use operator=() to assign a
value to it before using it.
- \sa QHash::constBegin() QHash::constEnd()
+ \sa QHash::constBegin(), QHash::constEnd()
*/
/*! \fn QHash::const_iterator::const_iterator(void *node)
operator+=().
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 24
+ \snippet code/src_corelib_tools_qhash.cpp 24
Unlike QHash, QMultiHash provides no operator[]. Use value() or
replace() if you want to access the most recently inserted item
If you want to retrieve all the values for a single key, you can
use values(const Key &key), which returns a QList<T>:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 25
+ \snippet code/src_corelib_tools_qhash.cpp 25
The items that share the same key are available from most
recently to least recently inserted.
the STL-style iterator for the first item with a key and iterate from
there:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 26
+ \snippet code/src_corelib_tools_qhash.cpp 26
QMultiHash's key and value data types must be \l{assignable data
types}. You cannot, for example, store a QWidget as a value;
the list (before the first item). Here's how to iterate over all
the elements sequentially:
- \snippet doc/src/snippets/code/doc_src_qiterator.cpp 0
+ \snippet code/doc_src_qiterator.cpp 0
The next() function returns the next item in the list and
advances the iterator. Unlike STL-style iterators, Java-style
position between the second and third item, and returns the second
item; and so on.
- \img javaiterators1.png
+ \image javaiterators1.png
Here's how to iterate over the elements in reverse order:
- \snippet doc/src/snippets/code/doc_src_qiterator.cpp 1
+ \snippet code/doc_src_qiterator.cpp 1
If you want to find all occurrences of a particular value, use
findNext() or findPrevious() in a loop.
beginning of the list (before the first item). Here's how to
iterate over all the elements sequentially:
- \snippet doc/src/snippets/code/doc_src_qiterator.cpp 2
+ \snippet code/doc_src_qiterator.cpp 2
The next() function returns the next item in the list and
advances the iterator. Unlike STL-style iterators, Java-style
position between the second and third item, and returns the second
item; and so on.
- \img javaiterators1.png
+ \image javaiterators1.png
Here's how to iterate over the elements in reverse order:
- \snippet doc/src/snippets/code/doc_src_qiterator.cpp 3
+ \snippet code/doc_src_qiterator.cpp 3
If you want to find all occurrences of a particular value, use
findNext() or findPrevious() in a loop.
of the vector (before the first item). Here's how to iterate over
all the elements sequentially:
- \snippet doc/src/snippets/code/doc_src_qiterator.cpp 4
+ \snippet code/doc_src_qiterator.cpp 4
The next() function returns the next item in the vector and
advances the iterator. Unlike STL-style iterators, Java-style
position between the second and third item, returning the second
item; and so on.
- \img javaiterators1.png
+ \image javaiterators1.png
Here's how to iterate over the elements in reverse order:
- \snippet doc/src/snippets/code/doc_src_qiterator.cpp 5
+ \snippet code/doc_src_qiterator.cpp 5
If you want to find all occurrences of a particular value, use
findNext() or findPrevious() in a loop.
the first item). Here's how to iterate over all the elements
sequentially:
- \snippet doc/src/snippets/code/doc_src_qiterator.cpp 6
+ \snippet code/doc_src_qiterator.cpp 6
The next() function returns the next item in the set and
advances the iterator. Unlike STL-style iterators, Java-style
position between the second and third item, returning the second
item; and so on.
- \img javaiterators1.png
+ \image javaiterators1.png
Here's how to iterate over the elements in reverse order:
- \snippet doc/src/snippets/code/doc_src_qiterator.cpp 7
+ \snippet code/doc_src_qiterator.cpp 7
If you want to find all occurrences of a particular value, use
findNext() or findPrevious() in a loop.
of the list (before the first item). Here's how to iterate over
all the elements sequentially:
- \snippet doc/src/snippets/code/doc_src_qiterator.cpp 8
+ \snippet code/doc_src_qiterator.cpp 8
The next() function returns the next item in the list and
advances the iterator. Unlike STL-style iterators, Java-style
position between the second and third item, returning the second
item; and so on.
- \img javaiterators1.png
+ \image javaiterators1.png
Here's how to iterate over the elements in reverse order:
- \snippet doc/src/snippets/code/doc_src_qiterator.cpp 9
+ \snippet code/doc_src_qiterator.cpp 9
If you want to find all occurrences of a particular value, use
findNext() or findPrevious() in a loop.
insert().
Example:
- \snippet doc/src/snippets/code/doc_src_qiterator.cpp 10
+ \snippet code/doc_src_qiterator.cpp 10
The example traverses a list, replacing negative numbers with
their absolute values, and eliminating zeroes.
beginning of the list (before the first item). Here's how to
iterate over all the elements sequentially:
- \snippet doc/src/snippets/code/doc_src_qiterator.cpp 11
+ \snippet code/doc_src_qiterator.cpp 11
The next() function returns the next item in the list and
advances the iterator. Unlike STL-style iterators, Java-style
position between the second and third item, returning the second
item; and so on.
- \img javaiterators1.png
+ \image javaiterators1.png
Here's how to iterate over the elements in reverse order:
- \snippet doc/src/snippets/code/doc_src_qiterator.cpp 12
+ \snippet code/doc_src_qiterator.cpp 12
If you want to find all occurrences of a particular value, use
findNext() or findPrevious() in a loop.
insert().
Example:
- \snippet doc/src/snippets/code/doc_src_qiterator.cpp 13
+ \snippet code/doc_src_qiterator.cpp 13
The example traverses a list, replacing negative numbers with
their absolute values, and eliminating zeroes.
beginning of the list (before the first item). Here's how to
iterate over all the elements sequentially:
- \snippet doc/src/snippets/code/doc_src_qiterator.cpp 14
+ \snippet code/doc_src_qiterator.cpp 14
The next() function returns the next item in the vector and
advances the iterator. Unlike STL-style iterators, Java-style
position between the second and third item, returning the second
item; and so on.
- \img javaiterators1.png
+ \image javaiterators1.png
Here's how to iterate over the elements in reverse order:
- \snippet doc/src/snippets/code/doc_src_qiterator.cpp 15
+ \snippet code/doc_src_qiterator.cpp 15
If you want to find all occurrences of a particular value, use
findNext() or findPrevious() in a loop.
insert().
Example:
- \snippet doc/src/snippets/code/doc_src_qiterator.cpp 16
+ \snippet code/doc_src_qiterator.cpp 16
The example traverses a vector, replacing negative numbers with
their absolute values, and eliminating zeroes.
of the set (before the first item). Here's how to iterate over
all the elements sequentially:
- \snippet doc/src/snippets/code/doc_src_qiterator.cpp 17
+ \snippet code/doc_src_qiterator.cpp 17
The next() function returns the next item in the set and
advances the iterator. Unlike STL-style iterators, Java-style
position between the second and third item, returning the second
item; and so on.
- \img javaiterators1.png
+ \image javaiterators1.png
Here's how to iterate over the elements in reverse order:
- \snippet doc/src/snippets/code/doc_src_qiterator.cpp 18
+ \snippet code/doc_src_qiterator.cpp 18
If you want to remove items as you iterate over the set, use
remove().
traversal functions (next(), previous(), findNext(), findPrevious()).
Example:
- \snippet doc/src/snippets/code/doc_src_qiterator.cpp 19
+ \snippet code/doc_src_qiterator.cpp 19
\sa insert(), setValue()
*/
traversal functions (next(), previous(), findNext(), findPrevious()).
Example:
- \snippet doc/src/snippets/code/doc_src_qiterator.cpp 20
+ \snippet code/doc_src_qiterator.cpp 20
\sa insert(), setValue()
*/
traversal functions (next(), previous(), findNext(), findPrevious()).
Example:
- \snippet doc/src/snippets/code/doc_src_qiterator.cpp 21
+ \snippet code/doc_src_qiterator.cpp 21
\sa insert(), setValue()
*/
traversal functions (next(), previous(), findNext(), findPrevious()).
Example:
- \snippet doc/src/snippets/code/doc_src_qiterator.cpp 22
+ \snippet code/doc_src_qiterator.cpp 22
\sa value()
*/
findPrevious().
Example:
- \snippet doc/src/snippets/code/doc_src_qiterator.cpp 23
+ \snippet code/doc_src_qiterator.cpp 23
\sa value(), remove(), insert()
*/
findPrevious().
Example:
- \snippet doc/src/snippets/code/doc_src_qiterator.cpp 24
+ \snippet code/doc_src_qiterator.cpp 24
\sa value(), remove(), insert()
*/
findPrevious().
Example:
- \snippet doc/src/snippets/code/doc_src_qiterator.cpp 25
+ \snippet code/doc_src_qiterator.cpp 25
\sa value(), remove(), insert()
*/
the map (before the first item). Here's how to iterate over all
the elements sequentially:
- \snippet doc/src/snippets/code/doc_src_qiterator.cpp 26
+ \snippet code/doc_src_qiterator.cpp 26
The next() function returns the next item in the map and
advances the iterator. The key() and value() functions return the
next() advances the iterator to the position between the second
and third item; and so on.
- \img javaiterators1.png
+ \image javaiterators1.png
Here's how to iterate over the elements in reverse order:
- \snippet doc/src/snippets/code/doc_src_qiterator.cpp 27
+ \snippet code/doc_src_qiterator.cpp 27
If you want to find all occurrences of a particular value, use
findNext() or findPrevious() in a loop. For example:
- \snippet doc/src/snippets/code/doc_src_qiterator.cpp 28
+ \snippet code/doc_src_qiterator.cpp 28
Multiple iterators can be used on the same map. If the map is
modified while a QMapIterator is active, the QMapIterator will
the hash (before the first item). Here's how to iterate over all
the elements sequentially:
- \snippet doc/src/snippets/code/doc_src_qiterator.cpp 29
+ \snippet code/doc_src_qiterator.cpp 29
The next() function returns the next item in the hash and
advances the iterator. The key() and value() functions return the
next() advances the iterator to the position between the second
and third item; and so on.
- \img javaiterators1.png
+ \image javaiterators1.png
Here's how to iterate over the elements in reverse order:
- \snippet doc/src/snippets/code/doc_src_qiterator.cpp 30
+ \snippet code/doc_src_qiterator.cpp 30
If you want to find all occurrences of a particular value, use
findNext() or findPrevious() in a loop. For example:
- \snippet doc/src/snippets/code/doc_src_qiterator.cpp 31
+ \snippet code/doc_src_qiterator.cpp 31
Multiple iterators can be used on the same hash. If the hash is
modified while a QHashIterator is active, the QHashIterator will
of the map (before the first item). Here's how to iterate over
all the elements sequentially:
- \snippet doc/src/snippets/code/doc_src_qiterator.cpp 32
+ \snippet code/doc_src_qiterator.cpp 32
The next() function returns the next item in the map and
advances the iterator. The key() and value() functions return the
next() advances the iterator to the position between the second
and third item; and so on.
- \img javaiterators1.png
+ \image javaiterators1.png
Here's how to iterate over the elements in reverse order:
- \snippet doc/src/snippets/code/doc_src_qiterator.cpp 33
+ \snippet code/doc_src_qiterator.cpp 33
If you want to find all occurrences of a particular value, use
findNext() or findPrevious() in a loop. For example:
- \snippet doc/src/snippets/code/doc_src_qiterator.cpp 34
+ \snippet code/doc_src_qiterator.cpp 34
If you want to remove items as you iterate over the map, use
remove(). If you want to modify the value of an item, use
Example:
- \snippet doc/src/snippets/code/doc_src_qiterator.cpp 35
+ \snippet code/doc_src_qiterator.cpp 35
The example removes all (key, value) pairs where the key and the
value are the same.
of the hash (before the first item). Here's how to iterate over
all the elements sequentially:
- \snippet doc/src/snippets/code/doc_src_qiterator.cpp 36
+ \snippet code/doc_src_qiterator.cpp 36
The next() function returns the next item in the hash and
advances the iterator. The key() and value() functions return the
next() advances the iterator to the position between the second
and third item; and so on.
- \img javaiterators1.png
+ \image javaiterators1.png
Here's how to iterate over the elements in reverse order:
- \snippet doc/src/snippets/code/doc_src_qiterator.cpp 37
+ \snippet code/doc_src_qiterator.cpp 37
If you want to find all occurrences of a particular value, use
findNext() or findPrevious() in a loop. For example:
- \snippet doc/src/snippets/code/doc_src_qiterator.cpp 38
+ \snippet code/doc_src_qiterator.cpp 38
If you want to remove items as you iterate over the hash, use
remove(). If you want to modify the value of an item, use
Example:
- \snippet doc/src/snippets/code/doc_src_qiterator.cpp 39
+ \snippet code/doc_src_qiterator.cpp 39
The example removes all (key, value) pairs where the key and the
value are the same.
Here's an example of a QLinkedList that stores integers and a
QLinkedList that stores QTime values:
- \snippet doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp 0
+ \snippet code/src_corelib_tools_qlinkedlist.cpp 0
QLinkedList stores a list of items. The default constructor
creates an empty list. To insert items into the list, you can use
operator<<():
- \snippet doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp 1
+ \snippet code/src_corelib_tools_qlinkedlist.cpp 1
If you want to get the first or last item in a linked list, use
first() or last(). If you want to remove an item from either end
list and do something with it. For this, QLinkedList provides
takeFirst() and takeLast(). Here's a loop that removes the items
from a list one at a time and calls \c delete on them:
- \snippet doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp 2
+ \snippet code/src_corelib_tools_qlinkedlist.cpp 2
QLinkedList's value type must be an \l {assignable data type}. This
covers most data types that are commonly used, but the compiler
Inserts \a value at the end of the list.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp 3
+ \snippet code/src_corelib_tools_qlinkedlist.cpp 3
This is the same as list.insert(end(), \a value).
Inserts \a value at the beginning of the list.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp 4
+ \snippet code/src_corelib_tools_qlinkedlist.cpp 4
This is the same as list.insert(begin(), \a value).
Removes all occurrences of \a value in the list.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp 5
+ \snippet code/src_corelib_tools_qlinkedlist.cpp 5
This function requires the value type to have an implementation of
\c operator==().
success; otherwise returns false.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp 6
+ \snippet code/src_corelib_tools_qlinkedlist.cpp 6
This function requires the value type to have an implementation of
\c operator==().
QLinkedList::insert() before you can start iterating. Here's a
typical loop that prints all the items stored in a list:
- \snippet doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp 7
+ \snippet code/src_corelib_tools_qlinkedlist.cpp 7
STL-style iterators can be used as arguments to \l{generic
algorithms}. For example, here's how to find an item in the list
using the qFind() algorithm:
- \snippet doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp 8
+ \snippet code/src_corelib_tools_qlinkedlist.cpp 8
Let's see a few examples of things we can do with a
QLinkedList::iterator that we cannot do with a QLinkedList::const_iterator.
Here's an example that increments every value stored in a
QLinkedList\<int\> by 2:
- \snippet doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp 9
+ \snippet code/src_corelib_tools_qlinkedlist.cpp 9
Here's an example that removes all the items that start with an
underscore character in a QLinkedList\<QString\>:
- \snippet doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp 10
+ \snippet code/src_corelib_tools_qlinkedlist.cpp 10
The call to QLinkedList::erase() removes the item pointed to by
the iterator from the list, and returns an iterator to the next
item. Here's another way of removing an item while iterating:
- \snippet doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp 11
+ \snippet code/src_corelib_tools_qlinkedlist.cpp 11
It might be tempting to write code like this:
- \snippet doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp 12
+ \snippet code/src_corelib_tools_qlinkedlist.cpp 12
However, this will potentially crash in \c{++i}, because \c i is
a dangling iterator after the call to erase().
on an uninitialized iterator. Use operator=() to assign a value
to it before using it.
- \sa QLinkedList::begin() QLinkedList::end()
+ \sa QLinkedList::begin(), QLinkedList::end()
*/
/*! \fn QLinkedList::iterator::iterator(Node *node)
You can change the value of an item by using operator*() on the
left side of an assignment, for example:
- \snippet doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp 13
+ \snippet code/src_corelib_tools_qlinkedlist.cpp 13
\sa operator->()
*/
QLinkedList::insert() before you can start iterating. Here's a
typical loop that prints all the items stored in a list:
- \snippet doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp 14
+ \snippet code/src_corelib_tools_qlinkedlist.cpp 14
STL-style iterators can be used as arguments to \l{generic
algorithms}. For example, here's how to find an item in the list
using the qFind() algorithm:
- \snippet doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp 15
+ \snippet code/src_corelib_tools_qlinkedlist.cpp 15
Multiple iterators can be used on the same list. If you add items
to the list, existing iterators will remain valid. If you remove
on an uninitialized iterator. Use operator=() to assign a value
to it before using it.
- \sa QLinkedList::constBegin() QLinkedList::constEnd()
+ \sa QLinkedList::constBegin(), QLinkedList::constEnd()
*/
/*! \fn QLinkedList::const_iterator::const_iterator(Node *node)
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp 16
+ \snippet code/src_corelib_tools_qlinkedlist.cpp 16
\sa toStdList()
*/
Returns a std::list object with the data contained in this
QLinkedList. Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp 17
+ \snippet code/src_corelib_tools_qlinkedlist.cpp 17
\sa fromStdList()
*/
Here's an example of a QList that stores integers and
a QList that stores QDate values:
- \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 0
+ \snippet code/src_corelib_tools_qlistdata.cpp 0
Qt includes a QStringList class that inherits QList\<QString\>
and adds a few convenience functions, such as QStringList::join()
empty list. To insert items into the list, you can use
operator<<():
- \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 1
+ \snippet code/src_corelib_tools_qlistdata.cpp 1
QList provides these basic functions to add, move, and remove
items: insert(), replace(), removeAt(), move(), and swap(). In
non-const lists, operator[]() returns a reference to the item and
can be used on the left side of an assignment:
- \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 2
+ \snippet code/src_corelib_tools_qlistdata.cpp 2
Because QList is implemented as an array of pointers, this
operation is very fast (\l{constant time}). For read-only access,
an alternative syntax is to use at():
- \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 3
+ \snippet code/src_corelib_tools_qlistdata.cpp 3
at() can be faster than operator[](), because it never causes a
\l{deep copy} to occur.
and takeLast(). Here's a loop that removes the items from a list
one at a time and calls \c delete on them:
- \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 4
+ \snippet code/src_corelib_tools_qlistdata.cpp 4
Inserting and removing items at either ends of the list is very
fast (\l{constant time} in most cases), because QList
backward. Both return the index of a matching item if they find
it; otherwise, they return -1. For example:
- \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 5
+ \snippet code/src_corelib_tools_qlistdata.cpp 5
If you simply want to check whether a list contains a particular
value, use contains(). If you want to find out how many times a
Inserts \a value at the end of the list.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 6
+ \snippet code/src_corelib_tools_qlistdata.cpp 6
This is the same as list.insert(size(), \a value).
Inserts \a value at the beginning of the list.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 7
+ \snippet code/src_corelib_tools_qlistdata.cpp 7
This is the same as list.insert(0, \a value).
value is appended to the list.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 8
+ \snippet code/src_corelib_tools_qlistdata.cpp 8
\sa append(), prepend(), replace(), removeAt()
*/
number of entries removed.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 9
+ \snippet code/src_corelib_tools_qlistdata.cpp 9
This function requires the value type to have an implementation of
\c operator==().
true on success; otherwise returns false.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 10
+ \snippet code/src_corelib_tools_qlistdata.cpp 10
This function requires the value type to have an implementation of
\c operator==().
Moves the item at index position \a from to index position \a to.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 11
+ \snippet code/src_corelib_tools_qlistdata.cpp 11
This is the same as insert(\a{to}, takeAt(\a{from})).This function
assumes that both \a from and \a to are at least 0 but less than
\a i and \a j are at least 0 and less than size().
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 12
+ \snippet code/src_corelib_tools_qlistdata.cpp 12
\sa move()
*/
-1 if no item matched.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 13
+ \snippet code/src_corelib_tools_qlistdata.cpp 13
This function requires the value type to have an implementation of
\c operator==().
Returns -1 if no item matched.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 14
+ \snippet code/src_corelib_tools_qlistdata.cpp 14
This function requires the value type to have an implementation of
\c operator==().
start iterating. Here's a typical loop that prints all the items
stored in a list:
- \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 15
+ \snippet code/src_corelib_tools_qlistdata.cpp 15
Let's see a few examples of things we can do with a
QList::iterator that we cannot do with a QList::const_iterator.
Here's an example that increments every value stored in a
QList\<int\> by 2:
- \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 16
+ \snippet code/src_corelib_tools_qlistdata.cpp 16
Most QList functions accept an integer index rather than an
iterator. For that reason, iterators are rarely useful in
For example, here's how to delete all the widgets stored in a
QList\<QWidget *\>:
- \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 17
+ \snippet code/src_corelib_tools_qlistdata.cpp 17
Multiple iterators can be used on the same list. However, be
aware that any non-const function call performed on the QList
on an uninitialized iterator. Use operator=() to assign a value
to it before using it.
- \sa QList::begin() QList::end()
+ \sa QList::begin(), QList::end()
*/
/*! \fn QList::iterator::iterator(Node *node)
You can change the value of an item by using operator*() on the
left side of an assignment, for example:
- \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 18
+ \snippet code/src_corelib_tools_qlistdata.cpp 18
\sa operator->()
*/
QList::insert() before you can start iterating. Here's a typical
loop that prints all the items stored in a list:
- \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 19
+ \snippet code/src_corelib_tools_qlistdata.cpp 19
Most QList functions accept an integer index rather than an
iterator. For that reason, iterators are rarely useful in
For example, here's how to delete all the widgets stored in a
QList\<QWidget *\>:
- \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 20
+ \snippet code/src_corelib_tools_qlistdata.cpp 20
Multiple iterators can be used on the same list. However, be
aware that any non-const function call performed on the QList
on an uninitialized iterator. Use operator=() to assign a value
to it before using it.
- \sa QList::constBegin() QList::constEnd()
+ \sa QList::constBegin(), QList::constEnd()
*/
/*! \typedef QList::const_iterator::iterator_category
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 21
+ \snippet code/src_corelib_tools_qlistdata.cpp 21
\sa fromSet(), toVector(), QVector::toList()
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 22
+ \snippet code/src_corelib_tools_qlistdata.cpp 22
\sa toSet(), fromVector(), QVector::fromList()
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 23
+ \snippet code/src_corelib_tools_qlistdata.cpp 23
\sa fromVector(), toSet(), QSet::toList(), qSort()
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 24
+ \snippet code/src_corelib_tools_qlistdata.cpp 24
\sa toVector(), fromSet(), QSet::fromList()
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 25
+ \snippet code/src_corelib_tools_qlistdata.cpp 25
\sa toStdList(), QVector::fromStdVector()
*/
Returns a std::list object with the data contained in this QList.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 26
+ \snippet code/src_corelib_tools_qlistdata.cpp 26
\sa fromStdList(), QVector::toStdVector()
*/
The language and country that are actually used can be queried
using language() and country().
- \sa setDefault() language() country()
+ \sa setDefault(), language(), country()
*/
QLocale::QLocale(Language language, Country country)
The language, script and country that are actually used can be queried
using language(), script() and country().
- \sa setDefault() language() script() country()
+ \sa setDefault(), language(), script(), country()
*/
QLocale::QLocale(Language language, Script script, Country country)
should be set at application startup, before any non-GUI threads
are created.
- \sa system() c()
+ \sa system(), c()
*/
void QLocale::setDefault(const QLocale &locale)
the "C" locale if the string cannot be interpreted in this
locale.
- \snippet doc/src/snippets/code/src_corelib_tools_qlocale.cpp 3
+ \snippet code/src_corelib_tools_qlocale.cpp 3
Notice that the last conversion returns 1234.0, because '.' is the
thousands group separator in the German locale.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qlocale.cpp 0
+ \snippet code/src_corelib_tools_qlocale.cpp 0
QLocale supports the concept of a default locale, which is
determined from the system's locale settings at application
The following example illustrates how to use QLocale directly:
- \snippet doc/src/snippets/code/src_corelib_tools_qlocale.cpp 1
+ \snippet code/src_corelib_tools_qlocale.cpp 1
When a language/country pair is specified in the constructor, one
of three things can happen:
An alternative method for constructing a QLocale object is by
specifying the locale name.
- \snippet doc/src/snippets/code/src_corelib_tools_qlocale.cpp 2
+ \snippet code/src_corelib_tools_qlocale.cpp 2
This constructor converts the locale name to a language/country
pair; it does not use the system locale database.
will fail if they encounter group separators in their input. The default
is to accept numbers containing correctly placed group separators.
- \sa setNumberOptions() numberOptions()
+ \sa setNumberOptions(), numberOptions()
*/
/*!
\endlist
Here's an example QMap with QString keys and \c int values:
- \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 0
+ \snippet code/src_corelib_tools_qmap.cpp 0
To insert a (key, value) pair into the map, you can use operator[]():
- \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 1
+ \snippet code/src_corelib_tools_qmap.cpp 1
This inserts the following three (key, value) pairs into the
QMap: ("one", 1), ("three", 3), and ("seven", 7). Another way to
insert items into the map is to use insert():
- \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 2
+ \snippet code/src_corelib_tools_qmap.cpp 2
To look up a value, use operator[]() or value():
- \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 3
+ \snippet code/src_corelib_tools_qmap.cpp 3
If there is no item with the specified key in the map, these
functions return a \l{default-constructed value}.
If you want to check whether the map contains a certain key, use
contains():
- \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 4
+ \snippet code/src_corelib_tools_qmap.cpp 4
There is also a value() overload that uses its second argument as
a default value if there is no item with the specified key:
- \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 5
+ \snippet code/src_corelib_tools_qmap.cpp 5
In general, we recommend that you use contains() and value()
rather than operator[]() for looking up a key in a map. The
const). For example, the following code snippet will create 1000
items in memory:
- \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 6
+ \snippet code/src_corelib_tools_qmap.cpp 6
To avoid this problem, replace \c map[i] with \c map.value(i)
in the code above.
QMap::iterator). Here's how to iterate over a QMap<QString, int>
using a Java-style iterator:
- \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 7
+ \snippet code/src_corelib_tools_qmap.cpp 7
Here's the same code, but using an STL-style iterator this time:
- \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 8
+ \snippet code/src_corelib_tools_qmap.cpp 8
The items are traversed in ascending key order.
insert() with a key that already exists in the QMap, the
previous value will be erased. For example:
- \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 9
+ \snippet code/src_corelib_tools_qmap.cpp 9
However, you can store multiple values per key by using
insertMulti() instead of insert() (or using the convenience
single key, you can use values(const Key &key), which returns a
QList<T>:
- \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 10
+ \snippet code/src_corelib_tools_qmap.cpp 10
The items that share the same key are available from most
recently to least recently inserted. Another approach is to call
find() to get the STL-style iterator for the first item with a
key and iterate from there:
- \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 11
+ \snippet code/src_corelib_tools_qmap.cpp 11
If you only need to extract the values from a map (not the keys),
you can also use \l{foreach}:
- \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 12
+ \snippet code/src_corelib_tools_qmap.cpp 12
Items can be removed from the map in several ways. One way is to
call remove(); this will remove any item with the given key.
< y} nor \c{y < x} is true.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 13
+ \snippet code/src_corelib_tools_qmap.cpp 13
In the example, we start by comparing the employees' names. If
they're equal, we compare their dates of birth to break the tie.
the iterator. For example, here's some code that iterates over all
the items with the same key:
- \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 14
+ \snippet code/src_corelib_tools_qmap.cpp 14
\sa constFind(), value(), values(), lowerBound(), upperBound(), QMultiMap::find()
*/
key.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 15
+ \snippet code/src_corelib_tools_qmap.cpp 15
If the map contains multiple items with key \a key, this
function returns an iterator that points to the most recently
the iterator. For example, here's some code that iterates over all
the items with the same key:
- \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 16
+ \snippet code/src_corelib_tools_qmap.cpp 16
\sa qLowerBound(), upperBound(), find()
*/
nearest item with a greater key.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 17
+ \snippet code/src_corelib_tools_qmap.cpp 17
\sa qUpperBound(), lowerBound(), find()
*/
start iterating. Here's a typical loop that prints all the (key,
value) pairs stored in a map:
- \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 18
+ \snippet code/src_corelib_tools_qmap.cpp 18
Unlike QHash, which stores its items in an arbitrary order, QMap
stores its items ordered by key. Items that share the same key
Here's an example that increments every value stored in the QMap
by 2:
- \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 19
+ \snippet code/src_corelib_tools_qmap.cpp 19
Here's an example that removes all the items whose key is a
string that starts with an underscore character:
- \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 20
+ \snippet code/src_corelib_tools_qmap.cpp 20
The call to QMap::erase() removes the item pointed to by the
iterator from the map, and returns an iterator to the next item.
Here's another way of removing an item while iterating:
- \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 21
+ \snippet code/src_corelib_tools_qmap.cpp 21
It might be tempting to write code like this:
- \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 22
+ \snippet code/src_corelib_tools_qmap.cpp 22
However, this will potentially crash in \c{++i}, because \c i is
a dangling iterator after the call to erase().
called on an uninitialized iterator. Use operator=() to assign a
value to it before using it.
- \sa QMap::begin() QMap::end()
+ \sa QMap::begin(), QMap::end()
*/
/*! \fn QMap::iterator::iterator(QMapData::Node *node)
You can change the value of an item by using value() on
the left side of an assignment, for example:
- \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 23
+ \snippet code/src_corelib_tools_qmap.cpp 23
\sa key(), operator*()
*/
QMap::find() before you can start iterating. Here's a typical
loop that prints all the (key, value) pairs stored in a map:
- \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 24
+ \snippet code/src_corelib_tools_qmap.cpp 24
Unlike QHash, which stores its items in an arbitrary order, QMap
stores its items ordered by key. Items that share the same key
called on an uninitialized iterator. Use operator=() to assign a
value to it before using it.
- \sa QMap::constBegin() QMap::constEnd()
+ \sa QMap::constBegin(), QMap::constEnd()
*/
/*! \fn QMap::const_iterator::const_iterator(QMapData::Node *node)
operator+=().
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 25
+ \snippet code/src_corelib_tools_qmap.cpp 25
Unlike QMap, QMultiMap provides no operator[]. Use value() or
replace() if you want to access the most recently inserted item
If you want to retrieve all the values for a single key, you can
use values(const Key &key), which returns a QList<T>:
- \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 26
+ \snippet code/src_corelib_tools_qmap.cpp 26
The items that share the same key are available from most
recently to least recently inserted.
the iterator for the first item with a key and iterate from
there:
- \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 27
+ \snippet code/src_corelib_tools_qmap.cpp 27
QMultiMap's key and value data types must be \l{assignable data
types}. This covers most data types you are likely to encounter,
Here's an example of a QPair that stores one QString and one \c
double value:
- \snippet doc/src/snippets/code/doc_src_qpair.cpp 0
+ \snippet code/doc_src_qpair.cpp 0
The components are accessible as public data members called \l
first and \l second. For example:
- \snippet doc/src/snippets/code/doc_src_qpair.cpp 1
+ \snippet code/doc_src_qpair.cpp 1
QPair's template data types (T1 and T2) must be \l{assignable
data types}. You cannot, for example, store a QWidget as a value;
\sa qMakePair()
*/
-/*!
- \fn QPair<T1, T2> &QPair::operator=(const QPair<T1, T2> &other)
-
- Assigns \a other to this pair.
-*/
-
/*! \fn bool operator==(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2)
\relates QPair
Returns a QPair\<T1, T2\> that contains \a value1 and \a value2.
Example:
- \snippet doc/src/snippets/code/doc_src_qpair.cpp 2
+ \snippet code/doc_src_qpair.cpp 2
This is equivalent to QPair<T1, T2>(\a value1, \a value2), but
usually requires less typing.
Given a point \e p, the following statements are all equivalent:
- \snippet doc/src/snippets/code/src_corelib_tools_qpoint.cpp 0
+ \snippet code/src_corelib_tools_qpoint.cpp 0
A QPoint object can also be used as a vector: Addition and
subtraction are defined as for vectors (each component is added
Sets the x coordinate of this point to the given \a x coordinate.
- \sa x() setY()
+ \sa x(), setY()
*/
/*!
Sets the y coordinate of this point to the given \a y coordinate.
- \sa y() setX()
+ \sa y(), setX()
*/
Using a reference makes it possible to directly manipulate x. For example:
- \snippet doc/src/snippets/code/src_corelib_tools_qpoint.cpp 1
+ \snippet code/src_corelib_tools_qpoint.cpp 1
- \sa x() setX()
+ \sa x(), setX()
*/
/*!
Using a reference makes it possible to directly manipulate y. For
example:
- \snippet doc/src/snippets/code/src_corelib_tools_qpoint.cpp 2
+ \snippet code/src_corelib_tools_qpoint.cpp 2
\sa y(), setY()
*/
Adds the given \a point to this point and returns a reference to
this point. For example:
- \snippet doc/src/snippets/code/src_corelib_tools_qpoint.cpp 3
+ \snippet code/src_corelib_tools_qpoint.cpp 3
\sa operator-=()
*/
Subtracts the given \a point from this point and returns a
reference to this point. For example:
- \snippet doc/src/snippets/code/src_corelib_tools_qpoint.cpp 4
+ \snippet code/src_corelib_tools_qpoint.cpp 4
\sa operator+=()
*/
Multiplies this point's coordinates by the given \a factor, and
returns a reference to this point. For example:
- \snippet doc/src/snippets/code/src_corelib_tools_qpoint.cpp 5
+ \snippet code/src_corelib_tools_qpoint.cpp 5
Note that the result is rounded to the nearest integer as points are held as
integers. Use QPointF for floating point accuracy.
Divides both x and y by the given \a divisor, and returns a reference to this
point. For example:
- \snippet doc/src/snippets/code/src_corelib_tools_qpoint.cpp 6
+ \snippet code/src_corelib_tools_qpoint.cpp 6
Note that the result is rounded to the nearest integer as points are held as
integers. Use QPointF for floating point accuracy.
traditionally known as the "Manhattan length" of the vector from
the origin to the point. For example:
- \snippet doc/src/snippets/code/src_corelib_tools_qpoint.cpp 7
+ \snippet code/src_corelib_tools_qpoint.cpp 7
This is a useful, and quick to calculate, approximation to the
true length:
- \snippet doc/src/snippets/code/src_corelib_tools_qpoint.cpp 8
+ \snippet code/src_corelib_tools_qpoint.cpp 8
The tradition of "Manhattan length" arises because such distances
apply to travelers who can only travel on a rectangular grid, like
Given a point \e p, the following statements are all equivalent:
- \snippet doc/src/snippets/code/src_corelib_tools_qpoint.cpp 9
+ \snippet code/src_corelib_tools_qpoint.cpp 9
A QPointF object can also be used as a vector: Addition and
subtraction are defined as for vectors (each component is added
Sets the x coordinate of this point to the given \a x coordinate.
- \sa x() setY()
+ \sa x(), setY()
*/
/*!
Using a reference makes it possible to directly manipulate x. For example:
- \snippet doc/src/snippets/code/src_corelib_tools_qpoint.cpp 10
+ \snippet code/src_corelib_tools_qpoint.cpp 10
\sa x(), setX()
*/
Using a reference makes it possible to directly manipulate y. For example:
- \snippet doc/src/snippets/code/src_corelib_tools_qpoint.cpp 11
+ \snippet code/src_corelib_tools_qpoint.cpp 11
- \sa y() setY()
+ \sa y(), setY()
*/
/*!
Adds the given \a point to this point and returns a reference to
this point. For example:
- \snippet doc/src/snippets/code/src_corelib_tools_qpoint.cpp 12
+ \snippet code/src_corelib_tools_qpoint.cpp 12
\sa operator-=()
*/
Subtracts the given \a point from this point and returns a reference
to this point. For example:
- \snippet doc/src/snippets/code/src_corelib_tools_qpoint.cpp 13
+ \snippet code/src_corelib_tools_qpoint.cpp 13
\sa operator+=()
*/
Multiplies this point's coordinates by the given \a factor, and
returns a reference to this point. For example:
- \snippet doc/src/snippets/code/src_corelib_tools_qpoint.cpp 14
+ \snippet code/src_corelib_tools_qpoint.cpp 14
\sa operator/=()
*/
Divides both x and y by the given \a divisor, and returns a reference
to this point. For example:
- \snippet doc/src/snippets/code/src_corelib_tools_qpoint.cpp 15
+ \snippet code/src_corelib_tools_qpoint.cpp 15
\sa operator*=()
*/
the head item without removing it.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qqueue.cpp 0
+ \snippet code/src_corelib_tools_qqueue.cpp 0
The example will output 1, 2, 3 in that order.
height integers, or from a QPoint and a QSize. The following code
creates two identical rectangles.
- \snippet doc/src/snippets/code/src_corelib_tools_qrect.cpp 0
+ \snippet code/src_corelib_tools_qrect.cpp 0
There is a third constructor that creates a QRect using the
top-left and bottom-right coordinates, but we recommend that you
height integers, or from a QPoint and a QSize. The following code
creates two identical rectangles.
- \snippet doc/src/snippets/code/src_corelib_tools_qrect.cpp 1
+ \snippet code/src_corelib_tools_qrect.cpp 1
There is also a third constructor creating a QRectF from a QRect,
and a corresponding toRect() function that returns a QRect object
\a y1), and the coordinates of its bottom-right corner to (\a x2,
\a y2).
- \sa getCoords() setRect()
+ \sa getCoords(), setRect()
*/
/*!
When the number of matches cannot be determined in advance, a
common idiom is to use cap() in a loop. For example:
- \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 0
+ \snippet code/src_corelib_tools_qregexp.cpp 0
\target assertions
\section1 Assertions
To test a string against a wildcard expression, use exactMatch().
For example:
- \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 1
+ \snippet code/src_corelib_tools_qregexp.cpp 1
\target perl-users
\section1 Notes for Perl Users
applied to all the quantifiers in the pattern. For example, to
match the Perl regexp \b{ro+?m} requires:
- \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 2
+ \snippet code/src_corelib_tools_qregexp.cpp 2
The equivalent of Perl's \c{/i} option is
setCaseSensitivity(Qt::CaseInsensitive).
the other hand, C++'s rules for literal strings can be used to
achieve the same:
- \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 3
+ \snippet code/src_corelib_tools_qregexp.cpp 3
Both zero-width positive and zero-width negative lookahead
assertions (?=pattern) and (?!pattern) are supported with the same
\target code-examples
\section1 Code Examples
- \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 4
+ \snippet code/src_corelib_tools_qregexp.cpp 4
The third string matches '\underline{6}'. This is a simple validation
regexp for integers in the range 0 to 99.
- \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 5
+ \snippet code/src_corelib_tools_qregexp.cpp 5
The second string matches '\underline{This_is-OK}'. We've used the
character set abbreviation '\\S' (non-whitespace) and the anchors
'letter' or 'correspondence' but only match whole words i.e. not
'email'
- \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 6
+ \snippet code/src_corelib_tools_qregexp.cpp 6
The second string matches "Please write the \underline{letter}". The
word 'letter' is also captured (because of the parentheses). We
can see what text we've captured like this:
- \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 7
+ \snippet code/src_corelib_tools_qregexp.cpp 7
This will capture the text from the first set of capturing
parentheses (counting capturing left parentheses from left to
right). The parentheses are counted from 1 since cap(0) is the
whole matched regexp (equivalent to '&' in most regexp engines).
- \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 8
+ \snippet code/src_corelib_tools_qregexp.cpp 8
Here we've passed the QRegExp to QString's replace() function to
replace the matched text with new text.
- \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 9
+ \snippet code/src_corelib_tools_qregexp.cpp 9
We've used the indexIn() function to repeatedly match the regexp in
the string. Note that instead of moving forward by one character
One common use of regexps is to split lines of delimited data into
their component fields.
- \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 10
+ \snippet code/src_corelib_tools_qregexp.cpp 10
In this example our input lines have the format company name, web
address and country. Unfortunately the regexp is rather long and
QString::split() function can take a separator string or regexp
as an argument and split a string accordingly.
- \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 11
+ \snippet code/src_corelib_tools_qregexp.cpp 11
Here field[0] is the company, field[1] the web address and so on.
To imitate the matching of a shell we can use wildcard mode.
- \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 12
+ \snippet code/src_corelib_tools_qregexp.cpp 12
Wildcard matching can be convenient because of its simplicity, but
any wildcard regexp can be defined using full regexps, e.g.
QString::replace().
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 13
+ \snippet code/src_corelib_tools_qregexp.cpp 13
Although const, this function sets matchedLength(),
capturedTexts() and pos().
#ifndef QT_NO_REGEXP_CAPTURE
/*!
- \fn int QRegExp::numCaptures() const
- \obsolete
- Returns the number of captures contained in the regular expression.
-
- \sa captureCount()
- */
-
-/*!
\since 4.6
Returns the number of captures contained in the regular expression.
*/
(capturing) subexpression of the regexp.
For example:
- \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 14
+ \snippet code/src_corelib_tools_qregexp.cpp 14
The above example also captures elements that may be present but
which we have no interest in. This problem can be solved by using
non-capturing parentheses:
- \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 15
+ \snippet code/src_corelib_tools_qregexp.cpp 15
Note that if you want to iterate over the list, you should iterate
over a copy, e.g.
- \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 16
+ \snippet code/src_corelib_tools_qregexp.cpp 16
Some regexps can match an indeterminate number of times. For
example if the input string is "Offsets: 12 14 99 231 7" and the
match has index 0 and the parenthesized subexpressions have
indexes starting from 1 (excluding non-capturing parentheses).
- \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 17
+ \snippet code/src_corelib_tools_qregexp.cpp 17
The order of elements matched by cap() is as follows. The first
element, cap(0), is the entire matching string. Each subsequent
of the whole match.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 18
+ \snippet code/src_corelib_tools_qregexp.cpp 18
For zero-length matches, pos() always returns -1. (For example, if
cap(4) would return an empty string, pos(4) returns -1.) This is
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 19
+ \snippet code/src_corelib_tools_qregexp.cpp 19
This function is useful to construct regexp patterns dynamically:
- \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 20
+ \snippet code/src_corelib_tools_qregexp.cpp 20
\sa setPatternSyntax()
*/
You can set the pattern string by passing a string to the QRegularExpression
constructor:
- \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 0
+ \snippet code/src_corelib_tools_qregularexpression.cpp 0
This sets the pattern string to \c{a pattern}. You can also use the
setPattern() function to set a pattern on an existing QRegularExpression
object:
- \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 1
+ \snippet code/src_corelib_tools_qregularexpression.cpp 1
Note that due to C++ literal strings rules, you must escape all backslashes
inside the pattern string with another backslash:
- \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 2
+ \snippet code/src_corelib_tools_qregularexpression.cpp 2
The pattern() function returns the pattern that is currently set for a
QRegularExpression object:
- \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 3
+ \snippet code/src_corelib_tools_qregularexpression.cpp 3
\section1 Pattern options
You can set the options by passing them to the QRegularExpression
constructor, as in:
- \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 4
+ \snippet code/src_corelib_tools_qregularexpression.cpp 4
Alternatively, you can use the setPatternOptions() function on an existing
QRegularExpressionObject:
- \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 5
+ \snippet code/src_corelib_tools_qregularexpression.cpp 5
It is possible to get the pattern options currently set on a
QRegularExpression object by using the patternOptions() function:
- \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 6
+ \snippet code/src_corelib_tools_qregularexpression.cpp 6
Please refer to the QRegularExpression::PatternOption enum documentation for
more information about each pattern option.
QRegularExpressionMatch object that can be used to inspect the results of
the match. For instance:
- \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 7
+ \snippet code/src_corelib_tools_qregularexpression.cpp 7
If a match is successful, the (implicit) capturing group number 0 can be
used to retrieve the substring matched by the entire pattern (see also the
section about \l{extracting captured substrings}):
- \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 8
+ \snippet code/src_corelib_tools_qregularexpression.cpp 8
It's also possible to start a match at an arbitrary offset inside the
subject string by passing the offset as an argument of the
match() function. In the following example \c{"12 abc"}
is not matched because the match is started at offset 1:
- \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 9
+ \snippet code/src_corelib_tools_qregularexpression.cpp 9
\target extracting captured substrings
\section2 Extracting captured substrings
\l{QRegularExpressionMatch::}{captured()} function will return the string
captured by the n-th capturing group:
- \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 10
+ \snippet code/src_corelib_tools_qregularexpression.cpp 10
Capturing groups in the pattern are numbered starting from 1, and the
implicit capturing group 0 is used to capture the substring that matched
\l{QRegularExpressionMatch::}{capturedStart()} and the
\l{QRegularExpressionMatch::}{capturedEnd()} functions:
- \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 11
+ \snippet code/src_corelib_tools_qregularexpression.cpp 11
All of these functions have an overload taking a QString as a parameter
in order to extract \e{named} captured substrings. For instance:
- \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 12
+ \snippet code/src_corelib_tools_qregularexpression.cpp 12
\target global matching
\section1 Global matching
which is a Java-like forward iterator that can be used to iterate over the
results. For instance:
- \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 13
+ \snippet code/src_corelib_tools_qregularexpression.cpp 13
Since it's a Java-like iterator, the QRegularExpressionMatchIterator will
point immediately before the first result. Every result is returned as a
\l{QRegularExpressionMatchIterator::}{next()} will return the next result
and advance the iterator. Continuing from the previous example:
- \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 14
+ \snippet code/src_corelib_tools_qregularexpression.cpp 14
You can also use \l{QRegularExpressionMatchIterator::}{peekNext()} to get
the next result without advancing the iterator.
This behaviour is implemented by the PartialPreferCompleteMatch match type.
For instance:
- \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 15
+ \snippet code/src_corelib_tools_qregularexpression.cpp 15
If matching the same regular expression against the subject string leads to
a complete match, it is reported as usual:
- \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 16
+ \snippet code/src_corelib_tools_qregularexpression.cpp 16
Another example with a different pattern, showing the behaviour of
preferring a complete match over a partial one:
- \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 17
+ \snippet code/src_corelib_tools_qregularexpression.cpp 17
In this case, the subpattern \c{abc\\w+X} partially matches the subject
string; however, the subpattern \c{def} matches the subject string
match), then the QRegularExpressionMatch object will report the first one
that is found. For instance:
- \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 18
+ \snippet code/src_corelib_tools_qregularexpression.cpp 18
\section2 Incremental/multi-segment matching
as soon as it is found, and other match alternatives are not tried
(even if they could lead to a complete match). For instance:
- \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 19
+ \snippet code/src_corelib_tools_qregularexpression.cpp 19
This happens because when matching the first branch of the alternation
operator a partial match is found, and therefore matching stops, without
trying the second branch. Another example:
- \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 20
+ \snippet code/src_corelib_tools_qregularexpression.cpp 20
This shows what could seem a counterintuitve behaviour of quantifiers:
since \c{?} is greedy, then the engine tries first to continue the match
subject string, and therefore a partial match is reported. This is
even more surprising in the following example:
- \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 21
+ \snippet code/src_corelib_tools_qregularexpression.cpp 21
It's easy to understand this behaviour if we remember that the engine
expects the subject string to be only a substring of the whole text we're
syntax errors in the pattern string. The isValid() function will return
true if the regular expression is valid, or false otherwise:
- \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 22
+ \snippet code/src_corelib_tools_qregularexpression.cpp 22
You can get more information about the specific error by calling the
errorString() function; moreover, the patternErrorOffset() function
will return the offset inside the pattern string
- \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 23
+ \snippet code/src_corelib_tools_qregularexpression.cpp 23
If a match is attempted with an invalid QRegularExpression, then the
returned QRegularExpressionMatch object will be invalid as well (that is,
putting the pattern between the \c{^} and the \c{$} anchors is enough
in most cases:
- \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 24
+ \snippet code/src_corelib_tools_qregularexpression.cpp 24
However, remember that the \c{$} anchor not only matches at the end of the
string, but also at a newline character right before the end of the string;
that is, the previous pattern matches against the string "this pattern must
- match exactly\n". Also, the behaviour of both the \c{^} and the \c{$}
+ match exactly\\n". Also, the behaviour of both the \c{^} and the \c{$}
anchors changes if the MultiLineOption is set either explicitely (as a
pattern option) or implicitly (as a directive inside the pattern string).
Therefore, in the most general case, you should wrap the pattern between
the \c{\A} and the \c{\z} anchors:
- \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 25
+ \snippet code/src_corelib_tools_qregularexpression.cpp 25
Note the usage of the non-capturing group in order to preserve the meaning
of the branch operator inside the pattern.
returns each substring captured, either by the capturing group's index or
by its name:
- \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 29
+ \snippet code/src_corelib_tools_qregularexpression.cpp 29
For each captured substring it is possible to query its starting and ending
offsets in the subject string by calling the capturedStart() and the
For instance:
- \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 30
+ \snippet code/src_corelib_tools_qregularexpression.cpp 30
Moreover, QRegularExpressionMatchIterator offers a peekNext() function
to get the next result \e{without} advancing the iterator.
meaning when used as a regular expression pattern string, and returns
the escaped string. For instance:
- \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 26
+ \snippet code/src_corelib_tools_qregularexpression.cpp 26
This is very convenient in order to build patterns from arbitrary strings:
- \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 27
+ \snippet code/src_corelib_tools_qregularexpression.cpp 27
\note This function implements Perl's quotemeta algorithm and escapes with
a backslash all characters in \a str, except for the characters in the
including the implicit capturing group 0. This can be used to extract all
the substrings that were captured:
- \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 28
+ \snippet code/src_corelib_tools_qregularexpression.cpp 28
Note that some of the capturing groups with an index less than
lastCapturedIndex() could have not matched, and therefore captured nothing.
Consider this function which does heap allocations, and have various exit points:
- \snippet doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp 0
+ \snippet code/src_corelib_tools_qscopedpointer.cpp 0
It's encumbered by the manual delete calls. With QScopedPointer, the code
can be simplified to:
- \snippet doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp 1
+ \snippet code/src_corelib_tools_qscopedpointer.cpp 1
The code the compiler generates for QScopedPointer is the same as when
writing it manually. Code that makes use of \a delete are candidates for
The const qualification on a regular C++ pointer can also be expressed with
a QScopedPointer:
- \snippet doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp 2
+ \snippet code/src_corelib_tools_qscopedpointer.cpp 2
\section1 Custom cleanup handlers
You can pass your own classes as handlers, provided that they have a public
static function \c{void cleanup(T *pointer)}.
- \snippet doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp 5
+ \snippet code/src_corelib_tools_qscopedpointer.cpp 5
\section1 Forward Declared Pointers
points to a forward declared class must have non-inline constructors,
destructors and assignment operators:
- \snippet doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp 4
+ \snippet code/src_corelib_tools_qscopedpointer.cpp 4
Otherwise, the compiler output a warning about not being able to destruct
\c MyPrivateClass.
Returns \c true if this object is not \c null. This function is suitable
for use in \tt if-constructs, like:
- \snippet doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp 3
+ \snippet code/src_corelib_tools_qscopedpointer.cpp 3
\sa isNull()
*/
Here's an example QSet with QString values:
- \snippet doc/src/snippets/code/doc_src_qset.cpp 0
+ \snippet code/doc_src_qset.cpp 0
To insert a value into the set, use insert():
- \snippet doc/src/snippets/code/doc_src_qset.cpp 1
+ \snippet code/doc_src_qset.cpp 1
Another way to insert items into the set is to use operator<<():
- \snippet doc/src/snippets/code/doc_src_qset.cpp 2
+ \snippet code/doc_src_qset.cpp 2
To test whether an item belongs to the set or not, use contains():
- \snippet doc/src/snippets/code/doc_src_qset.cpp 3
+ \snippet code/doc_src_qset.cpp 3
If you want to navigate through all the values stored in a QSet,
you can use an iterator. QSet supports both \l{Java-style
iterators} (QSet::iterator and QSet::const_iterator). Here's how
to iterate over a QSet<QWidget *> using a Java-style iterator:
- \snippet doc/src/snippets/code/doc_src_qset.cpp 4
+ \snippet code/doc_src_qset.cpp 4
Here's the same code, but using an STL-style iterator:
- \snippet doc/src/snippets/code/doc_src_qset.cpp 5
+ \snippet code/doc_src_qset.cpp 5
QSet is unordered, so an iterator's sequence cannot be assumed to
be predictable. If ordering by key is required, use a QMap.
To navigate through a QSet, you can also use \l{foreach}:
- \snippet doc/src/snippets/code/doc_src_qset.cpp 6
+ \snippet code/doc_src_qset.cpp 6
Items can be removed from the set using remove(). There is also a
clear() function that removes all items.
This function is useful for code that needs to build a huge set
and wants to avoid repeated reallocation. For example:
- \snippet doc/src/snippets/code/doc_src_qset.cpp 7
+ \snippet code/doc_src_qset.cpp 7
Ideally, \a size should be slightly more than the maximum number
of elements expected in the set. \a size doesn't have to be prime,
start iterating. Here's a typical loop that prints all the items
stored in a set:
- \snippet doc/src/snippets/code/doc_src_qset.cpp 8
+ \snippet code/doc_src_qset.cpp 8
Here's a loop that removes certain items (all those that start
with 'J') from a set while iterating:
- \snippet doc/src/snippets/code/doc_src_qset.cpp 9
+ \snippet code/doc_src_qset.cpp 9
STL-style iterators can be used as arguments to \l{generic
algorithms}. For example, here's how to find an item in the set
using the qFind() algorithm:
- \snippet doc/src/snippets/code/doc_src_qset.cpp 10
+ \snippet code/doc_src_qset.cpp 10
Multiple iterators can be used on the same set. However, you may
not attempt to modify the container while iterating on it.
start iterating. Here's a typical loop that prints all the items
stored in a set:
- \snippet doc/src/snippets/code/doc_src_qset.cpp 11
+ \snippet code/doc_src_qset.cpp 11
STL-style iterators can be used as arguments to \l{generic
algorithms}. For example, here's how to find an item in the set
using the qFind() algorithm:
- \snippet doc/src/snippets/code/doc_src_qset.cpp 12
+ \snippet code/doc_src_qset.cpp 12
Multiple iterators can be used on the same set. However, you may
not attempt to modify the container while iterating on it.
Example:
- \snippet doc/src/snippets/code/doc_src_qset.cpp 13
+ \snippet code/doc_src_qset.cpp 13
\sa fromList(), QList::fromSet(), qSort()
*/
Example:
- \snippet doc/src/snippets/code/doc_src_qset.cpp 14
+ \snippet code/doc_src_qset.cpp 14
\sa toList(), QList::toSet()
*/
implicitly shared \c Employee class. In the header file we define the
two classes \c Employee and \c EmployeeData.
- \snippet doc/src/snippets/sharedemployee/employee.h 0
+ \snippet sharedemployee/employee.h 0
In class \c Employee, note the single data member, a \e {d pointer}
of type \c {QSharedDataPointer<EmployeeData>}. All accesses of
straightforward. Both create a new instance of \c EmployeeData
and assign it to the \e{d pointer} .
- \snippet doc/src/snippets/sharedemployee/employee.h 1
+ \snippet sharedemployee/employee.h 1
\codeline
- \snippet doc/src/snippets/sharedemployee/employee.h 2
+ \snippet sharedemployee/employee.h 2
Note that class \c Employee also has a trivial copy constructor
defined, which is not strictly required in this case.
- \snippet doc/src/snippets/sharedemployee/employee.h 7
+ \snippet sharedemployee/employee.h 7
The copy constructor is not strictly required here, because class \c
EmployeeData is included in the same file as class \c Employee
detach() to ensure that the function operates on its own copy of the
data.
- \snippet doc/src/snippets/sharedemployee/employee.h 3
+ \snippet sharedemployee/employee.h 3
\codeline
- \snippet doc/src/snippets/sharedemployee/employee.h 4
+ \snippet sharedemployee/employee.h 4
Note that if detach() is called more than once in a member function
due to multiple dereferences of the \e {d pointer}, detach() will
In \c Employee's \e const member functions, dereferencing the \e {d
pointer} does \e not cause detach() to be called.
- \snippet doc/src/snippets/sharedemployee/employee.h 5
+ \snippet sharedemployee/employee.h 5
\codeline
- \snippet doc/src/snippets/sharedemployee/employee.h 6
+ \snippet sharedemployee/employee.h 6
Notice that there is no need to implement a copy constructor or an
assignment operator for the \c Employee class, because the copy
Consider a simple example that creates two instances of the
implicitly shared \c Employee class.
- \snippet doc/src/snippets/sharedemployee/main.cpp 0
+ \snippet sharedemployee/main.cpp 0
After the second employee e2 is created and e1 is assigned to it,
both \c e1 and \c e2 refer to Albrecht Durer, employee 1001. Both \c
\endlist
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qsize.cpp 0
+ \snippet code/src_corelib_tools_qsize.cpp 0
\sa setWidth(), setHeight(), scaled()
*/
Using a reference makes it possible to manipulate the width
directly. For example:
- \snippet doc/src/snippets/code/src_corelib_tools_qsize.cpp 1
+ \snippet code/src_corelib_tools_qsize.cpp 1
\sa rheight(), setWidth()
*/
Using a reference makes it possible to manipulate the height
directly. For example:
- \snippet doc/src/snippets/code/src_corelib_tools_qsize.cpp 2
+ \snippet code/src_corelib_tools_qsize.cpp 2
\sa rwidth(), setHeight()
*/
Adds the given \a size to \e this size, and returns a reference to
this size. For example:
- \snippet doc/src/snippets/code/src_corelib_tools_qsize.cpp 3
+ \snippet code/src_corelib_tools_qsize.cpp 3
*/
/*!
Subtracts the given \a size from \e this size, and returns a
reference to this size. For example:
- \snippet doc/src/snippets/code/src_corelib_tools_qsize.cpp 4
+ \snippet code/src_corelib_tools_qsize.cpp 4
*/
/*!
\endlist
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qsize.cpp 5
+ \snippet code/src_corelib_tools_qsize.cpp 5
\sa setWidth(), setHeight(), scaled()
*/
*/
/*!
- \fn QSizeF QSizeF::scaled(int width, int height, Qt::AspectRatioMode mode) const
+ \fn QSizeF QSizeF::scaled(qreal width, qreal height, Qt::AspectRatioMode mode) const
\since 5.0
Returns a size scaled to a rectangle with the given \a width and
- \a height, according to the specified \mode.
+ \a height, according to the specified \a mode.
\sa scale()
*/
Using a reference makes it possible to manipulate the width
directly. For example:
- \snippet doc/src/snippets/code/src_corelib_tools_qsize.cpp 6
+ \snippet code/src_corelib_tools_qsize.cpp 6
\sa rheight(), setWidth()
*/
Using a reference makes it possible to manipulate the height
directly. For example:
- \snippet doc/src/snippets/code/src_corelib_tools_qsize.cpp 7
+ \snippet code/src_corelib_tools_qsize.cpp 7
\sa rwidth(), setHeight()
*/
Adds the given \a size to this size and returns a reference to
this size. For example:
- \snippet doc/src/snippets/code/src_corelib_tools_qsize.cpp 8
+ \snippet code/src_corelib_tools_qsize.cpp 8
*/
/*!
Subtracts the given \a size from this size and returns a reference
to this size. For example:
- \snippet doc/src/snippets/code/src_corelib_tools_qsize.cpp 9
+ \snippet code/src_corelib_tools_qsize.cpp 9
*/
/*!
Example:
- \snippet doc/src/snippets/qstack/main.cpp 0
+ \snippet qstack/main.cpp 0
The example will output 3, 2, 1 in that order.
Most of the QChar member functions also exist in QCharRef.
However, they are not explicitly documented here.
- \sa QString::operator[]() QString::at() QChar
+ \sa QString::operator[](), QString::at(), QChar
*/
/*!
*} to its constructor. For example, the following code creates a
QString of size 5 containing the data "Hello":
- \snippet doc/src/snippets/qstring/main.cpp 0
+ \snippet qstring/main.cpp 0
QString converts the \c{const char *} data into Unicode using the
fromAscii() function. fromAscii() treats ordinals above 128 as Latin-1
You can also provide string data as an array of \l{QChar}s:
- \snippet doc/src/snippets/qstring/main.cpp 1
+ \snippet qstring/main.cpp 1
QString makes a deep copy of the QChar data, so you can modify it
later without experiencing side effects. (If for performance
character that can be used on the left side of an assignment. For
example:
- \snippet doc/src/snippets/qstring/main.cpp 2
+ \snippet qstring/main.cpp 2
For read-only access, an alternative syntax is to use the at()
function:
- \snippet doc/src/snippets/qstring/main.cpp 3
+ \snippet qstring/main.cpp 3
The at() function can be faster than \l operator[](), because it
never causes a \l{deep copy} to occur. Alternatively, use the
usage. For example, if you want to compare a QString with a string
literal, you can write code like this and it will work as expected:
- \snippet doc/src/snippets/qstring/main.cpp 4
+ \snippet qstring/main.cpp 4
You can also pass string literals to functions that take QStrings
as arguments, invoking the QString(const char *)
character data: append(), prepend(), insert(), replace(), and
remove(). For example:
- \snippet doc/src/snippets/qstring/main.cpp 5
+ \snippet qstring/main.cpp 5
If you are building a QString gradually and know in advance
approximately how many characters the QString will contain, you
they return -1. For example, here's a typical loop that finds all
occurrences of a particular substring:
- \snippet doc/src/snippets/qstring/main.cpp 6
+ \snippet qstring/main.cpp 6
QString provides many functions for converting numbers into
strings and strings into numbers. See the arg() functions, the
application is to add the following entry to your
\l{qmake Project Files}{qmake project file}:
- \snippet doc/src/snippets/code/src_corelib_tools_qstring.cpp 0
+ \snippet code/src_corelib_tools_qstring.cpp 0
You then need to explicitly call fromAscii(), fromLatin1(),
fromUtf8(), or fromLocal8Bit() to construct a QString from an
8-bit string, or use the lightweight QLatin1String class, for
example:
- \snippet doc/src/snippets/code/src_corelib_tools_qstring.cpp 1
+ \snippet code/src_corelib_tools_qstring.cpp 1
Similarly, you must call toAscii(), toLatin1(), toUtf8(), or
toLocal8Bit() explicitly to convert the QString to an 8-bit
\l{implicitly shared}, QStrings may be treated like \c{int}s or
other basic types. For example:
- \snippet doc/src/snippets/qstring/main.cpp 7
+ \snippet qstring/main.cpp 7
The \c result variable, is a normal variable allocated on the
stack. When \c return is called, and because we're returning by
string with size 0. A null string is always empty, but an empty
string isn't necessarily null:
- \snippet doc/src/snippets/qstring/main.cpp 8
+ \snippet qstring/main.cpp 8
All functions except isNull() treat null strings the same as empty
strings. For example, toAscii().constData() returns a pointer to a
complex string from multiple substrings. You will often write code
like this:
- \snippet doc/src/snippets/qstring/stringbuilder.cpp 0
+ \snippet qstring/stringbuilder.cpp 0
There is nothing wrong with either of these string constructions,
but there are a few hidden inefficiencies. Beginning with Qt 4.6,
\c{QStringBuilder} wherever you want to use it, and use the
\c{'%'} operator instead of \c{'+'} when concatenating strings:
- \snippet doc/src/snippets/qstring/stringbuilder.cpp 5
+ \snippet qstring/stringbuilder.cpp 5
A more global approach which is the most convenient but
not entirely source compatible, is to this define in your
.pro file:
- \snippet doc/src/snippets/qstring/stringbuilder.cpp 3
+ \snippet qstring/stringbuilder.cpp 3
and the \c{'+'} will automatically be performed as the
\c{QStringBuilder} \c{'%'} everywhere.
Example:
- \snippet doc/src/snippets/qstring/main.cpp 45
+ \snippet qstring/main.cpp 45
If you want to append a certain number of identical characters to
the string, use \l operator+=() as follows rather than resize():
- \snippet doc/src/snippets/qstring/main.cpp 46
+ \snippet qstring/main.cpp 46
If you want to expand the string so that it reaches a certain
width and fill the new positions with a particular character, use
If \a size is negative, it is equivalent to passing zero.
- \snippet doc/src/snippets/qstring/main.cpp 47
+ \snippet qstring/main.cpp 47
\sa truncate(), reserve()
*/
we're fairly sure that size is large enough to make a call to
reserve() worthwhile:
- \snippet doc/src/snippets/qstring/main.cpp 44
+ \snippet qstring/main.cpp 44
\sa squeeze(), capacity()
*/
Example:
- \snippet doc/src/snippets/qstring/main.cpp 26
+ \snippet qstring/main.cpp 26
If the given \a position is greater than size(), the array is
first extended using resize().
Example:
- \snippet doc/src/snippets/qstring/main.cpp 9
+ \snippet qstring/main.cpp 9
This is the same as using the insert() function:
- \snippet doc/src/snippets/qstring/main.cpp 10
+ \snippet qstring/main.cpp 10
The append() function is typically very fast (\l{constant time}),
because QString preallocates extra space at the end of the string
Example:
- \snippet doc/src/snippets/qstring/main.cpp 36
+ \snippet qstring/main.cpp 36
\sa append(), insert()
*/
position + \a n is beyond the end of the string, the string is
truncated at the specified \a position.
- \snippet doc/src/snippets/qstring/main.cpp 37
+ \snippet qstring/main.cpp 37
\sa insert(), replace()
*/
Example:
- \snippet doc/src/snippets/qstring/main.cpp 38
+ \snippet qstring/main.cpp 38
This is the same as \c replace(ch, "", cs).
Removes every occurrence of the regular expression \a rx in the
string, and returns a reference to the string. For example:
- \snippet doc/src/snippets/qstring/main.cpp 39
+ \snippet qstring/main.cpp 39
\sa indexOf(), lastIndexOf(), replace()
*/
Removes every occurrence of the regular expression \a re in the
string, and returns a reference to the string. For example:
- \snippet doc/src/snippets/qstring/main.cpp 96
+ \snippet qstring/main.cpp 96
\sa indexOf(), lastIndexOf(), replace()
*/
Example:
- \snippet doc/src/snippets/qstring/main.cpp 40
+ \snippet qstring/main.cpp 40
\sa insert(), remove()
*/
Example:
- \snippet doc/src/snippets/qstring/main.cpp 41
+ \snippet qstring/main.cpp 41
\note The replacement text is not rescanned after it is inserted.
Example:
- \snippet doc/src/snippets/qstring/main.cpp 86
+ \snippet qstring/main.cpp 86
*/
QString &QString::replace(const QString &before, const QString &after, Qt::CaseSensitivity cs)
{
\overload operator<()
The \a other byte array is converted to a QString using the
- fromAscii() function. If any NUL characters ('\0') are embedded
+ fromAscii() function. If any NUL characters ('\\0') are embedded
in the byte array, they will be included in the transformation.
You can disable this operator by defining \c
go through QObject::tr(), for example.
*/
-/*! \fn bool operator<=(const QString &s1, const QString &s2)
- \relates QString
+/*! \fn bool QString::operator<=(const QString &s1, const QString &s2)
Returns true if string \a s1 is lexically less than or equal to
string \a s2; otherwise returns false.
\overload operator<=()
The \a other byte array is converted to a QString using the
- fromAscii() function. If any NUL characters ('\0') are embedded
+ fromAscii() function. If any NUL characters ('\\0') are embedded
in the byte array, they will be included in the transformation.
You can disable this operator by defining \c
go through QObject::tr(), for example.
*/
-/*! \fn bool operator>(const QString &s1, const QString &s2)
- \relates QString
+/*! \fn bool QString::operator>(const QString &s1, const QString &s2)
Returns true if string \a s1 is lexically greater than string \a
s2; otherwise returns false.
\overload operator>()
The \a other byte array is converted to a QString using the
- fromAscii() function. If any NUL characters ('\0') are embedded
+ fromAscii() function. If any NUL characters ('\\0') are embedded
in the byte array, they will be included in the transformation.
You can disable this operator by defining \c
\overload operator>=()
The \a other byte array is converted to a QString using the
- fromAscii() function. If any NUL characters ('\0') are embedded in
+ fromAscii() function. If any NUL characters ('\\0') are embedded in
the byte array, they will be included in the transformation.
You can disable this operator by defining \c QT_NO_CAST_FROM_ASCII
\overload operator!=()
The \a other byte array is converted to a QString using the
- fromAscii() function. If any NUL characters ('\0') are embedded
+ fromAscii() function. If any NUL characters ('\\0') are embedded
in the byte array, they will be included in the transformation.
You can disable this operator by defining \c QT_NO_CAST_FROM_ASCII
Example:
- \snippet doc/src/snippets/qstring/main.cpp 24
+ \snippet qstring/main.cpp 24
If \a from is -1, the search starts at the last character; if it is
-2, at the next to last character and so on.
Example:
- \snippet doc/src/snippets/qstring/main.cpp 24
+ \snippet qstring/main.cpp 24
If \a from is -1, the search starts at the last character; if it is
-2, at the next to last character and so on.
Example:
- \snippet doc/src/snippets/qstring/main.cpp 29
+ \snippet qstring/main.cpp 29
\sa indexOf(), contains(), count()
*/
Example:
- \snippet doc/src/snippets/qstring/main.cpp 29
+ \snippet qstring/main.cpp 29
\sa indexOf(), contains(), count()
*/
string with \a after. Returns a reference to the string. For
example:
- \snippet doc/src/snippets/qstring/main.cpp 42
+ \snippet qstring/main.cpp 42
For regular expressions containing \l{capturing parentheses},
occurrences of \b{\\1}, \b{\\2}, ..., in \a after are replaced
with \a{rx}.cap(1), cap(2), ...
- \snippet doc/src/snippets/qstring/main.cpp 43
+ \snippet qstring/main.cpp 43
\sa indexOf(), lastIndexOf(), remove(), QRegExp::cap()
*/
string with \a after. Returns a reference to the string. For
example:
- \snippet doc/src/snippets/qstring/main.cpp 87
+ \snippet qstring/main.cpp 87
For regular expressions containing capturing groups,
- occurrences of \bold{\\1}, \bold{\\2}, ..., in \a after are replaced
+ occurrences of \b{\\1}, \b{\\2}, ..., in \a after are replaced
with the string captured by the corresponding capturing group.
- \snippet doc/src/snippets/qstring/main.cpp 88
+ \snippet qstring/main.cpp 88
\sa indexOf(), lastIndexOf(), remove(), QRegularExpression, QRegularExpressionMatch
*/
case sensitive; otherwise the search is case insensitive.
Example:
- \snippet doc/src/snippets/qstring/main.cpp 17
+ \snippet qstring/main.cpp 17
\sa indexOf(), count()
*/
Example:
- \snippet doc/src/snippets/qstring/main.cpp 25
+ \snippet qstring/main.cpp 25
*/
int QString::indexOf(const QRegExp& rx, int from) const
{
Example:
- \snippet doc/src/snippets/qstring/main.cpp 25
+ \snippet qstring/main.cpp 25
*/
int QString::indexOf(QRegExp& rx, int from) const
{
Example:
- \snippet doc/src/snippets/qstring/main.cpp 30
+ \snippet qstring/main.cpp 30
*/
int QString::lastIndexOf(const QRegExp& rx, int from) const
{
Example:
- \snippet doc/src/snippets/qstring/main.cpp 30
+ \snippet qstring/main.cpp 30
*/
int QString::lastIndexOf(QRegExp& rx, int from) const
{
This function counts overlapping matches, so in the example
below, there are four instances of "ana" or "ama":
- \snippet doc/src/snippets/qstring/main.cpp 18
+ \snippet qstring/main.cpp 18
*/
int QString::count(const QRegExp& rx) const
Example:
- \snippet doc/src/snippets/qstring/main.cpp 93
+ \snippet qstring/main.cpp 93
*/
int QString::indexOf(const QRegularExpression& re, int from) const
{
Example:
- \snippet doc/src/snippets/qstring/main.cpp 94
+ \snippet qstring/main.cpp 94
*/
int QString::lastIndexOf(const QRegularExpression &re, int from) const
{
This function counts overlapping matches, so in the example
below, there are four instances of "ana" or "ama":
- \snippet doc/src/snippets/qstring/main.cpp 95
+ \snippet qstring/main.cpp 95
*/
int QString::count(const QRegularExpression &re) const
{
to skip empty fields and how to deal with leading and trailing
separators; see \l{SectionFlags}.
- \snippet doc/src/snippets/qstring/main.cpp 52
+ \snippet qstring/main.cpp 52
If \a start or \a end is negative, we count fields from the right
of the string, the right-most field being -1, the one from
right-most field being -2, and so on.
- \snippet doc/src/snippets/qstring/main.cpp 53
+ \snippet qstring/main.cpp 53
\sa split()
*/
/*!
\overload section()
- \snippet doc/src/snippets/qstring/main.cpp 51
- \snippet doc/src/snippets/qstring/main.cpp 54
+ \snippet qstring/main.cpp 51
+ \snippet qstring/main.cpp 54
\sa split()
*/
This string is treated as a sequence of fields separated by the
regular expression, \a reg.
- \snippet doc/src/snippets/qstring/main.cpp 55
+ \snippet qstring/main.cpp 55
\warning Using this QRegExp version is much more expensive than
the overloaded string and character versions.
- \sa split() simplified()
+ \sa split(), simplified()
*/
QString QString::section(const QRegExp ®, int start, int end, SectionFlags flags) const
{
This string is treated as a sequence of fields separated by the
regular expression, \a re.
- \snippet doc/src/snippets/qstring/main.cpp 89
+ \snippet qstring/main.cpp 89
\warning Using this QRegularExpression version is much more expensive than
the overloaded string and character versions.
- \sa split() simplified()
+ \sa split(), simplified()
*/
QString QString::section(const QRegularExpression &re, int start, int end, SectionFlags flags) const
{
The entire string is returned if \a n is greater than size() or
less than zero.
- \snippet doc/src/snippets/qstring/main.cpp 31
+ \snippet qstring/main.cpp 31
\sa right(), mid(), startsWith()
*/
The entire string is returned if \a n is greater than size() or
less than zero.
- \snippet doc/src/snippets/qstring/main.cpp 48
+ \snippet qstring/main.cpp 48
\sa left(), mid(), endsWith()
*/
Example:
- \snippet doc/src/snippets/qstring/main.cpp 34
+ \snippet qstring/main.cpp 34
\sa left(), right()
*/
If \a cs is Qt::CaseSensitive (default), the search is
case sensitive; otherwise the search is case insensitive.
- \snippet doc/src/snippets/qstring/main.cpp 65
+ \snippet qstring/main.cpp 65
\sa endsWith()
*/
If \a cs is Qt::CaseSensitive (default), the search is case
sensitive; otherwise the search is case insensitive.
- \snippet doc/src/snippets/qstring/main.cpp 20
+ \snippet qstring/main.cpp 20
\sa startsWith()
*/
Example:
- \snippet doc/src/snippets/qstring/main.cpp 57
+ \snippet qstring/main.cpp 57
\sa trimmed()
*/
Example:
- \snippet doc/src/snippets/qstring/main.cpp 82
+ \snippet qstring/main.cpp 82
Unlike simplified(), trimmed() leaves internal whitespace alone.
Example:
- \snippet doc/src/snippets/qstring/main.cpp 85
+ \snippet qstring/main.cpp 85
The return value is of type QCharRef, a helper class for QString.
When you get an object of type QCharRef, you can use it as if it
Example:
- \snippet doc/src/snippets/qstring/main.cpp 83
+ \snippet qstring/main.cpp 83
If \a position is negative, it is equivalent to passing zero.
If \a n is greater than size(), the result is an empty string.
Example:
- \snippet doc/src/snippets/qstring/main.cpp 15
+ \snippet qstring/main.cpp 15
If you want to remove characters from the \e beginning of the
string, use remove() instead.
Example:
- \snippet doc/src/snippets/qstring/main.cpp 21
+ \snippet qstring/main.cpp 21
\sa resize()
*/
Example:
- \snippet doc/src/snippets/qstring/main.cpp 58
+ \snippet qstring/main.cpp 58
\sa isEmpty(), resize()
*/
Example:
- \snippet doc/src/snippets/qstring/main.cpp 28
+ \snippet qstring/main.cpp 28
Qt makes a distinction between null strings and empty strings for
historical reasons. For most applications, what matters is
Example:
- \snippet doc/src/snippets/qstring/main.cpp 27
+ \snippet qstring/main.cpp 27
\sa size()
*/
Example:
- \snippet doc/src/snippets/qstring/main.cpp 84
+ \snippet qstring/main.cpp 84
This operation is typically very fast (\l{constant time}),
because QString preallocates extra space at the end of the string
\overload operator+=()
Appends the byte array \a ba to this string. The byte array is converted
- to Unicode using the fromAscii() function. If any NUL characters ('\0')
+ to Unicode using the fromAscii() function. If any NUL characters ('\\0')
are embedded in the \a ba byte array, they will be included in the
transformation.
a human would expect. Consider sorting user-visible strings with
localeAwareCompare().
- \snippet doc/src/snippets/qstring/main.cpp 16
+ \snippet qstring/main.cpp 16
\sa operator==(), operator<(), operator>()
*/
If \a truncate is false and the size() of the string is more than
\a width, then the returned string is a copy of the string.
- \snippet doc/src/snippets/qstring/main.cpp 32
+ \snippet qstring/main.cpp 32
If \a truncate is true and the size() of the string is more than
\a width, then any characters in a copy of the string after
position \a width are removed, and the copy is returned.
- \snippet doc/src/snippets/qstring/main.cpp 33
+ \snippet qstring/main.cpp 33
\sa rightJustified()
*/
Returns a string of size() \a width that contains the \a fill
character followed by the string. For example:
- \snippet doc/src/snippets/qstring/main.cpp 49
+ \snippet qstring/main.cpp 49
If \a truncate is false and the size() of the string is more than
\a width, then the returned string is a copy of the string.
\a width, then the resulting string is truncated at position \a
width.
- \snippet doc/src/snippets/qstring/main.cpp 50
+ \snippet qstring/main.cpp 50
\sa leftJustified()
*/
/*!
Returns a lowercase copy of the string.
- \snippet doc/src/snippets/qstring/main.cpp 75
+ \snippet qstring/main.cpp 75
The case conversion will always happen in the 'C' locale. For locale dependent
case folding use QLocale::toLower()
/*!
Returns an uppercase copy of the string.
- \snippet doc/src/snippets/qstring/main.cpp 81
+ \snippet qstring/main.cpp 81
The case conversion will always happen in the 'C' locale. For locale dependent
case folding use QLocale::toUpper()
\c{long long}). If you need those, use the standard snprintf()
function instead:
- \snippet doc/src/snippets/qstring/main.cpp 63
+ \snippet qstring/main.cpp 63
\warning We do not recommend using QString::sprintf() in new Qt
code. Instead, consider using QTextStream or arg(), both of
which support Unicode strings seamlessly and are type-safe.
Here's an example that uses QTextStream:
- \snippet doc/src/snippets/qstring/main.cpp 64
+ \snippet qstring/main.cpp 64
For \l {QObject::tr()}{translations}, especially if the strings
contains more than one escape sequence, you should consider using
Example:
- \snippet doc/src/snippets/qstring/main.cpp 74
+ \snippet qstring/main.cpp 74
\sa number(), toULongLong(), toInt(), QLocale::toLongLong()
*/
Example:
- \snippet doc/src/snippets/qstring/main.cpp 79
+ \snippet qstring/main.cpp 79
\sa number(), toLongLong(), QLocale::toULongLong()
*/
Example:
- \snippet doc/src/snippets/qstring/main.cpp 73
+ \snippet qstring/main.cpp 73
\sa number(), toULong(), toInt(), QLocale::toLong()
*/
Example:
- \snippet doc/src/snippets/qstring/main.cpp 78
+ \snippet qstring/main.cpp 78
\sa number(), QLocale::toULong()
*/
Example:
- \snippet doc/src/snippets/qstring/main.cpp 72
+ \snippet qstring/main.cpp 72
\sa number(), toUInt(), toDouble(), QLocale::toInt()
*/
Example:
- \snippet doc/src/snippets/qstring/main.cpp 77
+ \snippet qstring/main.cpp 77
\sa number(), toInt(), QLocale::toUInt()
*/
Example:
- \snippet doc/src/snippets/qstring/main.cpp 76
+ \snippet qstring/main.cpp 76
\sa number(), toUShort(), toInt(), QLocale::toShort()
*/
Example:
- \snippet doc/src/snippets/qstring/main.cpp 80
+ \snippet qstring/main.cpp 80
\sa number(), toShort(), QLocale::toUShort()
*/
If a conversion error occurs, \c{*}\a{ok} is set to false;
otherwise \c{*}\a{ok} is set to true.
- \snippet doc/src/snippets/qstring/main.cpp 66
+ \snippet qstring/main.cpp 66
Various string formats for floating point numbers can be converted
to double values:
- \snippet doc/src/snippets/qstring/main.cpp 67
+ \snippet qstring/main.cpp 67
The string conversion will always happen in the 'C' locale. For locale
dependent conversion use QLocale::toDouble()
- \snippet doc/src/snippets/qstring/main.cpp 68
+ \snippet qstring/main.cpp 68
For historic reasons, this function does not handle
thousands group separators. If you need to convert such numbers,
use QLocale::toDouble().
- \snippet doc/src/snippets/qstring/main.cpp 69
+ \snippet qstring/main.cpp 69
- \sa number() QLocale::setDefault() QLocale::toDouble() trimmed()
+ \sa number(), QLocale::setDefault(), QLocale::toDouble(), trimmed()
*/
double QString::toDouble(bool *ok) const
Example:
- \snippet doc/src/snippets/qstring/main.cpp 71
+ \snippet qstring/main.cpp 71
\sa number(), toDouble(), toInt(), QLocale::toFloat()
*/
The base is 10 by default and must be between 2 and 36. For bases
other than 10, \a n is treated as an unsigned integer.
- \snippet doc/src/snippets/qstring/main.cpp 56
+ \snippet qstring/main.cpp 56
The formatting always uses QLocale::C, i.e., English/UnitedStates.
To get a localized string representation of a number, use
To get a localized string representation of a number, use
QLocale::toString() with the appropriate locale.
- \snippet doc/src/snippets/qstring/main.cpp 35
+ \snippet qstring/main.cpp 35
\sa setNum()
*/
Example:
- \snippet doc/src/snippets/qstring/main.cpp 62
+ \snippet qstring/main.cpp 62
\sa QStringList::join(), section()
*/
Here's an example where we extract the words in a sentence
using one or more whitespace characters as the separator:
- \snippet doc/src/snippets/qstring/main.cpp 59
+ \snippet qstring/main.cpp 59
Here's a similar example, but this time we use any sequence of
non-word characters as the separator:
- \snippet doc/src/snippets/qstring/main.cpp 60
+ \snippet qstring/main.cpp 60
Here's a third example where we use a zero-length assertion,
\b{\\b} (word boundary), to split the string into an
alternating sequence of non-word and word tokens:
- \snippet doc/src/snippets/qstring/main.cpp 61
+ \snippet qstring/main.cpp 61
\sa QStringList::join(), section()
*/
Here's an example where we extract the words in a sentence
using one or more whitespace characters as the separator:
- \snippet doc/src/snippets/qstring/main.cpp 90
+ \snippet qstring/main.cpp 90
Here's a similar example, but this time we use any sequence of
non-word characters as the separator:
- \snippet doc/src/snippets/qstring/main.cpp 91
+ \snippet qstring/main.cpp 91
Here's a third example where we use a zero-length assertion,
- \bold{\\b} (word boundary), to split the string into an
+ \b{\\b} (word boundary), to split the string into an
alternating sequence of non-word and word tokens:
- \snippet doc/src/snippets/qstring/main.cpp 92
+ \snippet qstring/main.cpp 92
\sa QStringList::join(), section()
*/
This example shows how we might create a \c status string for
reporting progress while processing a list of files:
- \snippet doc/src/snippets/qstring/main.cpp 11
+ \snippet qstring/main.cpp 11
First, \c arg(i) replaces \c %1. Then \c arg(total) replaces \c
%2. Finally, \c arg(fileName) replaces \c %3.
strings \a a1 and \a a2 are replaced in one pass. This can make a
difference if \a a1 contains e.g. \c{%1}:
- \snippet doc/src/snippets/qstring/main.cpp 13
+ \snippet qstring/main.cpp 13
*/
/*!
locale was specified, the "C" locale is used. The 'L' flag is
ignored if \a base is not 10.
- \snippet doc/src/snippets/qstring/main.cpp 12
- \snippet doc/src/snippets/qstring/main.cpp 14
+ \snippet qstring/main.cpp 12
+ \snippet qstring/main.cpp 14
If \a fillChar is '0' (the number 0, ASCII 48), the locale's zero is
used. For negative numbers, zero padding might appear before the
using QLocale::setDefault(). The 'L' flag is ignored if \a base is
not 10.
- \snippet doc/src/snippets/qstring/main.cpp 12
- \snippet doc/src/snippets/qstring/main.cpp 14
+ \snippet qstring/main.cpp 12
+ \snippet qstring/main.cpp 14
If \a fillChar is '0' (the number 0, ASCII 48), the locale's zero is
used. For negative numbers, zero padding might appear before the
value produces right-aligned text; a negative value produces
left-aligned text.
- \snippet doc/src/snippets/code/src_corelib_tools_qstring.cpp 2
+ \snippet code/src_corelib_tools_qstring.cpp 2
The '%' can be followed by an 'L', in which case the sequence is
replaced with a localized representation of \a a. The conversion
Example:
- \snippet doc/src/snippets/qstring/main.cpp 19
+ \snippet qstring/main.cpp 19
Note that the pointer remains valid only as long as the string is
not modified by other means. For read-only access, constData() is
Here's an example of how we can use a QRegExp on raw data in
memory without requiring to copy the data into a QString:
- \snippet doc/src/snippets/qstring/main.cpp 22
- \snippet doc/src/snippets/qstring/main.cpp 23
+ \snippet qstring/main.cpp 22
+ \snippet qstring/main.cpp 23
\warning A string created with fromRawData() is \e not
'\\0'-terminated, unless the raw data contains a '\\0' character
the \c{const char *} data. For example, assuming \c str is a
QString,
- \snippet doc/src/snippets/code/src_corelib_tools_qstring.cpp 3
+ \snippet code/src_corelib_tools_qstring.cpp 3
is much faster than
- \snippet doc/src/snippets/code/src_corelib_tools_qstring.cpp 4
+ \snippet code/src_corelib_tools_qstring.cpp 4
because it doesn't construct four temporary QString objects and
make a deep copy of the character data.
just a very thin wrapper around a \c{const char *}. Using
QLatin1String, the example code above becomes
- \snippet doc/src/snippets/code/src_corelib_tools_qstring.cpp 5
+ \snippet code/src_corelib_tools_qstring.cpp 5
This is a bit longer to type, but it provides exactly the same
benefits as the first version of the code, and is faster than
QLatin1String can be used everywhere a QString is expected. For
example:
- \snippet doc/src/snippets/code/src_corelib_tools_qstring.cpp 6
+ \snippet code/src_corelib_tools_qstring.cpp 6
\sa QString, QLatin1Char, QStringLiteral
*/
If \a n is greater than size() or less than zero, a reference to the entire
string is returned.
- \snippet doc/src/snippets/qstring/main.cpp leftRef
+ \snippet qstring/main.cpp leftRef
\sa left(), rightRef(), midRef(), startsWith()
*/
If \a n is greater than size() or less than zero, a reference to the entire
string is returned.
- \snippet doc/src/snippets/qstring/main.cpp rightRef
+ \snippet qstring/main.cpp rightRef
\sa right(), leftRef(), midRef(), endsWith()
*/
Example:
- \snippet doc/src/snippets/qstring/main.cpp midRef
+ \snippet qstring/main.cpp midRef
\sa mid(), leftRef(), rightRef()
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qstring.cpp 7
+ \snippet code/src_corelib_tools_qstring.cpp 7
*/
QString QString::toHtmlEscaped() const
{
\c QChar, \c QCharRef, \c QLatin1Char, and \c char.
*/
-/*! \fn QByteArray QStringBuilder::toLatin1() const
+/* \fn QByteArray QStringBuilder::toLatin1() const
Returns a Latin-1 representation of the string as a QByteArray. The
returned byte array is undefined if the string contains non-Latin1
characters.
{QList::operator+=()}{operator+=()} and \l
{QStringList::operator<<()}{operator<<()} functions. For example:
- \snippet doc/src/snippets/qstringlist/main.cpp 0
+ \snippet qstringlist/main.cpp 0
\section1 Iterating over the strings
Indexing:
- \snippet doc/src/snippets/qstringlist/main.cpp 1
+ \snippet qstringlist/main.cpp 1
Java-style iterator:
- \snippet doc/src/snippets/qstringlist/main.cpp 2
+ \snippet qstringlist/main.cpp 2
STL-style iterator:
- \snippet doc/src/snippets/qstringlist/main.cpp 3
+ \snippet qstringlist/main.cpp 3
The QStringListIterator class is simply a type definition for
QListIterator<QString>. QStringList also provide the
string list into a single string (with an optional separator)
using the join() function. For example:
- \snippet doc/src/snippets/qstringlist/main.cpp 4
+ \snippet qstringlist/main.cpp 4
To break up a string into a string list, use the QString::split()
function:
- \snippet doc/src/snippets/qstringlist/main.cpp 6
+ \snippet qstringlist/main.cpp 6
The argument to split can be a single character, a string, or a
QRegExp.
contain a particular substring (or match a particular regular
expression):
- \snippet doc/src/snippets/qstringlist/main.cpp 7
+ \snippet qstringlist/main.cpp 7
The contains() function tells you whether the list contains a
given string, while the indexOf() function returns the index of
Finally, the replaceInStrings() function calls QString::replace()
on each string in the string list in turn. For example:
- \snippet doc/src/snippets/qstringlist/main.cpp 8
+ \snippet qstringlist/main.cpp 8
\sa QString
*/
Constructs a string list that contains the given string, \a
str. Longer lists are easily created like this:
- \snippet doc/src/snippets/qstringlist/main.cpp 9
+ \snippet qstringlist/main.cpp 9
\sa append()
*/
comparison is case sensitive; otherwise the comparison is case
insensitive.
- \snippet doc/src/snippets/qstringlist/main.cpp 5
- \snippet doc/src/snippets/qstringlist/main.cpp 10
+ \snippet qstringlist/main.cpp 5
+ \snippet qstringlist/main.cpp 10
This is equivalent to
- \snippet doc/src/snippets/qstringlist/main.cpp 11
- \snippet doc/src/snippets/qstringlist/main.cpp 12
+ \snippet qstringlist/main.cpp 11
+ \snippet qstringlist/main.cpp 12
\sa contains()
*/
For example:
- \snippet doc/src/snippets/qstringlist/main.cpp 5
- \snippet doc/src/snippets/qstringlist/main.cpp 13
+ \snippet qstringlist/main.cpp 5
+ \snippet qstringlist/main.cpp 13
\sa QString::replace()
*/
For example:
- \snippet doc/src/snippets/qstringlist/main.cpp 5
- \snippet doc/src/snippets/qstringlist/main.cpp 14
+ \snippet qstringlist/main.cpp 5
+ \snippet qstringlist/main.cpp 14
For regular expressions that contain \l{capturing parentheses},
occurrences of \b{\\1}, \b{\\2}, ..., in \a after are
For example:
- \snippet doc/src/snippets/qstringlist/main.cpp 5
- \snippet doc/src/snippets/qstringlist/main.cpp 15
+ \snippet qstringlist/main.cpp 5
+ \snippet qstringlist/main.cpp 15
*/
void QtPrivate::QStringList_replaceInStrings(QStringList *that, const QRegExp &rx, const QString &after)
{
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qtimeline.cpp 0
+ \snippet code/src_corelib_tools_qtimeline.cpp 0
You can also use QTimeLine with the
\l{Graphics View}{Graphics View framework} for
The C++ language doesn't support variable-length arrays on the stack.
For example, the following code won't compile:
- \snippet doc/src/snippets/code/doc_src_qvarlengtharray.cpp 0
+ \snippet code/doc_src_qvarlengtharray.cpp 0
The alternative is to allocate the array on the heap (with
\c{new}):
- \snippet doc/src/snippets/code/doc_src_qvarlengtharray.cpp 1
+ \snippet code/doc_src_qvarlengtharray.cpp 1
However, if myfunc() is called very frequently from the
application's inner loop, heap allocation can be a major source
it is much faster than heap allocation.
Example:
- \snippet doc/src/snippets/code/doc_src_qvarlengtharray.cpp 2
+ \snippet code/doc_src_qvarlengtharray.cpp 2
In the example above, QVarLengthArray will preallocate 1024
elements on the stack and use them unless \c{n + 1} is greater
be used to access and modify the items in the array.
Example:
- \snippet doc/src/snippets/code/doc_src_qvarlengtharray.cpp 3
+ \snippet code/doc_src_qvarlengtharray.cpp 3
The pointer remains valid as long as the array isn't reallocated.
Here's an example of a QVector that stores integers and a QVector
that stores QString values:
- \snippet doc/src/snippets/code/src_corelib_tools_qvector.cpp 0
+ \snippet code/src_corelib_tools_qvector.cpp 0
QVector stores a vector (or array) of items. Typically, vectors
are created with an initial size. For example, the following code
constructs a QVector with 200 elements:
- \snippet doc/src/snippets/code/src_corelib_tools_qvector.cpp 1
+ \snippet code/src_corelib_tools_qvector.cpp 1
The elements are automatically initialized with a
\l{default-constructed value}. If you want to initialize the
vector with a different value, pass that value as the second
argument to the constructor:
- \snippet doc/src/snippets/code/src_corelib_tools_qvector.cpp 2
+ \snippet code/src_corelib_tools_qvector.cpp 2
You can also call fill() at any time to fill the vector with a
value.
non-const vectors, operator[]() returns a reference to the item
that can be used on the left side of an assignment:
- \snippet doc/src/snippets/code/src_corelib_tools_qvector.cpp 3
+ \snippet code/src_corelib_tools_qvector.cpp 3
For read-only access, an alternative syntax is to use at():
- \snippet doc/src/snippets/code/src_corelib_tools_qvector.cpp 4
+ \snippet code/src_corelib_tools_qvector.cpp 4
at() can be faster than operator[](), because it never causes a
\l{deep copy} to occur.
backward. Both return the index of the matching item if they found
one; otherwise, they return -1. For example:
- \snippet doc/src/snippets/code/src_corelib_tools_qvector.cpp 5
+ \snippet code/src_corelib_tools_qvector.cpp 5
If you simply want to check whether a vector contains a
particular value, use contains(). If you want to find out how
can be used to access and modify the items in the vector.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qvector.cpp 6
+ \snippet code/src_corelib_tools_qvector.cpp 6
The pointer remains valid as long as the vector isn't
reallocated.
Inserts \a value at the end of the vector.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qvector.cpp 7
+ \snippet code/src_corelib_tools_qvector.cpp 7
This is the same as calling resize(size() + 1) and assigning \a
value to the new last element in the vector.
Inserts \a value at the beginning of the vector.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qvector.cpp 8
+ \snippet code/src_corelib_tools_qvector.cpp 8
This is the same as vector.insert(0, \a value).
value is appended to the vector.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qvector.cpp 9
+ \snippet code/src_corelib_tools_qvector.cpp 9
For large vectors, this operation can be slow (\l{linear time}),
because it requires moving all the items at indexes \a i and
vector.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qvector.cpp 10
+ \snippet code/src_corelib_tools_qvector.cpp 10
*/
/*! \fn QVector::iterator QVector::insert(iterator before, const T &value)
size beforehand.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qvector.cpp 11
+ \snippet code/src_corelib_tools_qvector.cpp 11
\sa resize()
*/
Returns -1 if no item matched.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qvector.cpp 12
+ \snippet code/src_corelib_tools_qvector.cpp 12
This function requires the value type to have an implementation of
\c operator==().
last item. Returns -1 if no item matched.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qvector.cpp 13
+ \snippet code/src_corelib_tools_qvector.cpp 13
This function requires the value type to have an implementation of
\c operator==().
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qvector.cpp 14
+ \snippet code/src_corelib_tools_qvector.cpp 14
\sa fromList(), QList::fromVector()
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qvector.cpp 15
+ \snippet code/src_corelib_tools_qvector.cpp 15
\sa toList(), QList::toVector()
*/
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qvector.cpp 16
+ \snippet code/src_corelib_tools_qvector.cpp 16
\sa toStdVector(), QList::fromStdList()
*/
Returns a std::vector object with the data contained in this QVector.
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qvector.cpp 17
+ \snippet code/src_corelib_tools_qvector.cpp 17
\sa fromStdVector(), QList::toStdList()
*/
A typical loop with QXmlStreamReader looks like this:
- \snippet doc/src/snippets/code/src_corelib_xml_qxmlstream.cpp 0
+ \snippet code/src_corelib_xml_qxmlstream.cpp 0
QXmlStreamReader is a well-formed XML 1.0 parser that does \e not
The following abridged code snippet shows the basic use of the class
to write formatted XML with indentation:
- \snippet doc/src/snippets/qxmlstreamwriter/main.cpp start stream
+ \snippet qxmlstreamwriter/main.cpp start stream
\dots
- \snippet doc/src/snippets/qxmlstreamwriter/main.cpp write element
+ \snippet qxmlstreamwriter/main.cpp write element
\dots
- \snippet doc/src/snippets/qxmlstreamwriter/main.cpp finish stream
+ \snippet qxmlstreamwriter/main.cpp finish stream
QXmlStreamWriter takes care of prefixing namespaces, all you have to
do is specify the \c namespaceUri when writing elements or
This is a convenience function equivalent to:
- \snippet doc/src/snippets/code/src_corelib_xml_qxmlstream.cpp 1
+ \snippet code/src_corelib_xml_qxmlstream.cpp 1
*/
void QXmlStreamWriter::writeTextElement(const QString &qualifiedName, const QString &text)
This is a convenience function equivalent to:
- \snippet doc/src/snippets/code/src_corelib_xml_qxmlstream.cpp 2
+ \snippet code/src_corelib_xml_qxmlstream.cpp 2
*/
void QXmlStreamWriter::writeTextElement(const QString &namespaceUri, const QString &name, const QString &text)
Determines whether \a encName is a valid instance of production [81]EncName in the XML 1.0
specification. If it is, true is returned, otherwise false.
- \sa \l {http://www.w3.org/TR/REC-xml/#NT-EncName}
+ \sa {http://www.w3.org/TR/REC-xml/#NT-EncName},
{Extensible Markup Language (XML) 1.0 (Fourth Edition), [81] EncName}
*/
bool QXmlUtils::isEncName(const QString &encName)
Determines whether \a c is a valid instance of production [84]Letter in the XML 1.0
specification. If it is, true is returned, otherwise false.
- \sa \l {http://www.w3.org/TR/REC-xml/#NT-Letter}
+ \sa {http://www.w3.org/TR/REC-xml/#NT-Letter},
{Extensible Markup Language (XML) 1.0 (Fourth Edition), [84] Letter}
*/
bool QXmlUtils::isLetter(const QChar c)
Determines whether \a c is a valid instance of production [2]Char in the XML 1.0
specification. If it is, true is returned, otherwise false.
- \sa \l {http://www.w3.org/TR/REC-xml/#NT-Char}
+ \sa {http://www.w3.org/TR/REC-xml/#NT-Char},
{Extensible Markup Language (XML) 1.0 (Fourth Edition), [2] Char}
*/
bool QXmlUtils::isChar(const QChar c)
production [4]NameChar in the XML 1.0 specification. If it
is, true is returned, otherwise false.
- \sa \l {http://www.w3.org/TR/REC-xml/#NT-NameChar}
+ \sa {http://www.w3.org/TR/REC-xml/#NT-NameChar},
{Extensible Markup Language (XML) 1.0 (Fourth Edition), [4] NameChar}
*/
bool QXmlUtils::isNameChar(const QChar c)
production [12] PubidLiteral in the XML 1.0 specification. If it
is, true is returned, otherwise false.
- \sa \l {http://www.w3.org/TR/REC-xml/#NT-PubidLiteral}
+ \sa {http://www.w3.org/TR/REC-xml/#NT-PubidLiteral},
{Extensible Markup Language (XML) 1.0 (Fourth Edition), [12] PubidLiteral}
*/
bool QXmlUtils::isPublicID(const QString &candidate)
production [4]NCName in the XML 1.0 Namespaces specification. If it
is, true is returned, otherwise false.
- \sa \l {http://www.w3.org/TR/REC-xml-names/#NT-NCName}
+ \sa {http://www.w3.org/TR/REC-xml-names/#NT-NCName},
{W3CNamespaces in XML 1.0 (Second Edition), [4] NCName}
*/
bool QXmlUtils::isNCName(const QStringRef &ncName)