aboutsummaryrefslogtreecommitdiffstats
path: root/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qiodevice.cpp
blob: 44bd19795ccb89c32e3b5c0a7308a2e59a797fe3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//! [0]
gzip = QProcess()
gzip.start("gzip", QStringList() << "-c")
if !gzip.waitForStarted():
    return false

gzip.write("uncompressed data");

compressed = QByteArray()
while gzip.waitForReadyRead():
    compressed += gzip.readAll()
//! [0]


//! [1]
def bytesAvailable(self):
    return buffer.size() + QIODevice.bytesAvailable()
//! [1]


//! [2]
file = QFile("box.txt")
if file.open(QFile.ReadOnly):
    buf = file.readLine(1024);
    if buf.size():
        # the line is available in buf
//! [2]


//! [3]
def canReadLine(self):
    return buffer.contains('\n') || QIODevice.canReadLine()
//! [3]


//! [4]
def isExeFile(file):
    buf = file->peek(2);
    if buf.size() == 2:
        return (buf[0] == 'M' && buf[1] == 'Z')
    return false
//! [4]


//! [5]
def isExeFile(file):
    return file->peek(2) == "MZ"
//! [5]