|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the documentation of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
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 ** |
|
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. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include <QApplication> |
|
43 #include <QBuffer> |
|
44 #include <QPalette> |
|
45 |
|
46 static 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 |
|
62 static 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 |
|
74 static 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 |
|
88 static 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 |
|
101 static 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 |
|
115 int 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 } |