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
src_corelib_text_qbytearrayview.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3#include <QByteArrayView>
4
5//! [0]
6 void myfun1(QByteArrayView bv); // preferred
7 void myfun2(const QByteArrayView &bv); // compiles and works, but slower
8//! [0]
9
10//! [1]
11 void fun(QByteArrayView bv);
12 void fun(char ch) { fun(QByteArrayView(&ch, 1)); }
13//! [1]
14
16{
17 {
18 //! [2]
19 QByteArrayView str("FF");
20 bool ok;
21 int hex = str.toInt(&ok, 16); // hex == 255, ok == true
22 int dec = str.toInt(&ok, 10); // dec == 0, ok == false
23 //! [2]
24 }
25
26 {
27 //! [3]
28 QByteArrayView str("FF");
29 bool ok;
30 long hex = str.toLong(&ok, 16); // hex == 255, ok == true
31 long dec = str.toLong(&ok, 10); // dec == 0, ok == false
32 //! [3]
33 }
34
35 {
36 //! [4]
37 QByteArrayView string("1234.56 Volt");
38 bool ok;
39 float a = string.toFloat(&ok); // a == 0, ok == false
40 a = string.first(7).toFloat(&ok); // a == 1234.56, ok == true
41 //! [4]
42 }
43}
bool examples()
[3]
void myfun1(QAnyStringView sv)
[0]
void myfun2(const QAnyStringView &sv)
void fun(QByteArrayView bv)
[0]
void fun(char ch)