summaryrefslogtreecommitdiffstats
path: root/doc/src/snippets
diff options
context:
space:
mode:
Diffstat (limited to 'doc/src/snippets')
-rw-r--r--doc/src/snippets/code/doc_src_lgpl.qdoc20
-rw-r--r--doc/src/snippets/code/doc_src_stylesheet.qdoc2
-rw-r--r--doc/src/snippets/code/src_corelib_concurrent_qtconcurrentrun.cpp2
-rw-r--r--doc/src/snippets/declarative/colors.qml125
-rw-r--r--doc/src/snippets/declarative/focus/focusColumn.qml2
-rw-r--r--doc/src/snippets/declarative/mousearea/mousearea.qml116
-rw-r--r--doc/src/snippets/declarative/pics/checker.svg17
-rw-r--r--doc/src/snippets/declarative/propertyaction-sequential.qml72
-rw-r--r--doc/src/snippets/declarative/propertyaction.qml62
-rw-r--r--doc/src/snippets/declarative/propertyanimation.qml24
-rw-r--r--doc/src/snippets/declarative/script.js5
-rw-r--r--doc/src/snippets/declarative/states/statechangescript.qml61
-rw-r--r--doc/src/snippets/declarative/transition-from-to-modified.qml60
-rw-r--r--doc/src/snippets/declarative/transition-from-to.qml2
-rw-r--r--doc/src/snippets/declarative/transition-reversible.qml2
-rw-r--r--doc/src/snippets/declarative/transitions-list.qml89
-rw-r--r--doc/src/snippets/declarative/webview/webview.qml51
-rw-r--r--doc/src/snippets/qabstractsliderisnippet.cpp2
-rw-r--r--doc/src/snippets/qstring/main.cpp382
19 files changed, 785 insertions, 311 deletions
diff --git a/doc/src/snippets/code/doc_src_lgpl.qdoc b/doc/src/snippets/code/doc_src_lgpl.qdoc
index 11fd0fff97..3ff5936862 100644
--- a/doc/src/snippets/code/doc_src_lgpl.qdoc
+++ b/doc/src/snippets/code/doc_src_lgpl.qdoc
@@ -96,7 +96,7 @@ modified by someone else and passed on, the recipients should know
that what they have is not the original version, so that the original
author's reputation will not be affected by problems that might be
introduced by others.
-
+
Finally, software patents pose a constant threat to the existence of
any free program. We wish to make sure that a company cannot
effectively restrict the users of a free program by obtaining a
@@ -152,7 +152,7 @@ modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, whereas the latter must
be combined with the library in order to run.
-
+
GNU LESSER GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
@@ -199,7 +199,7 @@ Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
-
+
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
@@ -257,7 +257,7 @@ instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
-
+
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
@@ -308,7 +308,7 @@ Library will still fall under Section 6.)
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
-
+
6. As an exception to the Sections above, you may also combine or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
@@ -370,7 +370,7 @@ restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
-
+
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
@@ -388,7 +388,7 @@ permitted, and provided that you do these two things:
where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute
-the Library except as expressly provided under this License. Any
+0the Library except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License. However, parties who have received copies,
@@ -411,7 +411,7 @@ subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties with
this License.
-
+
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
@@ -463,7 +463,7 @@ conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
-
+
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
@@ -497,7 +497,7 @@ SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
END OF TERMS AND CONDITIONS
-
+
How to Apply These Terms to Your New Libraries
If you develop a new library, and you want it to be of the greatest
diff --git a/doc/src/snippets/code/doc_src_stylesheet.qdoc b/doc/src/snippets/code/doc_src_stylesheet.qdoc
index 49e2581082..9b8a3b5e6f 100644
--- a/doc/src/snippets/code/doc_src_stylesheet.qdoc
+++ b/doc/src/snippets/code/doc_src_stylesheet.qdoc
@@ -213,7 +213,7 @@ namespace ns {
}
// ...
-qApp->setSytleSheet("ns--MyPushButton { background: yellow; }");
+qApp->setStyleSheet("ns--MyPushButton { background: yellow; }");
//! [27]
diff --git a/doc/src/snippets/code/src_corelib_concurrent_qtconcurrentrun.cpp b/doc/src/snippets/code/src_corelib_concurrent_qtconcurrentrun.cpp
index 2494eb24c0..11f5163f50 100644
--- a/doc/src/snippets/code/src_corelib_concurrent_qtconcurrentrun.cpp
+++ b/doc/src/snippets/code/src_corelib_concurrent_qtconcurrentrun.cpp
@@ -75,7 +75,7 @@ QString result = future.result();
//! [4]
// call 'QList<QByteArray> QByteArray::split(char sep) const' in a separate thread
-QByteArray bytearray = "hello world;
+QByteArray bytearray = "hello world";
QFuture<QList<QByteArray> > future = QtConcurrent::run(bytearray, &QByteArray::split), ',');
...
QList<QByteArray> result = future.result();
diff --git a/doc/src/snippets/declarative/colors.qml b/doc/src/snippets/declarative/colors.qml
new file mode 100644
index 0000000000..c670eca0ea
--- /dev/null
+++ b/doc/src/snippets/declarative/colors.qml
@@ -0,0 +1,125 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** 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$
+**
+****************************************************************************/
+
+import QtQuick 1.0
+
+Rectangle {
+ width: 160; height: 250
+
+ Image {
+ width: 160; height: 200
+ source: "pics/checker.svg"
+ fillMode: Image.Tile
+
+ //! [colors]
+ Rectangle {
+ color: "steelblue"
+ width: 40; height: 40
+ }
+ Rectangle {
+ color: "transparent"
+ y: 40; width: 40; height: 40
+ }
+ Rectangle {
+ color: "#FF0000"
+ y: 80; width: 40; height: 40
+ }
+ Rectangle {
+ color: "#800000FF"
+ y: 120; width: 40; height: 40
+ }
+ Rectangle {
+ color: "#00000000" // ARGB fully transparent
+ y: 160
+ width: 40; height: 40
+ }
+ //! [colors]
+
+ Rectangle {
+ x: 40
+ width: 120; height: 200
+
+ Text {
+ font.pixelSize: 16
+ text: "steelblue"
+ x: 10; height: 40
+ verticalAlignment: Text.AlignVCenter
+ }
+ Text {
+ font.pixelSize: 16
+ text: "transparent"
+ x: 10; y: 40; height: 40
+ verticalAlignment: Text.AlignVCenter
+ }
+ Text {
+ font.pixelSize: 16
+ text: "FF0000"
+ x: 10; y: 80; height: 40
+ verticalAlignment: Text.AlignVCenter
+ }
+ Text {
+ font.pixelSize: 16
+ text: "800000FF"
+ x: 10; y: 120; height: 40
+ verticalAlignment: Text.AlignVCenter
+ }
+ Text {
+ font.pixelSize: 16
+ text: "00000000"
+ x: 10; y: 160; height: 40
+ verticalAlignment: Text.AlignVCenter
+ }
+ }
+ }
+
+ Image {
+ y: 210
+ width: 40; height: 40
+ source: "pics/checker.svg"
+ fillMode: Image.Tile
+ }
+
+ Text {
+ font.pixelSize: 16
+ text: "(background)"
+ x: 50; y: 210; height: 40
+ verticalAlignment: Text.AlignVCenter
+ }
+}
diff --git a/doc/src/snippets/declarative/focus/focusColumn.qml b/doc/src/snippets/declarative/focus/focusColumn.qml
index e6a6fcf439..42ee3da68b 100644
--- a/doc/src/snippets/declarative/focus/focusColumn.qml
+++ b/doc/src/snippets/declarative/focus/focusColumn.qml
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/doc/src/snippets/declarative/mousearea/mousearea.qml b/doc/src/snippets/declarative/mousearea/mousearea.qml
index e3cbebb8ed..18ea971541 100644
--- a/doc/src/snippets/declarative/mousearea/mousearea.qml
+++ b/doc/src/snippets/declarative/mousearea/mousearea.qml
@@ -46,74 +46,72 @@ Rectangle {
width: childrenRect.width
height: childrenRect.height
-Row {
+ Row {
+ //! [intro]
+ Rectangle {
+ width: 100; height: 100
+ color: "green"
-//! [intro]
-Rectangle {
- width: 100; height: 100
- color: "green"
-
- MouseArea {
- anchors.fill: parent
- onClicked: { parent.color = 'red' }
- }
-}
-//! [intro]
+ MouseArea {
+ anchors.fill: parent
+ onClicked: { parent.color = 'red' }
+ }
+ }
+ //! [intro]
-//! [intro-extended]
-Rectangle {
- width: 100; height: 100
- color: "green"
+ //! [intro-extended]
+ Rectangle {
+ width: 100; height: 100
+ color: "green"
- MouseArea {
- anchors.fill: parent
- acceptedButtons: Qt.LeftButton | Qt.RightButton
- onClicked: {
- if (mouse.button == Qt.RightButton)
- parent.color = 'blue';
- else
- parent.color = 'red';
+ MouseArea {
+ anchors.fill: parent
+ acceptedButtons: Qt.LeftButton | Qt.RightButton
+ onClicked: {
+ if (mouse.button == Qt.RightButton)
+ parent.color = 'blue';
+ else
+ parent.color = 'red';
+ }
+ }
}
- }
-}
-//! [intro-extended]
+ //! [intro-extended]
-//! [drag]
-Rectangle {
- id: container
- width: 600; height: 200
+ //! [drag]
+ Rectangle {
+ id: container
+ width: 600; height: 200
- Rectangle {
- id: rect
- width: 50; height: 50
- color: "red"
- opacity: (600.0 - rect.x) / 600
+ Rectangle {
+ id: rect
+ width: 50; height: 50
+ color: "red"
+ opacity: (600.0 - rect.x) / 600
- MouseArea {
- anchors.fill: parent
- drag.target: rect
- drag.axis: Drag.XAxis
- drag.minimumX: 0
- drag.maximumX: container.width - rect.width
+ MouseArea {
+ anchors.fill: parent
+ drag.target: rect
+ drag.axis: Drag.XAxis
+ drag.minimumX: 0
+ drag.maximumX: container.width - rect.width
+ }
+ }
}
- }
-}
-//! [drag]
+ //! [drag]
-//! [mousebuttons]
-Text {
- text: mouseArea.pressedButtons & Qt.RightButton ? "right" : ""
- horizontalAlignment: Text.AlignHCenter
- verticalAlignment: Text.AlignVCenter
-
- MouseArea {
- id: mouseArea
- anchors.fill: parent
- acceptedButtons: Qt.LeftButton | Qt.RightButton
- }
-}
-//! [mousebuttons]
+ //! [mousebuttons]
+ Text {
+ text: mouseArea.pressedButtons & Qt.RightButton ? "right" : ""
+ horizontalAlignment: Text.AlignHCenter
+ verticalAlignment: Text.AlignVCenter
-}
+ MouseArea {
+ id: mouseArea
+ anchors.fill: parent
+ acceptedButtons: Qt.LeftButton | Qt.RightButton
+ }
+ }
+ //! [mousebuttons]
+ }
}
diff --git a/doc/src/snippets/declarative/pics/checker.svg b/doc/src/snippets/declarative/pics/checker.svg
new file mode 100644
index 0000000000..374d89dc0d
--- /dev/null
+++ b/doc/src/snippets/declarative/pics/checker.svg
@@ -0,0 +1,17 @@
+<?xml version="1.0" standalone="no"?>
+<svg width="10px" height="10px" viewBox="0 0 10px 10px"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:xlink="http://www.w3.org/1999/xlink/"
+ baseProfile="tiny" version="1.2">
+ <title>Checker</title>
+ <desc>A checkerboard pattern to use as a background.</desc>
+ <g fill="#e0e0e0" stroke="none" >
+ <rect x="0" y="0" width="10px" height="10px" />
+ </g>
+ <g fill="#404040" stroke="none" >
+ <rect x="0" y="0" width="5px" height="5px" />
+ </g>
+ <g fill="#404040" stroke="none" >
+ <rect x="5px" y="5px" width="5px" height="5px" />
+ </g>
+</svg>
diff --git a/doc/src/snippets/declarative/propertyaction-sequential.qml b/doc/src/snippets/declarative/propertyaction-sequential.qml
new file mode 100644
index 0000000000..a60b1f45a3
--- /dev/null
+++ b/doc/src/snippets/declarative/propertyaction-sequential.qml
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** 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$
+**
+****************************************************************************/
+import QtQuick 1.0
+
+Row {
+
+ Item {
+ width: 400; height: 400
+
+ Rectangle {
+ id: rect
+ width: 200; height: 100
+ color: "red"
+
+ states: State {
+ name: "rotated"
+ PropertyChanges { target: rect; rotation: 180; transformOrigin: Item.BottomRight }
+ }
+
+ //! [sequential]
+ transitions: Transition {
+ SequentialAnimation {
+ PropertyAction { target: rect; property: "transformOrigin" }
+ RotationAnimation { duration: 1000; direction: RotationAnimation.Counterclockwise }
+ }
+ }
+ //! [sequential]
+
+ MouseArea {
+ anchors.fill: parent
+ onClicked: rect.state = "rotated"
+ }
+ }
+ }
+}
diff --git a/doc/src/snippets/declarative/propertyaction.qml b/doc/src/snippets/declarative/propertyaction.qml
index dd21d14229..f5ae79814e 100644
--- a/doc/src/snippets/declarative/propertyaction.qml
+++ b/doc/src/snippets/declarative/propertyaction.qml
@@ -41,45 +41,43 @@ import QtQuick 1.0
Row {
-//![transition]
-Item {
- width: 400; height: 400
+ //![transition]
+ Item {
+ width: 400; height: 400
- Rectangle {
- id: rect
- width: 200; height: 100
- color: "red"
+ Rectangle {
+ id: rect
+ width: 200; height: 100
+ color: "red"
- states: State {
- name: "rotated"
- PropertyChanges { target: rect; rotation: 180; transformOrigin: Item.BottomRight }
- }
+ states: State {
+ name: "rotated"
+ PropertyChanges { target: rect; rotation: 180; transformOrigin: Item.BottomRight }
+ }
- transitions: Transition {
- RotationAnimation { duration: 1000; direction: RotationAnimation.Counterclockwise }
- }
+ transitions: Transition {
+ RotationAnimation { duration: 1000; direction: RotationAnimation.Counterclockwise }
+ }
- MouseArea {
- anchors.fill: parent
- onClicked: rect.state = "rotated"
+ MouseArea {
+ anchors.fill: parent
+ onClicked: rect.state = "rotated"
+ }
}
}
-}
-//![transition]
+ //![transition]
-Item {
- width: 300; height: 300
+ Item {
+ width: 300; height: 300
- Image { id: img; source: "pics/qt.png" }
-
-//![standalone]
-SequentialAnimation {
- PropertyAction { target: img; property: "smooth"; value: "true" }
- NumberAnimation { target: img; property: "width"; to: 300; duration: 1000 }
- PropertyAction { target: img; property: "smooth"; value: "false" }
-}
-//![standalone]
-}
+ Image { id: img; source: "pics/qt.png" }
+ //![standalone]
+ SequentialAnimation {
+ PropertyAction { target: img; property: "smooth"; value: "true" }
+ NumberAnimation { target: img; property: "width"; to: 300; duration: 1000 }
+ PropertyAction { target: img; property: "smooth"; value: "false" }
+ }
+ //![standalone]
+ }
}
-
diff --git a/doc/src/snippets/declarative/propertyanimation.qml b/doc/src/snippets/declarative/propertyanimation.qml
index d0a009a43f..711feec084 100644
--- a/doc/src/snippets/declarative/propertyanimation.qml
+++ b/doc/src/snippets/declarative/propertyanimation.qml
@@ -48,10 +48,12 @@ Rectangle {
width: 100; height: 100
color: "red"
+ //! [single state]
states: State {
name: "moved"
PropertyChanges { target: rect; x: 50 }
}
+ //! [single state]
transitions: Transition {
PropertyAnimation { properties: "x,y"; easing.type: Easing.InOutQuad }
@@ -83,18 +85,16 @@ Rectangle {
}
//![propertyvaluesource]
-//![standalone]
-Rectangle {
- id: theRect
- width: 100; height: 100
- color: "red"
-
- // this is a standalone animation, it's not running by default
- PropertyAnimation { id: animation; target: theRect; property: "width"; to: 30; duration: 500 }
-
- MouseArea { anchors.fill: parent; onClicked: animation.running = true }
-}
-//![standalone]
+ //![standalone]
+ Rectangle {
+ id: theRect
+ width: 100; height: 100
+ color: "red"
+ // this is a standalone animation, it's not running by default
+ PropertyAnimation { id: animation; target: theRect; property: "width"; to: 30; duration: 500 }
+ MouseArea { anchors.fill: parent; onClicked: animation.running = true }
+ }
+ //![standalone]
}
diff --git a/doc/src/snippets/declarative/script.js b/doc/src/snippets/declarative/script.js
index cd67311e30..f55dee3507 100644
--- a/doc/src/snippets/declarative/script.js
+++ b/doc/src/snippets/declarative/script.js
@@ -1 +1,4 @@
-# Just here so that workerscript.qml succeeds.
+WorkerScript.onMessage = function(message) {
+ // ... long-running operations and calculations are done here
+ WorkerScript.sendMessage({ 'reply': 'Mouse is at ' + message.x + ',' + message.y })
+}
diff --git a/doc/src/snippets/declarative/states/statechangescript.qml b/doc/src/snippets/declarative/states/statechangescript.qml
new file mode 100644
index 0000000000..b885137450
--- /dev/null
+++ b/doc/src/snippets/declarative/states/statechangescript.qml
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** 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$
+**
+****************************************************************************/
+
+Item {
+//! [state and transition]
+State {
+ name: "state1"
+ StateChangeScript {
+ name: "myScript"
+ script: doStateStuff();
+ }
+ // ...
+}
+// ...
+Transition {
+ to: "state1"
+ SequentialAnimation {
+ NumberAnimation { /* ... */ }
+ ScriptAction { scriptName: "myScript" }
+ NumberAnimation { /* ... */ }
+ }
+}
+//! [state and transition]
+}
diff --git a/doc/src/snippets/declarative/transition-from-to-modified.qml b/doc/src/snippets/declarative/transition-from-to-modified.qml
new file mode 100644
index 0000000000..1e2ebca2cc
--- /dev/null
+++ b/doc/src/snippets/declarative/transition-from-to-modified.qml
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** 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$
+**
+****************************************************************************/
+import QtQuick 1.0
+
+Rectangle {
+ id: rect
+ width: 100; height: 100
+ color: "red"
+
+ MouseArea { id: mouseArea; anchors.fill: parent }
+
+ states: State {
+ name: "brighter"; when: mouseArea.pressed
+ PropertyChanges { target: rect; color: "yellow" }
+ }
+
+ //! [modified transition]
+ transitions: Transition {
+ to: "brighter"
+ ColorAnimation { duration: 1000 }
+ }
+ //! [modified transition]
+}
diff --git a/doc/src/snippets/declarative/transition-from-to.qml b/doc/src/snippets/declarative/transition-from-to.qml
index 5fde653514..ba07518dd4 100644
--- a/doc/src/snippets/declarative/transition-from-to.qml
+++ b/doc/src/snippets/declarative/transition-from-to.qml
@@ -57,5 +57,3 @@ Rectangle {
}
}
//![0]
-
-
diff --git a/doc/src/snippets/declarative/transition-reversible.qml b/doc/src/snippets/declarative/transition-reversible.qml
index c67fd80e1c..6a6ef2382b 100644
--- a/doc/src/snippets/declarative/transition-reversible.qml
+++ b/doc/src/snippets/declarative/transition-reversible.qml
@@ -53,12 +53,14 @@ Rectangle {
PropertyChanges { target: rect; color: "yellow"; x: 50 }
}
+ //! [sequential animations]
transitions: Transition {
SequentialAnimation {
PropertyAnimation { property: "x"; duration: 1000 }
ColorAnimation { duration: 1000 }
}
}
+ //! [sequential animations]
}
//![0]
diff --git a/doc/src/snippets/declarative/transitions-list.qml b/doc/src/snippets/declarative/transitions-list.qml
new file mode 100644
index 0000000000..cd413cc9dd
--- /dev/null
+++ b/doc/src/snippets/declarative/transitions-list.qml
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** 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$
+**
+****************************************************************************/
+
+import QtQuick 1.0
+
+Rectangle {
+ width: 150; height: 250
+
+ Rectangle {
+ id: stopLight
+ x: 25; y: 15; width: 100; height: 100
+ }
+ Rectangle {
+ id: goLight
+ x: 25; y: 135; width: 100; height: 100
+ }
+
+ states: [
+ State {
+ name: "stop"
+ PropertyChanges { target: stopLight; color: "red" }
+ PropertyChanges { target: goLight; color: "black" }
+ },
+ State {
+ name: "go"
+ PropertyChanges { target: stopLight; color: "black" }
+ PropertyChanges { target: goLight; color: "green" }
+ }
+ ]
+
+ state: "stop"
+
+ MouseArea {
+ anchors.fill: parent
+ onClicked: parent.state == "stop" ?
+ parent.state = "go" : parent.state = "stop"
+ }
+
+ //! [list of transitions]
+ transitions: [
+ Transition {
+ from: "stop"; to: "go"
+ PropertyAnimation { target: stopLight
+ properties: "color"; duration: 1000 }
+ },
+ Transition {
+ from: "go"; to: "stop"
+ PropertyAnimation { target: goLight
+ properties: "color"; duration: 1000 }
+ } ]
+ //! [list of transitions]
+}
diff --git a/doc/src/snippets/declarative/webview/webview.qml b/doc/src/snippets/declarative/webview/webview.qml
new file mode 100644
index 0000000000..c1cef33a6f
--- /dev/null
+++ b/doc/src/snippets/declarative/webview/webview.qml
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** 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$
+**
+****************************************************************************/
+
+//! [document]
+import QtWebKit 1.0
+
+WebView {
+ url: "http://www.nokia.com"
+ preferredWidth: 490
+ preferredHeight: 400
+ scale: 0.5
+ smooth: false
+}
+//! [document]
diff --git a/doc/src/snippets/qabstractsliderisnippet.cpp b/doc/src/snippets/qabstractsliderisnippet.cpp
index 6b684e9af7..cb0f8cc130 100644
--- a/doc/src/snippets/qabstractsliderisnippet.cpp
+++ b/doc/src/snippets/qabstractsliderisnippet.cpp
@@ -50,7 +50,7 @@ QAbstractSliderPrivate::~QAbstractSliderPrivate()
{
}
-oid QAbstractSlider::setRange(int min, int max)
+void QAbstractSlider::setRange(int min, int max)
{
Q_D(QAbstractSlider);
int oldMin = d->minimum;
diff --git a/doc/src/snippets/qstring/main.cpp b/doc/src/snippets/qstring/main.cpp
index 9aac79ddce..bbc9e98901 100644
--- a/doc/src/snippets/qstring/main.cpp
+++ b/doc/src/snippets/qstring/main.cpp
@@ -126,22 +126,22 @@ Widget::Widget(QWidget *parent)
void Widget::constCharPointer()
{
-//! [0]
+ //! [0]
QString str = "Hello";
-//! [0]
+ //! [0]
}
void Widget::constCharArray()
{
-//! [1]
+ //! [1]
static const QChar data[4] = { 0x0055, 0x006e, 0x10e3, 0x03a3 };
QString str(data, 4);
-//! [1]
+ //! [1]
}
void Widget::characterReference()
{
-//! [2]
+ //! [2]
QString str;
str.resize(4);
@@ -149,46 +149,46 @@ void Widget::characterReference()
str[1] = QChar('n');
str[2] = QChar(0x10e3);
str[3] = QChar(0x03a3);
-//! [2]
+ //! [2]
}
void Widget::atFunction()
{
-//! [3]
+ //! [3]
QString str;
for (int i = 0; i < str.size(); ++i) {
if (str.at(i) >= QChar('a') && str.at(i) <= QChar('f'))
qDebug() << "Found character in range [a-f]";
}
-//! [3]
+ //! [3]
}
void Widget::stringLiteral()
{
-//! [4]
+ //! [4]
QString str;
if (str == "auto" || str == "extern"
|| str == "static" || str == "register") {
// ...
}
-//! [4]
+ //! [4]
}
void Widget::modify()
{
-//! [5]
+ //! [5]
QString str = "and";
str.prepend("rock "); // str == "rock and"
str.append(" roll"); // str == "rock and roll"
str.replace(5, 3, "&"); // str == "rock & roll"
-//! [5]
+ //! [5]
}
void Widget::index()
{
-//! [6]
+ //! [6]
QString str = "We must be <b>bold</b>, very <b>bold</b>";
int j = 0;
@@ -196,25 +196,25 @@ void Widget::index()
qDebug() << "Found <b> tag at index position" << j;
++j;
}
-//! [6]
+ //! [6]
}
//! [7]
- QString Widget::boolToString(bool b)
- {
- QString result;
- if (b)
- result = "True";
- else
- result = "False";
- return result;
- }
+QString Widget::boolToString(bool b)
+{
+ QString result;
+ if (b)
+ result = "True";
+ else
+ result = "False";
+ return result;
+}
//! [7]
void Widget::nullVsEmpty()
{
-//! [8]
+ //! [8]
QString().isNull(); // returns true
QString().isEmpty(); // returns true
@@ -223,45 +223,45 @@ void Widget::nullVsEmpty()
QString("abc").isNull(); // returns false
QString("abc").isEmpty(); // returns false
-//! [8]
+ //! [8]
}
void Widget::appendFunction()
{
-//! [9]
+ //! [9]
QString x = "free";
QString y = "dom";
x.append(y);
// x == "freedom"
-//! [9]
+ //! [9]
-//! [10]
+ //! [10]
x.insert(x.size(), y);
-//! [10]
+ //! [10]
}
void Widget::argFunction()
{
-//! [11]
+ //! [11]
QString i; // current file's number
QString total; // number of files to process
QString fileName; // current file's name
QString status = QString("Processing file %1 of %2: %3")
.arg(i).arg(total).arg(fileName);
-//! [11]
+ //! [11]
-//! [12] //! [13]
+ //! [12] //! [13]
QString str;
-//! [12]
+ //! [12]
str = "%1 %2";
str.arg("%1f", "Hello"); // returns "%1f Hello"
str.arg("%1f").arg("Hello"); // returns "Hellof %2"
-//! [13]
+ //! [13]
-//! [14]
+ //! [14]
str = QString("Decimal 63 is %1 in hexadecimal")
.arg(63, 0, 16);
// str == "Decimal 63 is 3f in hexadecimal"
@@ -272,16 +272,16 @@ void Widget::argFunction()
.arg(12345)
.arg(12345, 0, 16);
// str == "12345 12,345 3039"
-//! [14]
+ //! [14]
}
void Widget::chopFunction()
{
-//! [15]
+ //! [15]
QString str("LOGOUT\r\n");
str.chop(2);
// str == "LOGOUT"
-//! [15]
+ //! [15]
}
void Widget::compareFunction()
@@ -293,251 +293,251 @@ void Widget::compareFunction()
void Widget::compareSensitiveFunction()
{
-//! [16]
+ //! [16]
int x = QString::compare("aUtO", "AuTo", Qt::CaseInsensitive); // x == 0
int y = QString::compare("auto", "Car", Qt::CaseSensitive); // y > 0
int z = QString::compare("auto", "Car", Qt::CaseInsensitive); // z < 0
-//! [16]
+ //! [16]
}
void Widget::containsFunction()
{
-//! [17]
+ //! [17]
QString str = "Peter Pan";
str.contains("peter", Qt::CaseInsensitive); // returns true
-//! [17]
+ //! [17]
}
void Widget::countFunction()
{
-//! [18]
+ //! [18]
QString str = "banana and panama";
str.count(QRegExp("a[nm]a")); // returns 4
-//! [18]
+ //! [18]
}
void Widget::dataFunction()
{
-//! [19]
+ //! [19]
QString str = "Hello world";
QChar *data = str.data();
while (!data->isNull()) {
qDebug() << data->unicode();
++data;
}
-//! [19]
+ //! [19]
}
void Widget::endsWithFunction()
{
-//! [20]
+ //! [20]
QString str = "Bananas";
str.endsWith("anas"); // returns true
str.endsWith("pple"); // returns false
-//! [20]
+ //! [20]
}
void Widget::fillFunction()
{
-//! [21]
+ //! [21]
QString str = "Berlin";
str.fill('z');
// str == "zzzzzz"
str.fill('A', 2);
// str == "AA"
-//! [21]
+ //! [21]
}
void Widget::fromRawDataFunction()
{
-//! [22]
- QRegExp pattern;
- static const QChar unicode[] = {
- 0x005A, 0x007F, 0x00A4, 0x0060,
- 0x1009, 0x0020, 0x0020};
- int size = sizeof(unicode) / sizeof(QChar);
+ //! [22]
+ QRegExp pattern;
+ static const QChar unicode[] = {
+ 0x005A, 0x007F, 0x00A4, 0x0060,
+ 0x1009, 0x0020, 0x0020};
+ int size = sizeof(unicode) / sizeof(QChar);
- QString str = QString::fromRawData(unicode, size);
- if (str.contains(QRegExp(pattern))) {
- // ...
-//! [22] //! [23]
- }
-//! [23]
+ QString str = QString::fromRawData(unicode, size);
+ if (str.contains(QRegExp(pattern))) {
+ // ...
+ //! [22] //! [23]
+ }
+ //! [23]
}
void Widget::indexOfFunction()
{
-//! [24]
+ //! [24]
QString x = "sticky question";
QString y = "sti";
x.indexOf(y); // returns 0
x.indexOf(y, 1); // returns 10
x.indexOf(y, 10); // returns 10
x.indexOf(y, 11); // returns -1
-//! [24]
+ //! [24]
}
void Widget::firstIndexOfFunction()
{
-//! [25]
+ //! [25]
QString str = "the minimum";
str.indexOf(QRegExp("m[aeiou]"), 0); // returns 4
-//! [25]
+ //! [25]
}
void Widget::insertFunction()
{
-//! [26]
+ //! [26]
QString str = "Meal";
str.insert(1, QString("ontr"));
// str == "Montreal"
-//! [26]
+ //! [26]
}
void Widget::isEmptyFunction()
{
-//! [27]
+ //! [27]
QString().isEmpty(); // returns true
QString("").isEmpty(); // returns true
QString("x").isEmpty(); // returns false
QString("abc").isEmpty(); // returns false
-//! [27]
+ //! [27]
}
void Widget::isNullFunction()
{
-//! [28]
+ //! [28]
QString().isNull(); // returns true
QString("").isNull(); // returns false
QString("abc").isNull(); // returns false
-//! [28]
+ //! [28]
}
void Widget::lastIndexOfFunction()
{
-//! [29]
+ //! [29]
QString x = "crazy azimuths";
QString y = "az";
x.lastIndexOf(y); // returns 6
x.lastIndexOf(y, 6); // returns 6
x.lastIndexOf(y, 5); // returns 2
x.lastIndexOf(y, 1); // returns -1
-//! [29]
+ //! [29]
-//! [30]
+ //! [30]
QString str = "the minimum";
str.lastIndexOf(QRegExp("m[aeiou]")); // returns 8
-//! [30]
+ //! [30]
}
void Widget::leftFunction()
{
-//! [31]
+ //! [31]
QString x = "Pineapple";
QString y = x.left(4); // y == "Pine"
-//! [31]
+ //! [31]
}
void Widget::leftJustifiedFunction()
{
-//! [32]
+ //! [32]
QString s = "apple";
QString t = s.leftJustified(8, '.'); // t == "apple..."
-//! [32]
+ //! [32]
-//! [33]
+ //! [33]
QString str = "Pineapple";
str = str.leftJustified(5, '.', true); // str == "Pinea"
-//! [33]
+ //! [33]
}
void Widget::midFunction()
{
-//! [34]
+ //! [34]
QString x = "Nine pineapples";
QString y = x.mid(5, 4); // y == "pine"
QString z = x.mid(5); // z == "pineapples"
-//! [34]
+ //! [34]
}
void Widget::numberFunction()
{
-//! [35]
+ //! [35]
long a = 63;
QString s = QString::number(a, 16); // s == "3f"
QString t = QString::number(a, 16).toUpper(); // t == "3F"
-//! [35]
+ //! [35]
}
void Widget::prependFunction()
{
-//! [36]
+ //! [36]
QString x = "ship";
QString y = "air";
x.prepend(y);
// x == "airship"
-//! [36]
+ //! [36]
}
void Widget::removeFunction()
{
-//! [37]
+ //! [37]
QString s = "Montreal";
s.remove(1, 4);
// s == "Meal"
-//! [37]
+ //! [37]
-//! [38]
+ //! [38]
QString t = "Ali Baba";
t.remove(QChar('a'), Qt::CaseInsensitive);
// t == "li Bb"
-//! [38]
+ //! [38]
-//! [39]
+ //! [39]
QString r = "Telephone";
r.remove(QRegExp("[aeiou]."));
// r == "The"
-//! [39]
+ //! [39]
}
void Widget::replaceFunction()
{
-//! [40]
+ //! [40]
QString x = "Say yes!";
QString y = "no";
x.replace(4, 3, y);
// x == "Say no!"
-//! [40]
+ //! [40]
-//! [41]
+ //! [41]
QString str = "colour behaviour flavour neighbour";
str.replace(QString("ou"), QString("o"));
// str == "color behavior flavor neighbor"
-//! [41]
+ //! [41]
-//! [42]
+ //! [42]
QString s = "Banana";
s.replace(QRegExp("a[mn]"), "ox");
// s == "Boxoxa"
-//! [42]
+ //! [42]
-//! [43]
+ //! [43]
QString t = "A <i>bon mot</i>.";
t.replace(QRegExp("<i>([^<]*)</i>"), "\\emph{\\1}");
// t == "A \\emph{bon mot}."
-//! [43]
+ //! [43]
-//! [86]
+ //! [86]
QString equis = "xxxxxx";
equis.replace("xx", "x");
// equis == "xxx"
-//! [86]
+ //! [86]
}
void Widget::reserveFunction()
{
-//! [44]
+ //! [44]
QString result;
int maxSize;
bool condition;
@@ -549,59 +549,59 @@ void Widget::reserveFunction()
result.append(nextChar);
result.squeeze();
-//! [44]
+ //! [44]
}
void Widget::resizeFunction()
{
-//! [45]
+ //! [45]
QString s = "Hello world";
s.resize(5);
// s == "Hello"
s.resize(8);
// s == "Hello???" (where ? stands for any character)
-//! [45]
+ //! [45]
-//! [46]
+ //! [46]
QString t = "Hello";
t += QString(10, 'X');
// t == "HelloXXXXXXXXXX"
-//! [46]
+ //! [46]
-//! [47]
+ //! [47]
QString r = "Hello";
r = r.leftJustified(10, ' ');
// r == "Hello "
-//! [47]
+ //! [47]
}
void Widget::rightFunction()
{
-//! [48]
+ //! [48]
QString x = "Pineapple";
QString y = x.right(5); // y == "apple"
-//! [48]
+ //! [48]
}
void Widget::rightJustifiedFunction()
{
-//! [49]
+ //! [49]
QString s = "apple";
QString t = s.rightJustified(8, '.'); // t == "...apple"
-//! [49]
+ //! [49]
-//! [50]
+ //! [50]
QString str = "Pineapple";
str = str.rightJustified(5, '.', true); // str == "Pinea"
-//! [50]
+ //! [50]
}
void Widget::sectionFunction()
{
-//! [51] //! [52]
+ //! [51] //! [52]
QString str;
-//! [51]
+ //! [51]
QString csv = "forename,middlename,surname,phone";
QString path = "/usr/local/bin/myapp"; // First field is empty
QString::SectionFlag flag = QString::SectionSkipEmpty;
@@ -610,83 +610,83 @@ void Widget::sectionFunction()
str = csv.section(',', 2, 2); // str == "surname"
str = path.section('/', 3, 4); // str == "bin/myapp"
str = path.section('/', 3, 3, flag); // str == "myapp"
-//! [52]
+ //! [52]
-//! [53]
+ //! [53]
str = csv.section(',', -3, -2); // str == "middlename,surname"
str = path.section('/', -1); // str == "myapp"
-//! [53]
+ //! [53]
-//! [54]
+ //! [54]
QString data = "forename**middlename**surname**phone";
str = data.section("**", 2, 2); // str == "surname"
str = data.section("**", -3, -2); // str == "middlename**surname"
-//! [54]
+ //! [54]
-//! [55]
+ //! [55]
QString line = "forename\tmiddlename surname \t \t phone";
QRegExp sep("\\s+");
str = line.section(sep, 2, 2); // s == "surname"
str = line.section(sep, -3, -2); // s == "middlename surname"
-//! [55]
+ //! [55]
}
void Widget::setNumFunction()
{
-//! [56]
+ //! [56]
QString str;
str.setNum(1234); // str == "1234"
-//! [56]
+ //! [56]
}
void Widget::simplifiedFunction()
{
-//! [57]
+ //! [57]
QString str = " lots\t of\nwhitespace\r\n ";
str = str.simplified();
// str == "lots of whitespace";
-//! [57]
+ //! [57]
}
void Widget::sizeFunction()
{
-//! [58]
+ //! [58]
QString str = "World";
int n = str.size(); // n == 5
str.data()[0]; // returns 'W'
str.data()[4]; // returns 'd'
str.data()[5]; // returns '\0'
-//! [58]
+ //! [58]
}
void Widget::splitFunction()
{
-//! [59]
+ //! [59]
QString str;
QStringList list;
str = "Some text\n\twith strange whitespace.";
list = str.split(QRegExp("\\s+"));
// list: [ "Some", "text", "with", "strange", "whitespace." ]
-//! [59]
+ //! [59]
-//! [60]
+ //! [60]
str = "This time, a normal English sentence.";
list = str.split(QRegExp("\\W+"), QString::SkipEmptyParts);
// list: [ "This", "time", "a", "normal", "English", "sentence" ]
-//! [60]
+ //! [60]
-//! [61]
+ //! [61]
str = "Now: this sentence fragment.";
list = str.split(QRegExp("\\b"));
// list: [ "", "Now", ": ", "this", " ", "sentence", " ", "fragment", "." ]
-//! [61]
+ //! [61]
}
void Widget::splitCaseSensitiveFunction()
{
-//! [62]
+ //! [62]
QString str = "a,,b,c";
QStringList list1 = str.split(",");
@@ -694,241 +694,241 @@ void Widget::splitCaseSensitiveFunction()
QStringList list2 = str.split(",", QString::SkipEmptyParts);
// list2: [ "a", "b", "c" ]
-//! [62]
+ //! [62]
}
void Widget::sprintfFunction()
{
-//! [63]
+ //! [63]
size_t BufSize;
char buf[BufSize];
::snprintf(buf, BufSize, "%lld", 123456789LL);
QString str = QString::fromAscii(buf);
-//! [63]
+ //! [63]
-//! [64]
+ //! [64]
QString result;
QTextStream(&result) << "pi = " << 3.14;
// result == "pi = 3.14"
-//! [64]
+ //! [64]
}
void Widget::startsWithFunction()
{
-//! [65]
+ //! [65]
QString str = "Bananas";
str.startsWith("Ban"); // returns true
str.startsWith("Car"); // returns false
-//! [65]
+ //! [65]
}
void Widget::toDoubleFunction()
{
-//! [66]
+ //! [66]
QString str = "1234.56";
double val = str.toDouble(); // val == 1234.56
-//! [66]
+ //! [66]
-//! [67]
+ //! [67]
bool ok;
double d;
d = QString( "1234.56e-02" ).toDouble(&ok); // ok == true, d == 12.3456
-//! [67]
+ //! [67]
-//! [68] //! [69]
+ //! [68] //! [69]
QLocale::setDefault(QLocale::C);
d = QString( "1234,56" ).toDouble(&ok); // ok == false
-//! [68]
+ //! [68]
d = QString( "1234.56" ).toDouble(&ok); // ok == true, d == 1234.56
-//! [69] //! [70]
+ //! [69] //! [70]
QLocale::setDefault(QLocale::German);
d = QString( "1234,56" ).toDouble(&ok); // ok == true, d == 1234.56
d = QString( "1234.56" ).toDouble(&ok); // ok == true, d == 1234.56
-//! [70]
+ //! [70]
QLocale::setDefault(QLocale::C);
d = QString( "1,234,567.89" ).toDouble(&ok); // ok == false
}
void Widget::toFloatFunction()
{
-//! [71]
+ //! [71]
QString str1 = "1234.56";
str1.toFloat(); // returns 1234.56
bool ok;
QString str2 = "R2D2";
str2.toFloat(&ok); // returns 0.0, sets ok to false
-//! [71]
+ //! [71]
}
void Widget::toIntFunction()
{
-//! [72]
+ //! [72]
QString str = "FF";
bool ok;
int hex = str.toInt(&ok, 16); // hex == 255, ok == true
int dec = str.toInt(&ok, 10); // dec == 0, ok == false
-//! [72]
+ //! [72]
}
void Widget::toLongFunction()
{
-//! [73]
+ //! [73]
QString str = "FF";
bool ok;
long hex = str.toLong(&ok, 16); // hex == 255, ok == true
long dec = str.toLong(&ok, 10); // dec == 0, ok == false
-//! [73]
+ //! [73]
}
void Widget::toLongLongFunction()
{
-//! [74]
+ //! [74]
QString str = "FF";
bool ok;
qint64 hex = str.toLongLong(&ok, 16); // hex == 255, ok == true
qint64 dec = str.toLongLong(&ok, 10); // dec == 0, ok == false
-//! [74]
+ //! [74]
}
void Widget::toLowerFunction()
{
-//! [75]
+ //! [75]
QString str = "Qt by NOKIA";
str = str.toLower(); // str == "qt by nokia"
-//! [75]
+ //! [75]
}
void Widget::toShortFunction()
{
-//! [76]
+ //! [76]
QString str = "FF";
bool ok;
short hex = str.toShort(&ok, 16); // hex == 255, ok == true
short dec = str.toShort(&ok, 10); // dec == 0, ok == false
-//! [76]
+ //! [76]
}
void Widget::toUIntFunction()
{
-//! [77]
+ //! [77]
QString str = "FF";
bool ok;
uint hex = str.toUInt(&ok, 16); // hex == 255, ok == true
uint dec = str.toUInt(&ok, 10); // dec == 0, ok == false
-//! [77]
+ //! [77]
}
void Widget::toULongFunction()
{
-//! [78]
+ //! [78]
QString str = "FF";
bool ok;
ulong hex = str.toULong(&ok, 16); // hex == 255, ok == true
ulong dec = str.toULong(&ok, 10); // dec == 0, ok == false
-//! [78]
+ //! [78]
}
void Widget::toULongLongFunction()
{
-//! [79]
+ //! [79]
QString str = "FF";
bool ok;
quint64 hex = str.toULongLong(&ok, 16); // hex == 255, ok == true
quint64 dec = str.toULongLong(&ok, 10); // dec == 0, ok == false
-//! [79]
+ //! [79]
}
void Widget::toUShortFunction()
{
-//! [80]
+ //! [80]
QString str = "FF";
bool ok;
ushort hex = str.toUShort(&ok, 16); // hex == 255, ok == true
ushort dec = str.toUShort(&ok, 10); // dec == 0, ok == false
-//! [80]
+ //! [80]
}
void Widget::toUpperFunction()
{
-//! [81]
+ //! [81]
QString str = "TeXt";
str = str.toUpper(); // str == "TEXT"
-//! [81]
+ //! [81]
}
void Widget::trimmedFunction()
{
-//! [82]
+ //! [82]
QString str = " lots\t of\nwhitespace\r\n ";
str = str.trimmed();
// str == "lots\t of\nwhitespace"
-//! [82]
+ //! [82]
}
void Widget::truncateFunction()
{
-//! [83]
+ //! [83]
QString str = "Vladivostok";
str.truncate(4);
// str == "Vlad"
-//! [83]
+ //! [83]
}
void Widget::plusEqualOperator()
{
-//! [84]
+ //! [84]
QString x = "free";
QString y = "dom";
x += y;
// x == "freedom"
-//! [84]
+ //! [84]
}
void Widget::arrayOperator()
{
-//! [85]
+ //! [85]
QString str;
if (str[0] == QChar('?'))
str[0] = QChar('_');
-//! [85]
+ //! [85]
}
void Widget::midRefFunction()
{
-//! [midRef]
+ //! [midRef]
QString x = "Nine pineapples";
QStringRef y = x.midRef(5, 4); // y == "pine"
QStringRef z = x.midRef(5); // z == "pineapples"
-//! [midRef]
+ //! [midRef]
}
void Widget::leftRefFunction()
{
-//! [leftRef]
+ //! [leftRef]
QString x = "Pineapple";
QStringRef y = x.leftRef(4); // y == "Pine"
-//! [leftRef]
+ //! [leftRef]
}
void Widget::rightRefFunction()
{
-//! [rightRef]
+ //! [rightRef]
QString x = "Pineapple";
QStringRef y = x.rightRef(5); // y == "apple"
-//! [rightRef]
+ //! [rightRef]
}