Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
buffer.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4#include <QApplication>
5#include <QBuffer>
6#include <QPalette>
7
8static void main_snippet()
9{
10//! [0]
11 QBuffer buffer;
12 char ch;
13
14 buffer.open(QBuffer::ReadWrite);
15 buffer.write("Qt rocks!");
16 buffer.seek(0);
17 buffer.getChar(&ch); // ch == 'Q'
18 buffer.getChar(&ch); // ch == 't'
19 buffer.getChar(&ch); // ch == ' '
20 buffer.getChar(&ch); // ch == 'r'
21//! [0]
22}
23
25{
26//! [1]
27 QByteArray byteArray;
28 QBuffer buffer(&byteArray);
29 buffer.open(QIODevice::WriteOnly);
30
31 QDataStream out(&buffer);
32 out << QApplication::palette();
33//! [1]
34}
35
37{
38 QByteArray byteArray;
39
40//! [2]
41 QPalette palette;
42 QBuffer buffer(&byteArray);
43 buffer.open(QIODevice::ReadOnly);
44
45 QDataStream in(&buffer);
46 in >> palette;
47//! [2]
48}
49
51{
52//! [3]
53 QByteArray byteArray("abc");
54 QBuffer buffer(&byteArray);
55 buffer.open(QIODevice::WriteOnly);
56 buffer.seek(3);
57 buffer.write("def", 3);
58 buffer.close();
59 // byteArray == "abcdef"
60//! [3]
61}
62
63static void setBuffer_snippet()
64{
65//! [4]
66 QByteArray byteArray("abc");
67 QBuffer buffer;
68 buffer.setBuffer(&byteArray);
69 buffer.open(QIODevice::WriteOnly);
70 buffer.seek(3);
71 buffer.write("def", 3);
72 buffer.close();
73 // byteArray == "abcdef"
74//! [4]
75}
76
77int main(int argc, char *argv[])
78{
79 QApplication app(argc, argv);
80
86 return 0;
87}
int main(int argc, char *argv[])
[2]
Definition buffer.cpp:77
static void main_snippet()
Definition buffer.cpp:8
static void bytearray_ptr_ctor_snippet()
Definition buffer.cpp:50
static void setBuffer_snippet()
Definition buffer.cpp:63
static void write_datastream_snippets()
Definition buffer.cpp:24
static void read_datastream_snippets()
Definition buffer.cpp:36