summaryrefslogtreecommitdiffstats
path: root/doc/codesnippets/doc/src/snippets
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2010-12-02 16:18:29 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2010-12-03 07:54:44 -0300
commit7ee87cc8f2f0185482a76a1ae3db87179150e19c (patch)
treeb67adba5a96c4fd6cff7b4bccd72e867d96cb1ac /doc/codesnippets/doc/src/snippets
parent59b4f2b59dcdee3831335c69109d3c19290d940f (diff)
downloadpyside-7ee87cc8f2f0185482a76a1ae3db87179150e19c.tar.gz
pyside-7ee87cc8f2f0185482a76a1ae3db87179150e19c.tar.xz
pyside-7ee87cc8f2f0185482a76a1ae3db87179150e19c.zip
Updated a lot of code snippets on documentation concerning QtCore module.
Reviewed by Hugo Parente <hugo.lima@openbossa.org> Reviewed by Luciano Wolf <luciano.wolf@openbossa.org>
Diffstat (limited to 'doc/codesnippets/doc/src/snippets')
-rw-r--r--doc/codesnippets/doc/src/snippets/code/doc_src_unicode.qdoc8
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_corelib_codecs_qtextcodec.cpp22
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qthreadpool.cpp2
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_corelib_global_qglobal.cpp50
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_corelib_io_qabstractfileengine.cpp12
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_corelib_io_qdatastream.cpp46
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_corelib_io_qdir.cpp8
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_corelib_io_qfileinfo.cpp12
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_corelib_io_qiodevice.cpp24
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_corelib_io_qprocess.cpp5
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_corelib_io_qsettings.cpp8
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_corelib_io_qtemporaryfile.cpp6
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_corelib_io_qtextstream.cpp22
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_corelib_io_qurl.cpp8
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qcoreapplication.cpp18
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp8
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qtimer.cpp2
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qthread.cpp2
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qbitarray.cpp2
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qbytearray.cpp14
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qdatetime.cpp2
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qlocale.cpp13
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qtimeline.cpp4
-rw-r--r--doc/codesnippets/doc/src/snippets/process/process.cpp2
-rw-r--r--doc/codesnippets/doc/src/snippets/qdir-namefilters/main.cpp33
-rw-r--r--doc/codesnippets/doc/src/snippets/qprocess-environment/main.cpp9
-rw-r--r--doc/codesnippets/doc/src/snippets/qprocess/qprocess-simpleexecution.cpp5
-rw-r--r--doc/codesnippets/doc/src/snippets/timers/timers.cpp8
-rw-r--r--doc/codesnippets/doc/src/snippets/whatsthis/whatsthis.cpp4
29 files changed, 172 insertions, 187 deletions
diff --git a/doc/codesnippets/doc/src/snippets/code/doc_src_unicode.qdoc b/doc/codesnippets/doc/src/snippets/code/doc_src_unicode.qdoc
index 30a3710..526c755 100644
--- a/doc/codesnippets/doc/src/snippets/code/doc_src_unicode.qdoc
+++ b/doc/codesnippets/doc/src/snippets/code/doc_src_unicode.qdoc
@@ -1,18 +1,18 @@
//! [0]
-label->setText("Password:");
+label.setText("Password:")
//! [0]
//! [1]
-label->setText(tr("Password:"));
+label.setText(QObject.tr("Password:"))
//! [1]
//! [2]
-QFile file(QString::fromLatin1("appicon.png"));
+file_ = QFile("appicon.png")
//! [2]
//! [3]
-QFile file(QLatin1String("appicon.png"));
+file_= QFile("appicon.png")
//! [3]
diff --git a/doc/codesnippets/doc/src/snippets/code/src_corelib_codecs_qtextcodec.cpp b/doc/codesnippets/doc/src/snippets/code/src_corelib_codecs_qtextcodec.cpp
index f1c839d..47a5c7a 100644
--- a/doc/codesnippets/doc/src/snippets/code/src_corelib_codecs_qtextcodec.cpp
+++ b/doc/codesnippets/doc/src/snippets/code/src_corelib_codecs_qtextcodec.cpp
@@ -1,25 +1,25 @@
//! [0]
encodedString = QByteArray("...")
-codec = QTextCodec::codecForName("KOI8-R")
-string = codec->toUnicode(encodedString)
+codec = QTextCodec.codecForName("KOI8-R")
+string = codec.toUnicode(encodedString)
//! [0]
//! [1]
-string = QString("...")
-codec = QTextCodec::codecForName("KOI8-R")
-encodedString = codec->fromUnicode(string)
+string = u"..."
+codec = QTextCodec.codecForName("KOI8-R")
+encodedString = codec.fromUnicode(string)
//! [1]
//! [2]
-codec = QTextCodec::codecForName("Shift-JIS")
-decoder = codec->makeDecoder()
+codec = QTextCodec.codecForName("Shift-JIS")
+decoder = codec.makeDecoder()
-string = QString()
+string = u''
while new_data_available():
- chunk = get_new_data();
- string += decoder->toUnicode(chunk)
+ chunk = get_new_data()
+ string += decoder.toUnicode(chunk)
//! [2]
@@ -27,6 +27,6 @@ while new_data_available():
//! [3]
def main():
app = QApplication([])
- QTextCodec::setCodecForTr(QTextCodec::codecForName("eucKR"))
+ QTextCodec.setCodecForTr(QTextCodec.codecForName("eucKR"))
...
//! [3]
diff --git a/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qthreadpool.cpp b/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qthreadpool.cpp
index 174b878..ecbfe23 100644
--- a/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qthreadpool.cpp
+++ b/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qthreadpool.cpp
@@ -5,5 +5,5 @@ class HelloWorldTask(QRunnable):
hello = HelloWorldTask()
# QThreadPool takes ownership and deletes 'hello' automatically
-QThreadPool.globalInstance()->start(hello)
+QThreadPool.globalInstance().start(hello)
//! [0]
diff --git a/doc/codesnippets/doc/src/snippets/code/src_corelib_global_qglobal.cpp b/doc/codesnippets/doc/src/snippets/code/src_corelib_global_qglobal.cpp
index 287181a..4c12049 100644
--- a/doc/codesnippets/doc/src/snippets/code/src_corelib_global_qglobal.cpp
+++ b/doc/codesnippets/doc/src/snippets/code/src_corelib_global_qglobal.cpp
@@ -1,5 +1,5 @@
//! [0]
-label->setAlignment(Qt::AlignLeft | Qt::AlignTop);
+label.setAlignment(Qt.AlignLeft | Qt.AlignTop)
//! [0]
@@ -73,60 +73,58 @@ quint64 value = Q_UINT64_C(932838457459459);
//! [10]
-int absoluteValue;
-int myValue = -4;
-
-absoluteValue = qAbs(myValue);
+myValue = -4
+absoluteValue = qAbs(myValue)
// absoluteValue == 4
//! [10]
//! [11]
-qreal valueA = 2.3;
-qreal valueB = 2.7;
+valueA = 2.3
+valueB = 2.7
-int roundedValueA = qRound(valueA);
+roundedValueA = qRound(valueA)
// roundedValueA = 2
-int roundedValueB = qRound(valueB);
+roundedValueB = qRound(valueB)
// roundedValueB = 3
//! [11]
//! [12]
-qreal valueA = 42949672960.3;
-qreal valueB = 42949672960.7;
+valueA = 42949672960.3
+valueB = 42949672960.7
-int roundedValueA = qRound(valueA);
+roundedValueA = qRound(valueA)
// roundedValueA = 42949672960
-int roundedValueB = qRound(valueB);
+roundedValueB = qRound(valueB)
// roundedValueB = 42949672961
//! [12]
//! [13]
-int myValue = 6;
-int yourValue = 4;
+myValue = 6
+yourValue = 4
-int minValue = qMin(myValue, yourValue);
+minValue = qMin(myValue, yourValue)
// minValue == yourValue
//! [13]
//! [14]
-int myValue = 6;
-int yourValue = 4;
+myValue = 6
+yourValue = 4
-int maxValue = qMax(myValue, yourValue);
+maxValue = qMax(myValue, yourValue)
// maxValue == myValue
//! [14]
//! [15]
-int myValue = 10;
-int minValue = 2;
-int maxValue = 6;
+myValue = 10
+minValue = 2
+maxValue = 6
-int boundedValue = qBound(minValue, myValue, maxValue);
+boundedValue = qBound(minValue, myValue, maxValue)
// boundedValue == 6
//! [15]
@@ -436,7 +434,7 @@ namespace QT_NAMESPACE {
//! [43]
class MyClass : public QObject
{
-
+
private:
Q_DISABLE_COPY(MyClass)
};
@@ -446,7 +444,7 @@ class MyClass : public QObject
//! [44]
class MyClass : public QObject
{
-
+
private:
MyClass(const MyClass &);
MyClass &operator=(const MyClass &);
@@ -454,7 +452,7 @@ class MyClass : public QObject
//! [44]
//! [45]
- QWidget w = QWidget();
+ w = QWidget()
//! [45]
//! [46]
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 5984b62..de0fd50 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
@@ -1,6 +1,6 @@
//! [0]
-class ZipEngineHandler(QAbstractFileEngineHandler)
- def create(fileName):
+class ZipEngineHandler(QAbstractFileEngineHandler):
+ def create(self, fileName):
# ZipEngineHandler returns a ZipEngine for all .zip files
if fileName.toLower().endsWith(".zip"):
return ZipEngine(fileName)
@@ -22,7 +22,7 @@ def main():
//! [1]
def create(fileName):
# ZipEngineHandler returns a ZipEngine for all .zip files
- if fileName.toLower().endsWith(".zip"):
+ if fileName.lower().endswith(".zip"):
return ZipEngine(fileName)
else
return None
@@ -52,9 +52,9 @@ class CustomIterator(QAbstractFileEngineIterator):
return self.index < self.entries.size() - 1
def next(self):
- if !self.hasNext():
- return QString()
- index++
+ if not self.hasNext():
+ return None
+ index += 1
return currentFilePath()
def currentFileName(self):
diff --git a/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qdatastream.cpp b/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qdatastream.cpp
index 6b66276..033a54c 100644
--- a/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qdatastream.cpp
+++ b/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qdatastream.cpp
@@ -2,27 +2,27 @@ void wrapInFunction()
{
//! [0]
-file = QFile("file.dat")
-file.open(QIODevice.WriteOnly)
+file_ = QFile("file.dat")
+file_.open(QIODevice.WriteOnly)
# we will serialize the data into the file
-out = QDataStream(file)
+out = QDataStream(file_)
# serialize a string
-out << "the answer is"
+out.writeQString("the answer is")
# serialize an integer
out.writeInt32(42)
//! [0]
//! [1]
-file = QFile("file.dat")
-file.open(QIODevice.ReadOnly)
+file_ = QFile("file.dat")
+file_.open(QIODevice.ReadOnly)
# read the data serialized from the file
-i = QDataStream(file)
-str = QString()
+i = QDataStream(file_)
+string = ''
a = 0
# extract "the answer is" and 42
-i >> str
-a = i.readInt32()
+string = i.readQString()
+a = i.readInt32()
//! [1]
@@ -32,15 +32,15 @@ stream.setVersion(QDataStream.Qt_4_0)
//! [3]
-file = QFile("file.xxx")
-file.open(QIODevice.WriteOnly)
-out = QDataStream(file)
+file_ = QFile("file.xxx")
+file_.open(QIODevice.WriteOnly)
+out = QDataStream(file_)
# Write a header with a "magic number" and a version
out.writeInt32(0xA0B0C0D0)
out.writeInt32(123)
-out.setVersion(QDataStream.Qt_4_0);
+out.setVersion(QDataStream.Qt_4_0)
// Write the data
out << lots_of_interesting_data
@@ -48,9 +48,9 @@ out << lots_of_interesting_data
//! [4]
-file = QFile("file.xxx")
-file.open(QIODevice.ReadOnly)
-i = QDataStream(file)
+file_ = QFile("file.xxx")
+file_.open(QIODevice.ReadOnly)
+i = QDataStream(file_)
// Read and check the header
magic = i.readInt32()
@@ -65,20 +65,20 @@ if version > 123:
return XXX_BAD_FILE_TOO_NEW
if version <= 110:
- in.setVersion(QDataStream.Qt_3_2)
+ in_.setVersion(QDataStream.Qt_3_2)
else:
- in.setVersion(QDataStream.Qt_4_0)
+ in_.setVersion(QDataStream.Qt_4_0)
// Read the data
-in >> lots_of_interesting_data
+in_ >> lots_of_interesting_data
if version >= 120:
- in >> data_new_in_XXX_version_1_2
-in >> other_interesting_data
+ in_ >> data_new_in_XXX_version_1_2
+in_ >> other_interesting_data
//! [4]
//! [5]
-out = QDataStream(file)
+out = QDataStream(file_)
out.setVersion(QDataStream.Qt_4_0)
//! [5]
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 5bb0b07..a849e48 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
@@ -28,14 +28,14 @@ absolutePath = directory.absoluteFilePath("contents.txt")
//! [4]
dir = QDir("example")
-if !dir.exists():
+if not dir.exists():
print "Cannot find the example directory"
//! [4]
//! [5]
dir = QDir.root() # "/"
-if !dir.cd("tmp"): # "/tmp"
+if not dir.cd("tmp"): # "/tmp"
print "Cannot find the \"/tmp\" directory"
else:
file = QFile(dir.filePath("ex1.txt")) # "/tmp/ex1.txt"
@@ -83,7 +83,7 @@ if dir.isRoot():
//! [10]
-// The current directory is "/usr/local"
+# The current directory is "/usr/local"
d1 = QDir("/usr/local/bin")
d2 = QDir("bin")
if d1 == d2:
@@ -112,7 +112,7 @@ Q_INIT_RESOURCE(myapp);
//! [14]
-def initMyResource():
+def initMyResource():
Q_INIT_RESOURCE(myapp)
class MyNamespace
diff --git a/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qfileinfo.cpp b/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qfileinfo.cpp
index fb0e1c8..c021c3b 100644
--- a/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qfileinfo.cpp
+++ b/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qfileinfo.cpp
@@ -11,7 +11,7 @@ info1.size() # returns 56201
info1.symLinkTarget() # returns "/opt/pretty++/bin/untabify"
info2 = QFileInfo(info1.symLinkTarget())
-info1.isSymLink() # returns false
+info1.isSymLink() # returns False
info1.absoluteFilePath() # returns "/opt/pretty++/bin/untabify"
info1.size() # returns 56201
@@ -20,25 +20,25 @@ info1.size() # returns 56201
//! [1]
info1 = QFileInfo("C:\\Documents and Settings\\Bob\\untabify.lnk")
-info1.isSymLink() # returns true
+info1.isSymLink() # returns True
info1.absoluteFilePath() # returns "C:/Documents and Settings/Bob/untabify.lnk"
info1.size() # returns 743
info1.symLinkTarget() # returns "C:/Pretty++/untabify"
info2 = QFileInfo(info1.symLinkTarget())
-info1.isSymLink() # returns false
+info1.isSymLink() # returns False
info1.absoluteFilePath() # returns "C:/Pretty++/untabify"
info1.size() # returns 63942
//! [1]
//! [2]
-absolute = QString("/local/bin")
-relative = QString("local/bin")
+absolute = "/local/bin"
+relative = "local/bin"
absFile = QFileInfo(absolute)
relFile = QFileInfo(relative)
-QDir.setCurrent(QDir::rootPath())
+QDir.setCurrent(QDir.rootPath())
# absFile and relFile now point to the same file
QDir.setCurrent("/tmp")
diff --git a/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qiodevice.cpp b/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qiodevice.cpp
index 44bd197..6b791bf 100644
--- a/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qiodevice.cpp
+++ b/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qiodevice.cpp
@@ -1,10 +1,10 @@
//! [0]
gzip = QProcess()
-gzip.start("gzip", QStringList() << "-c")
-if !gzip.waitForStarted():
- return false
+gzip.start("gzip", ["-c"])
+if not gzip.waitForStarted():
+ return False
-gzip.write("uncompressed data");
+gzip.write("uncompressed data")
compressed = QByteArray()
while gzip.waitForReadyRead():
@@ -21,7 +21,7 @@ def bytesAvailable(self):
//! [2]
file = QFile("box.txt")
if file.open(QFile.ReadOnly):
- buf = file.readLine(1024);
+ buf = file.readLine(1024)
if buf.size():
# the line is available in buf
//! [2]
@@ -29,20 +29,20 @@ if file.open(QFile.ReadOnly):
//! [3]
def canReadLine(self):
- return buffer.contains('\n') || QIODevice.canReadLine()
+ return buffer.contains('\n') or QIODevice.canReadLine()
//! [3]
//! [4]
-def isExeFile(file):
- buf = file->peek(2);
+def isExeFile(file_):
+ buf = file_.peek(2)
if buf.size() == 2:
- return (buf[0] == 'M' && buf[1] == 'Z')
- return false
+ return buf[0] == 'M' and buf[1] == 'Z'
+ return False
//! [4]
//! [5]
-def isExeFile(file):
- return file->peek(2) == "MZ"
+def isExeFile(file_):
+ return file_.peek(2) == "MZ"
//! [5]
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 7f4bd7a..228a24c 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
@@ -6,10 +6,11 @@ builder = QProcess()
builder.setProcessChannelMode(QProcess.MergedChannels)
builder.start("make", QStringList() << "-j2")
+import sys
if !builder.waitForFinished():
- qDebug() << "Make failed:" << builder.errorString()
+ sys.stderr.write("Make failed:" + builder.errorString())
else
- qDebug() << "Make output:" << builder.readAll()
+ sys.stderr.write("Make output:" + builder.readAll())
//! [0]
diff --git a/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qsettings.cpp b/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qsettings.cpp
index 71745fa..f07dc8b 100644
--- a/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qsettings.cpp
+++ b/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qsettings.cpp
@@ -106,8 +106,8 @@ settings.endGroup()
//! [15]
class Login:
- userName = QString()
- password = QString()
+ userName = ''
+ password = ''
logins = []
...
@@ -127,8 +127,8 @@ class Login:
//! [16]
class Login:
- userName = QString()
- password = QString()
+ userName = ''
+ password = ''
logins = []
...
diff --git a/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qtemporaryfile.cpp b/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qtemporaryfile.cpp
index 8ebbd9e..77d394e 100644
--- a/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qtemporaryfile.cpp
+++ b/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qtemporaryfile.cpp
@@ -2,9 +2,9 @@
//! [0]
# Within a function/method...
- file = QTemporaryFile()
- if file.open():
- # file.fileName() returns the unique file name
+ file_ = QTemporaryFile()
+ if file_.open():
+ # file_.fileName() returns the unique file name
# The QTemporaryFile destructor removes the temporary file
# as it goes out of scope.
diff --git a/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qtextstream.cpp b/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qtextstream.cpp
index 6988af4..18e1f69 100644
--- a/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qtextstream.cpp
+++ b/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qtextstream.cpp
@@ -1,6 +1,6 @@
//! [0]
data = QFile("output.txt")
-if data.open(QFile.WriteOnly | QFile::Truncate):
+if data.open(QFile.WriteOnly | QFile.Truncate):
out = QTextStream(&data)
out << "Result: " << qSetFieldWidth(10) << left << 3.14 << 2.7
# writes "Result: 3.14 2.7 "
@@ -19,15 +19,15 @@ while(True):
//! [2]
-in = QTextStream("0x50 0x20")
+in_ = QTextStream("0x50 0x20")
firstNumber = 0
secondNumber = 0
-in >> firstNumber # firstNumber == 80
-in >> dec >> secondNumber # secondNumber == 0
+in_ >> firstNumber # firstNumber == 80
+in_ >> dec >> secondNumber # secondNumber == 0
ch = None
-in >> ch # ch == 'x'
+in_ >> ch # ch == 'x'
//! [2]
@@ -36,16 +36,16 @@ def main():
# read numeric arguments (123, 0x20, 4.5...)
for i in sys.argv():
number = None
- QTextStream in(i)
- in >> number
+ QTextStream in_(i)
+ in_ >> number
...
//! [3]
//! [4]
str = QString()
-in = QTextStream(sys.stdin.fileno())
-in >> str
+in_ = QTextStream(sys.stdin.fileno())
+in_ >> str
//! [4]
@@ -65,11 +65,11 @@ out << "Qt" << "rocks!"
//! [7]
-in = QTextStream(file)
+in_ = QTextStream(file)
ch1 = QChar()
ch2 = QChar()
ch3 = QChar()
-in >> ch1 >> ch2 >> ch3;
+in_ >> ch1 >> ch2 >> ch3;
//! [7]
diff --git a/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qurl.cpp b/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qurl.cpp
index a568438..c0a4fca 100644
--- a/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qurl.cpp
+++ b/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qurl.cpp
@@ -12,10 +12,10 @@ url = QUrl.fromEncoded("http://qtsoftware.com/List%20of%20holidays.xml")
//! [2]
def checkUrl(url):
if !url.isValid():
- print QString("Invalid URL: %1").arg(url.toString())
- return false
+ print "Invalid URL: %s" % url.toString()
+ return False
- return true
+ return True
//! [2]
@@ -41,6 +41,6 @@ print baseUrl.resolved(relativeUrl).toString()
//! [6]
ba = QUrl.toPercentEncoding("{a fishy string?}", "{}", "s")
-print ba.constData()
+print ba
# prints "{a fi%73hy %73tring%3F}"
//! [6]
diff --git a/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qcoreapplication.cpp b/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qcoreapplication.cpp
index f9cc001..48d3a24 100644
--- a/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qcoreapplication.cpp
+++ b/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qcoreapplication.cpp
@@ -6,7 +6,7 @@ QApplication.sendEvent(mainWindow, event)
//! [1]
quitButton = QPushButton("Quit")
-QObject.connect(quitButton, SIGNAL("clicked()"), app, SLOT("quit()"))
+quitButton.clicked.connect(app.quit)
//! [1]
@@ -22,19 +22,11 @@ myEventFilter(message, result)
//! [4]
-static int *global_ptr = 0;
+def cleanup_stuff():
+ # do the cleanup stuff
-static void cleanup_ptr()
-{
- delete [] global_ptr;
- global_ptr = 0;
-}
-
-void init_ptr()
-{
- global_ptr = new int[100]; // allocate data
- qAddPostRoutine(cleanup_ptr); // delete later
-}
+def init_stuff():
+ qAddPostRoutine(cleanup_stuff)
//! [4]
diff --git a/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp b/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp
index 5676f13..046b40c 100644
--- a/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp
+++ b/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp
@@ -48,17 +48,13 @@ class MyClass:
//! [propertyCount]
metaObject = obj.metaObject()
-properties = QStringList()
-for i in range(metaObject.propertyOffset(), metaObject.propertyCount()):
- properties << QString.fromLatin1(metaObject.property(i).name())
+properties = [metaObject.property(i).name() for i in range(metaObject.propertyOffset(), metaObject.propertyCount())]
//! [propertyCount]
//! [methodCount]
metaObject = obj.metaObject()
-methods = QStringList()
-for i in rang(metaObject.methodOffset(), metaObject->methodCount()):
- methods << QString.fromLatin1(metaObject.method(i).signature())
+methods = [metaObject.method(i).signature() for i in range(metaObject.methodOffset(), metaObject.methodCount())]
//! [methodCount]
//! [6]
diff --git a/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qtimer.cpp b/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qtimer.cpp
index 1b7ea4e..bb646a1 100644
--- a/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qtimer.cpp
+++ b/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qtimer.cpp
@@ -6,5 +6,5 @@ def main():
app = QApplication([])
QTimer.singleShot(600000, app, SLOT('quit()'))
...
- return app.exec()
+ return app.exec_()
//! [0]
diff --git a/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qthread.cpp b/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qthread.cpp
index a100127..768f96f 100644
--- a/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qthread.cpp
+++ b/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qthread.cpp
@@ -5,5 +5,5 @@ class MyThread (QThread):
# connect QTcpSocket's signals somewhere meaningful
# ...
socket.connectToHost(hostName, portNumber)
- exec_()
+ self.exec_()
//! [0]
diff --git a/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qbitarray.cpp b/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qbitarray.cpp
index 19be88f..d794676 100644
--- a/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qbitarray.cpp
+++ b/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qbitarray.cpp
@@ -173,7 +173,7 @@ c = a | b
//! [14]
a = QBitArray(3)
-QBitArray b(2)
+b = QBitArray(2)
c = QBitArray()
a[0] = 1
a[1] = 0
diff --git a/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qbytearray.cpp b/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qbytearray.cpp
index c097a26..c563df4 100644
--- a/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qbytearray.cpp
+++ b/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qbytearray.cpp
@@ -327,15 +327,13 @@ ba = QByteArray.number(12.3456, 'E', 3)
//! [43]
- static const char mydata[] = {
- 0x00, 0x00, 0x03, 0x84, 0x78, 0x9c, 0x3b, 0x76,
- 0xec, 0x18, 0xc3, 0x31, 0x0a, 0xf1, 0xcc, 0x99,
- ...
- 0x6d, 0x5b
-};
+mydata = '\x00\x00\x03\x84\x78\x9c\x3b\x76'\
+ '\xec\x18\xc3\x31\x0a\xf1\xcc\x99'\
+ ...
+ '\x6d\x5b'
-QByteArray data = QByteArray::fromRawData(mydata, sizeof(mydata));
-QDataStream in(&data, QIODevice::ReadOnly);
+data = QByteArray.fromRawData(mydata)
+in_ = QDataStream(data, QIODevice.ReadOnly)
...
//! [43]
diff --git a/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qdatetime.cpp b/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qdatetime.cpp
index b935e34..ccd4380 100644
--- a/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qdatetime.cpp
+++ b/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qdatetime.cpp
@@ -36,7 +36,7 @@ QDate.isValid(1202, 6, 6) # True (even though 1202 is pre-Gregorian)
//! [5]
-n = QTime(14, 0, 0) # n == 14:00:00
+n = QTime(14, 0, 0) # n == 14:00:00
t = QTime()
t = n.addSecs(70) # t == 14:01:10
t = n.addSecs(-70) # t == 13:58:50
diff --git a/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qlocale.cpp b/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qlocale.cpp
index 6fedb1f..c1b8468 100644
--- a/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qlocale.cpp
+++ b/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qlocale.cpp
@@ -14,15 +14,18 @@ hebrew = QLocale() # Constructs a default QLocale
s1 = hebrew.toString(15714.3, 'e')
QLocale.setDefault(QLocale(QLocale.C))
-(d, ok) = QString("1234,56").toDouble() # ok == false
-(d, ok) = QString("1234.56").toDouble() # ok == true, d == 1234.56
+c = QLocale()
+(d, ok) = c.toDouble("1234,56") # ok == false
+(d, ok) = c.toDouble("1234.56") # ok == true, d == 1234.56
QLocale.setDefault(QLocale(QLocale.German))
-(d, ok) = QString("1234,56").toDouble() # ok == true, d == 1234.56
-(d, ok) = QString("1234.56").toDouble() # ok == true, d == 1234.56
+german = QLocale()
+(d, ok) = german.toDouble("1234,56") # ok == true, d == 1234.56
+(d, ok) = german.toDouble("1234.56") # ok == true, d == 1234.56
QLocale.setDefault(QLocale(QLocale.English, QLocale.UnitedStates))
-string = QString("%1 %L2 %L3").arg(12345).arg(12345).arg(12345, 0, 16)
+english = QLocale()
+string = '%s %s %10x' % (12345, english.toString(12345), 12345)
# string == "12345 12,345 3039"
//! [1]
diff --git a/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qtimeline.cpp b/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qtimeline.cpp
index 5f2e978..5b0d16e 100644
--- a/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qtimeline.cpp
+++ b/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qtimeline.cpp
@@ -6,10 +6,10 @@ progressBar.setRange(0, 100)
# Construct a 1-second timeline with a frame range of 0 - 100
timeLine = QTimeLine(1000, self)
timeLine.setFrameRange(0, 100)
-QObject.connect(timeLine, SIGNAL("frameChanged(int)"), progressBar, SLOT("setValue(int)"))
+timeLine.frameChanged[int].connect(progressBar.setValue)
# Clicking the push button will start the progress bar animation
pushButton = QPushButton(QObject.tr("Start animation"), self)
-QObject.connect(pushButton, SIGNAL("clicked()"), timeLine, SLOT("start()"))
+pushButton.clicked.connect(timeLine.start)
...
//! [0]
diff --git a/doc/codesnippets/doc/src/snippets/process/process.cpp b/doc/codesnippets/doc/src/snippets/process/process.cpp
index 3baeb58..7201bdb 100644
--- a/doc/codesnippets/doc/src/snippets/process/process.cpp
+++ b/doc/codesnippets/doc/src/snippets/process/process.cpp
@@ -45,7 +45,7 @@ bool zip()
{
//! [0]
gzip = QProcess()
- gzip.start("gzip", QStringList() << "-c")
+ gzip.start("gzip", ["-c"])
if not gzip.waitForStarted():
return False
diff --git a/doc/codesnippets/doc/src/snippets/qdir-namefilters/main.cpp b/doc/codesnippets/doc/src/snippets/qdir-namefilters/main.cpp
index d34fdf3..259821f 100644
--- a/doc/codesnippets/doc/src/snippets/qdir-namefilters/main.cpp
+++ b/doc/codesnippets/doc/src/snippets/qdir-namefilters/main.cpp
@@ -39,28 +39,21 @@
**
****************************************************************************/
-#include <QDir>
-#include <iostream>
+from PySide.QtCore import *
-int main(int argc, char *argv[])
-{
- QDir dir;
- dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
- dir.setSorting(QDir::Size | QDir::Reversed);
+def main():
+ dir_ = QDir()
+ dir_.setFilter(QDir.Files | QDir.Hidden | QDir.NoSymLinks)
+ dir_.setSorting(QDir.Size | QDir.Reversed)
//! [0]
- filters = QStringList()
- filters << "*.cpp" << "*.cxx" << "*.cc"
- dir.setNameFilters(filters)
+ filters = ["*.cpp", "*.cxx", "*.cc"]
+ dir_.setNameFilters(filters)
//! [0]
+//
+ lst = d.entryInfoList()
+
+ print " Bytes Filename"
+ for fileInfo in lst:
+ print '%d %s' % (fileInfo.size(), fileInfo.fileName())
- QFileInfoList list = dir.entryInfoList();
- std::cout << " Bytes Filename" << std::endl;
- for (int i = 0; i < list.size(); ++i) {
- QFileInfo fileInfo = list.at(i);
- std::cout << qPrintable(QString("%1 %2").arg(fileInfo.size(), 10)
- .arg(fileInfo.fileName()));
- std::cout << std::endl;
- }
- return 0;
-}
diff --git a/doc/codesnippets/doc/src/snippets/qprocess-environment/main.cpp b/doc/codesnippets/doc/src/snippets/qprocess-environment/main.cpp
index ed49da3..696daeb 100644
--- a/doc/codesnippets/doc/src/snippets/qprocess-environment/main.cpp
+++ b/doc/codesnippets/doc/src/snippets/qprocess-environment/main.cpp
@@ -44,10 +44,15 @@
void startProcess()
{
//! [0]
+import re
+from PySide.QtCore import QProcess
+
process = QProcess()
+
env = QProcess.systemEnvironment()
-env << "TMPDIR=C:\\MyApp\\temp" # Add an environment variable
-env.replaceInStrings(QRegExp("^PATH=(.*)", Qt.CaseInsensitive), "PATH=\\1;C:\\Bin")
+env.append("TMPDIR=C:\\MyApp\\temp") # Add an environment variable
+regex = re.compile(r'^PATH=(.*)', re.IGNORECASE)
+env = [regex.sub(r'PATH=\1;C:\\Bin', var) for var in env]
process.setEnvironment(env)
process.start("myapp")
//! [0]
diff --git a/doc/codesnippets/doc/src/snippets/qprocess/qprocess-simpleexecution.cpp b/doc/codesnippets/doc/src/snippets/qprocess/qprocess-simpleexecution.cpp
index 09bb7ca..b17f9ef 100644
--- a/doc/codesnippets/doc/src/snippets/qprocess/qprocess-simpleexecution.cpp
+++ b/doc/codesnippets/doc/src/snippets/qprocess/qprocess-simpleexecution.cpp
@@ -51,13 +51,12 @@ int main(int argc, char *argv[])
parent = &app;
//! [1]
- program = QString("./path/to/Qt/examples/widgets/analogclock")
+ program = "./path/to/Qt/examples/widgets/analogclock"
//! [1]
program = "./../../../../examples/widgets/analogclock/analogclock";
//! [2]
- arguments = QStringList()
- arguments << "-style" << "motif"
+ arguments ["-style", "motif"]
myProcess = QProcess(parent)
myProcess.start(program, arguments)
diff --git a/doc/codesnippets/doc/src/snippets/timers/timers.cpp b/doc/codesnippets/doc/src/snippets/timers/timers.cpp
index 3e5e1ac..9a05870 100644
--- a/doc/codesnippets/doc/src/snippets/timers/timers.cpp
+++ b/doc/codesnippets/doc/src/snippets/timers/timers.cpp
@@ -39,7 +39,7 @@
**
****************************************************************************/
-#include <QTimer>
+from PySide.QtCore import QTimer
class Foo : public QObject
{
@@ -52,7 +52,7 @@ Foo::Foo()
//! [0]
timer = QTimer(self)
//! [0] //! [1]
- self.connect(timer, SIGNAL("timeout()"), self.updateCaption)
+ timer.timeout.connect(self.updateCaption)
//! [1] //! [2]
timer.start(1000)
//! [2]
@@ -66,7 +66,7 @@ Foo::Foo()
//! [4]
timer = QTimer(self)
//! [4] //! [5]
- self.connect(timer, SIGNAL("timeout()"), self.processOneThing)
+ timer.timeout.connect(self.processOneThing)
//! [5] //! [6]
timer.start()
//! [6]
@@ -75,5 +75,5 @@ Foo::Foo()
int main()
{
-
+
}
diff --git a/doc/codesnippets/doc/src/snippets/whatsthis/whatsthis.cpp b/doc/codesnippets/doc/src/snippets/whatsthis/whatsthis.cpp
index 4bd1961..871254b 100644
--- a/doc/codesnippets/doc/src/snippets/whatsthis/whatsthis.cpp
+++ b/doc/codesnippets/doc/src/snippets/whatsthis/whatsthis.cpp
@@ -42,7 +42,7 @@
//! [0]
Act = QAction(tr("&New"), self)
Act.setShortcut(tr("Ctrl+N"))
- Act.setStatusTip(tr("Create a new file"))
- Act.setWhatsThis(tr("Click self option to create a new file."))
+ Act.setStatusTip(QObject.tr("Create a new file"))
+ Act.setWhatsThis(QObject.tr("Click self option to create a new file."))
//! [0]