summaryrefslogtreecommitdiffstats
path: root/doc/codesnippets/doc
diff options
context:
space:
mode:
Diffstat (limited to 'doc/codesnippets/doc')
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_corelib_io_qabstractfileengine.cpp2
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_corelib_io_qdir.cpp4
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_corelib_io_qprocess.cpp10
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp20
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_corelib_statemachine_qstatemachine.cpp55
-rw-r--r--doc/codesnippets/doc/src/snippets/qelapsedtimer/main.cpp109
-rw-r--r--doc/codesnippets/doc/src/snippets/qelapsedtimer/qelapsedtimer.pro2
-rw-r--r--doc/codesnippets/doc/src/snippets/qprocess-environment/main.cpp70
-rw-r--r--doc/codesnippets/doc/src/snippets/qprocess/qprocess-simpleexecution.cpp2
9 files changed, 236 insertions, 38 deletions
diff --git a/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qabstractfileengine.cpp b/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qabstractfileengine.cpp
index de0fd50..98c9303 100644
--- a/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qabstractfileengine.cpp
+++ b/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qabstractfileengine.cpp
@@ -31,7 +31,7 @@ def create(fileName):
//! [2]
# @arg filters QDir.Filters
-# @arg filterNames QStringList
+# @arg filterNames [str, ...]
# @return QAbstractFileEngineIterator
def beginEntryList(filters, filterNames):
return CustomFileEngineIterator(filters, filterNames)
diff --git a/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qdir.cpp b/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qdir.cpp
index a849e48..1de2168 100644
--- a/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qdir.cpp
+++ b/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qdir.cpp
@@ -66,8 +66,8 @@ s = dir.relativeFilePath("/home/mary/file.txt") # s is "../mary/file.txt"
//! [8]
-QDir.setSearchPaths("icons", QStringList(QDir.homePath() + "/images"))
-QDir.setSearchPaths("docs", QStringList(":/embeddedDocuments"))
+QDir.setSearchPaths("icons", [QDir.homePath() + "/images"])
+QDir.setSearchPaths("docs", [":/embeddedDocuments"])
...
pixmap = QPixmap("icons:undo.png") # will look for undo.png in QDir::homePath() + "/images"
file = QFile("docs:design.odf") # will look in the :/embeddedDocuments resource path
diff --git a/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qprocess.cpp b/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qprocess.cpp
index 228a24c..6b97e37 100644
--- a/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qprocess.cpp
+++ b/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qprocess.cpp
@@ -4,10 +4,10 @@ def wrapInFunction():
//! [0]
builder = QProcess()
builder.setProcessChannelMode(QProcess.MergedChannels)
-builder.start("make", QStringList() << "-j2")
+builder.start("make", ["-j2"])
import sys
-if !builder.waitForFinished():
+if not builder.waitForFinished():
sys.stderr.write("Make failed:" + builder.errorString())
else
sys.stderr.write("Make output:" + builder.readAll())
@@ -57,7 +57,7 @@ class SandboxProcess(QProcess):
//! [5]
process = QProcess()
process.start("del /s *.txt")
-# same as process.start("del", QStringList() << "/s" << "*.txt")
+# same as process.start("del", ["/s", "*.txt"])
...
//! [5]
@@ -76,8 +76,8 @@ process.start("dir \"\"\"My Documents\"\"\"")
//! [8]
environment = QProcess.systemEnvironment()
-# environment = {"PATH=/usr/bin:/usr/local/bin",
-# "USER=greg", "HOME=/home/greg"}
+# environment = [PATH=/usr/bin:/usr/local/bin",
+# "USER=greg", "HOME=/home/greg"]
//! [8]
diff --git a/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp b/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp
index 61ea362..1f20c3b 100644
--- a/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp
+++ b/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp
@@ -26,3 +26,23 @@ beginInsertColumns(parent, 6, 8)
//! [5]
beginRemoveColumns(parent, 4, 6)
//! [5]
+
+
+//! [6]
+beginMoveRows(sourceParent, 2, 4, destinationParent, 2)
+//! [6]
+
+
+//! [7]
+beginMoveRows(sourceParent, 2, 4, destinationParent, 6)
+//! [7]
+
+
+//! [8]
+beginMoveRows(parent, 2, 2, parent, 0)
+//! [8]
+
+
+//! [9]
+beginMoveRows(parent, 2, 2, parent, 4)
+//! [9]
diff --git a/doc/codesnippets/doc/src/snippets/code/src_corelib_statemachine_qstatemachine.cpp b/doc/codesnippets/doc/src/snippets/code/src_corelib_statemachine_qstatemachine.cpp
new file mode 100644
index 0000000..e768081
--- /dev/null
+++ b/doc/codesnippets/doc/src/snippets/code/src_corelib_statemachine_qstatemachine.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** 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$
+**
+****************************************************************************/
+
+//! [simple state machine]
+button = QPushButton()
+
+machine = QStateMachine()
+s1 = QState()
+s1.assignProperty(button, "text", "Click me")
+
+s2 = QFinalState()
+s1.addTransition(button, SIGNAL('clicked()'), s2)
+
+machine.addState(s1)
+machine.addState(s2)
+machine.setInitialState(s1)
+machine.start()
+//! [simple state machine]
diff --git a/doc/codesnippets/doc/src/snippets/qelapsedtimer/main.cpp b/doc/codesnippets/doc/src/snippets/qelapsedtimer/main.cpp
new file mode 100644
index 0000000..cae84e7
--- /dev/null
+++ b/doc/codesnippets/doc/src/snippets/qelapsedtimer/main.cpp
@@ -0,0 +1,109 @@
+/****************************************************************************
+**
+** 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 QtNetwork module 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 <QtCore>
+
+void slowOperation1()
+{
+ static char buf[256];
+ for (int i = 0; i < (1<<20); ++i)
+ buf[i % sizeof buf] = i;
+}
+
+void slowOperation2(int) { slowOperation1(); }
+
+void startExample()
+{
+//![0]
+ timer = QElapsedTimer()
+ timer.start()
+
+ slowOperation1()
+
+ sys.stderr.write("The slow operation took" + timer.elapsed() + "milliseconds")
+//![0]
+}
+
+//![1]
+def executeSlowOperations(timeout):
+ timer = QElapsedTimer()
+ timer.start()
+ slowOperation1()
+
+ remainingTime = timeout - timer.elapsed()
+ if remainingTime > 0:
+ slowOperation2(remainingTime)
+//![1]
+
+//![2]
+def executeOperationsForTime(ms):
+ timer = QElapsedTimer()
+ timer.start()
+
+ while not timer.hasExpired(ms):
+ slowOperation1()
+//![2]
+
+int restartExample()
+{
+//![3]
+ timer = QElapsedTimer()
+
+ count = 1
+ timer.start()
+
+ while True:
+ count *= 2
+ slowOperation2(count)
+ if timer.restart() < 250:
+ break
+
+ return count
+//![3]
+}
+
+int main(int argc, char **argv)
+{
+ QCoreApplication app(argc, argv);
+
+ startExample();
+ restartExample();
+ executeSlowOperations(5);
+ executeOperationsForTime(5);
+}
diff --git a/doc/codesnippets/doc/src/snippets/qelapsedtimer/qelapsedtimer.pro b/doc/codesnippets/doc/src/snippets/qelapsedtimer/qelapsedtimer.pro
new file mode 100644
index 0000000..b0a8f66
--- /dev/null
+++ b/doc/codesnippets/doc/src/snippets/qelapsedtimer/qelapsedtimer.pro
@@ -0,0 +1,2 @@
+SOURCES = main.cpp
+QT -= gui
diff --git a/doc/codesnippets/doc/src/snippets/qprocess-environment/main.cpp b/doc/codesnippets/doc/src/snippets/qprocess-environment/main.cpp
index 696daeb..9168197 100644
--- a/doc/codesnippets/doc/src/snippets/qprocess-environment/main.cpp
+++ b/doc/codesnippets/doc/src/snippets/qprocess-environment/main.cpp
@@ -1,40 +1,39 @@
/****************************************************************************
**
-** Copyright (C) 2009 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)
**
** This file is part of the documentation of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial Usage
-** Licensees holding valid Qt Commercial licenses may use this file in
-** accordance with the Qt Commercial License Agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Nokia.
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** "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.
**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://www.qtsoftware.com/contact.
+** 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$
**
****************************************************************************/
@@ -43,6 +42,7 @@
void startProcess()
{
+ {
//! [0]
import re
from PySide.QtCore import QProcess
@@ -56,6 +56,18 @@ env = [regex.sub(r'PATH=\1;C:\\Bin', var) for var in env]
process.setEnvironment(env)
process.start("myapp")
//! [0]
+ }
+
+ {
+//! [1]
+process = QProcess()
+env = QProcessEnvironment.systemEnvironment()
+env.insert("TMPDIR", "C:\\MyApp\\temp") # Add an environment variable
+env.insert("PATH", env.value("Path") + ";C:\\Bin")
+process.setProcessEnvironment(env)
+process.start("myapp")
+//! [1]
+ }
}
int main(int argc, char *argv[])
diff --git a/doc/codesnippets/doc/src/snippets/qprocess/qprocess-simpleexecution.cpp b/doc/codesnippets/doc/src/snippets/qprocess/qprocess-simpleexecution.cpp
index b17f9ef..779c909 100644
--- a/doc/codesnippets/doc/src/snippets/qprocess/qprocess-simpleexecution.cpp
+++ b/doc/codesnippets/doc/src/snippets/qprocess/qprocess-simpleexecution.cpp
@@ -56,7 +56,7 @@ int main(int argc, char *argv[])
program = "./../../../../examples/widgets/analogclock/analogclock";
//! [2]
- arguments ["-style", "motif"]
+ arguments = ["-style", "motif"]
myProcess = QProcess(parent)
myProcess.start(program, arguments)