source: trunk/doc/src/snippets/buffer/buffer.cpp@ 651

Last change on this file since 651 was 651, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.2 sources.

File size: 3.5 KB
RevLine 
[2]1/****************************************************************************
2**
[651]3** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
[561]4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
[2]6**
7** This file is part of the documentation of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
[561]24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
[2]27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
[561]36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
[2]38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include <QApplication>
43#include <QBuffer>
44#include <QPalette>
45
46static void main_snippet()
47{
48//! [0]
49 QBuffer buffer;
50 char ch;
51
52 buffer.open(QBuffer::ReadWrite);
53 buffer.write("Qt rocks!");
54 buffer.seek(0);
55 buffer.getChar(&ch); // ch == 'Q'
56 buffer.getChar(&ch); // ch == 't'
57 buffer.getChar(&ch); // ch == ' '
58 buffer.getChar(&ch); // ch == 'r'
59//! [0]
60}
61
62static void write_datastream_snippets()
63{
64//! [1]
65 QByteArray byteArray;
66 QBuffer buffer(&byteArray);
67 buffer.open(QIODevice::WriteOnly);
68
69 QDataStream out(&buffer);
70 out << QApplication::palette();
71//! [1]
72}
73
74static void read_datastream_snippets()
75{
76 QByteArray byteArray;
77
78//! [2]
79 QPalette palette;
80 QBuffer buffer(&byteArray);
81 buffer.open(QIODevice::ReadOnly);
82
83 QDataStream in(&buffer);
84 in >> palette;
85//! [2]
86}
87
88static void bytearray_ptr_ctor_snippet()
89{
90//! [3]
91 QByteArray byteArray("abc");
92 QBuffer buffer(&byteArray);
93 buffer.open(QIODevice::WriteOnly);
94 buffer.seek(3);
95 buffer.write("def", 3);
96 buffer.close();
97 // byteArray == "abcdef"
98//! [3]
99}
100
101static void setBuffer_snippet()
102{
103//! [4]
104 QByteArray byteArray("abc");
105 QBuffer buffer;
106 buffer.setBuffer(&byteArray);
107 buffer.open(QIODevice::WriteOnly);
108 buffer.seek(3);
109 buffer.write("def", 3);
110 buffer.close();
111 // byteArray == "abcdef"
112//! [4]
113}
114
115int main(int argc, char *argv[])
116{
117 QApplication app(argc, argv);
118
119 main_snippet();
120 bytearray_ptr_ctor_snippet();
121 write_datastream_snippets();
122 read_datastream_snippets();
123 setBuffer_snippet();
124 return 0;
125}
Note: See TracBrowser for help on using the repository browser.