Updates to more code snippets on documentation concerning QtCore module.
Reviewed by Hugo Parente <hugo.lima@openbossa.org> Reviewed by Luciano Wolf <luciano.wolf@openbossa.org>
This commit is contained in:
parent
0220d7d176
commit
885386fdba
9 changed files with 236 additions and 38 deletions
|
|
@ -31,7 +31,7 @@ def create(fileName):
|
||||||
|
|
||||||
//! [2]
|
//! [2]
|
||||||
# @arg filters QDir.Filters
|
# @arg filters QDir.Filters
|
||||||
# @arg filterNames QStringList
|
# @arg filterNames [str, ...]
|
||||||
# @return QAbstractFileEngineIterator
|
# @return QAbstractFileEngineIterator
|
||||||
def beginEntryList(filters, filterNames):
|
def beginEntryList(filters, filterNames):
|
||||||
return CustomFileEngineIterator(filters, filterNames)
|
return CustomFileEngineIterator(filters, filterNames)
|
||||||
|
|
|
||||||
|
|
@ -66,8 +66,8 @@ s = dir.relativeFilePath("/home/mary/file.txt") # s is "../mary/file.txt"
|
||||||
|
|
||||||
|
|
||||||
//! [8]
|
//! [8]
|
||||||
QDir.setSearchPaths("icons", QStringList(QDir.homePath() + "/images"))
|
QDir.setSearchPaths("icons", [QDir.homePath() + "/images"])
|
||||||
QDir.setSearchPaths("docs", QStringList(":/embeddedDocuments"))
|
QDir.setSearchPaths("docs", [":/embeddedDocuments"])
|
||||||
...
|
...
|
||||||
pixmap = QPixmap("icons:undo.png") # will look for undo.png in QDir::homePath() + "/images"
|
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
|
file = QFile("docs:design.odf") # will look in the :/embeddedDocuments resource path
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,10 @@ def wrapInFunction():
|
||||||
//! [0]
|
//! [0]
|
||||||
builder = QProcess()
|
builder = QProcess()
|
||||||
builder.setProcessChannelMode(QProcess.MergedChannels)
|
builder.setProcessChannelMode(QProcess.MergedChannels)
|
||||||
builder.start("make", QStringList() << "-j2")
|
builder.start("make", ["-j2"])
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
if !builder.waitForFinished():
|
if not builder.waitForFinished():
|
||||||
sys.stderr.write("Make failed:" + builder.errorString())
|
sys.stderr.write("Make failed:" + builder.errorString())
|
||||||
else
|
else
|
||||||
sys.stderr.write("Make output:" + builder.readAll())
|
sys.stderr.write("Make output:" + builder.readAll())
|
||||||
|
|
@ -57,7 +57,7 @@ class SandboxProcess(QProcess):
|
||||||
//! [5]
|
//! [5]
|
||||||
process = QProcess()
|
process = QProcess()
|
||||||
process.start("del /s *.txt")
|
process.start("del /s *.txt")
|
||||||
# same as process.start("del", QStringList() << "/s" << "*.txt")
|
# same as process.start("del", ["/s", "*.txt"])
|
||||||
...
|
...
|
||||||
//! [5]
|
//! [5]
|
||||||
|
|
||||||
|
|
@ -76,8 +76,8 @@ process.start("dir \"\"\"My Documents\"\"\"")
|
||||||
|
|
||||||
//! [8]
|
//! [8]
|
||||||
environment = QProcess.systemEnvironment()
|
environment = QProcess.systemEnvironment()
|
||||||
# environment = {"PATH=/usr/bin:/usr/local/bin",
|
# environment = [PATH=/usr/bin:/usr/local/bin",
|
||||||
# "USER=greg", "HOME=/home/greg"}
|
# "USER=greg", "HOME=/home/greg"]
|
||||||
//! [8]
|
//! [8]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,3 +26,23 @@ beginInsertColumns(parent, 6, 8)
|
||||||
//! [5]
|
//! [5]
|
||||||
beginRemoveColumns(parent, 4, 6)
|
beginRemoveColumns(parent, 4, 6)
|
||||||
//! [5]
|
//! [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]
|
||||||
|
|
|
||||||
|
|
@ -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]
|
||||||
109
doc/codesnippets/doc/src/snippets/qelapsedtimer/main.cpp
Normal file
109
doc/codesnippets/doc/src/snippets/qelapsedtimer/main.cpp
Normal file
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
SOURCES = main.cpp
|
||||||
|
QT -= gui
|
||||||
|
|
@ -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)
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||||
**
|
**
|
||||||
** This file is part of the documentation of the Qt Toolkit.
|
** This file is part of the documentation of the Qt Toolkit.
|
||||||
**
|
**
|
||||||
** $QT_BEGIN_LICENSE:LGPL$
|
** $QT_BEGIN_LICENSE:BSD$
|
||||||
** Commercial Usage
|
** You may use this file under the terms of the BSD license as follows:
|
||||||
** 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.
|
|
||||||
**
|
**
|
||||||
** GNU Lesser General Public License Usage
|
** "Redistribution and use in source and binary forms, with or without
|
||||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
** modification, are permitted provided that the following conditions are
|
||||||
** General Public License version 2.1 as published by the Free Software
|
** met:
|
||||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
** * Redistributions of source code must retain the above copyright
|
||||||
** packaging of this file. Please review the following information to
|
** notice, this list of conditions and the following disclaimer.
|
||||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
** * Redistributions in binary form must reproduce the above copyright
|
||||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
** 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
|
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
** additional rights. These rights are described in the Nokia Qt LGPL
|
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
** package.
|
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
**
|
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
** GNU General Public License Usage
|
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
** Alternatively, this file may be used under the terms of the GNU
|
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
** General Public License version 3.0 as published by the Free Software
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
** packaging of this file. Please review the following information to
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
** ensure the GNU General Public License version 3.0 requirements will be
|
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||||
** 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.
|
|
||||||
** $QT_END_LICENSE$
|
** $QT_END_LICENSE$
|
||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
@ -43,6 +42,7 @@
|
||||||
|
|
||||||
void startProcess()
|
void startProcess()
|
||||||
{
|
{
|
||||||
|
{
|
||||||
//! [0]
|
//! [0]
|
||||||
import re
|
import re
|
||||||
from PySide.QtCore import QProcess
|
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.setEnvironment(env)
|
||||||
process.start("myapp")
|
process.start("myapp")
|
||||||
//! [0]
|
//! [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[])
|
int main(int argc, char *argv[])
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ int main(int argc, char *argv[])
|
||||||
program = "./../../../../examples/widgets/analogclock/analogclock";
|
program = "./../../../../examples/widgets/analogclock/analogclock";
|
||||||
|
|
||||||
//! [2]
|
//! [2]
|
||||||
arguments ["-style", "motif"]
|
arguments = ["-style", "motif"]
|
||||||
|
|
||||||
myProcess = QProcess(parent)
|
myProcess = QProcess(parent)
|
||||||
myProcess.start(program, arguments)
|
myProcess.start(program, arguments)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue