Qt
6.x
The Qt SDK
Toggle main menu visibility
Main Page
Related Pages
Namespaces
Namespace List
Namespace Members
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
y
z
Typedefs
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
Enumerations
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
Enumerator
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Classes
Class List
Class Hierarchy
Class Members
All
:
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Typedefs
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
y
Enumerations
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Enumerator
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Properties
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Related Symbols
:
a
b
c
d
e
f
g
h
i
j
l
m
n
o
p
q
r
s
t
u
v
w
Files
File List
File Members
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Typedefs
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Enumerations
_
a
b
c
d
e
f
g
h
i
j
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Enumerator
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
Macros
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Pages
Loading...
Searching...
No Matches
src_corelib_tools_qscopedpointer.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
5
void
myFunction
(
bool
useSubClass)
6
{
7
MyClass
*
p
= useSubClass ?
new
MyClass
() :
new
MySubClass;
8
QIODevice
*
device
= handsOverOwnership();
9
10
if
(m_value > 3) {
11
delete
p
;
12
delete
device
;
13
return
;
14
}
15
16
try
{
17
process(
device
);
18
}
19
catch
(...) {
20
delete
p
;
21
delete
device
;
22
throw
;
23
}
24
25
delete
p
;
26
delete
device
;
27
}
29
31
void
myFunction
(
bool
useSubClass)
32
{
33
// assuming that MyClass has a virtual destructor
34
QScopedPointer<MyClass>
p
(useSubClass ?
new
MyClass
() : new MySubClass);
35
QScopedPointer<QIODevice>
device
(handsOverOwnership());
36
37
if
(m_value > 3)
38
return
;
39
40
process(
device
);
41
}
43
45
const
QWidget
*
const
p
=
new
QWidget
();
46
// is equivalent to:
47
const
QScopedPointer<const QWidget>
p
(
new
QWidget
());
48
49
QWidget
*
const
p
=
new
QWidget
();
50
// is equivalent to:
51
const
QScopedPointer<QWidget>
p
(
new
QWidget
());
52
53
const
QWidget
*
p
=
new
QWidget
();
54
// is equivalent to:
55
QScopedPointer<const QWidget>
p
(
new
QWidget
());
57
59
if
(scopedPointer) {
60
...
61
}
63
65
class
MyPrivateClass;
// forward declare MyPrivateClass
66
67
class
MyClass
68
{
69
private
:
70
QScopedPointer<MyPrivateClass>
privatePtr;
// QScopedPointer to forward declared class
71
72
public
:
73
MyClass
();
// OK
74
inline
~MyClass
() {}
// VIOLATION - Destructor must not be inline
75
76
private
:
77
Q_DISABLE_COPY(
MyClass
)
// OK - copy constructor and assignment operators
78
// are now disabled, so the compiler won't implicitly
79
// generate them.
80
};
82
84
// this QScopedPointer deletes its data using the delete[] operator:
85
QScopedPointer<int, QScopedPointerArrayDeleter<int>
>
arrayPointer
(
new
int
[42]);
86
87
// this QScopedPointer frees its data using free():
88
QScopedPointer<int, QScopedPointerPodDeleter>
podPointer
(
reinterpret_cast<
int
*
>
(malloc(42)));
89
90
// this struct calls "myCustomDeallocator" to delete the pointer
91
struct
ScopedPointerCustomDeleter
92
{
93
static
inline
void
cleanup
(MyCustomClass *
pointer
)
94
{
95
myCustomDeallocator(
pointer
);
96
}
97
};
98
99
// QScopedPointer using a custom deleter:
100
QScopedPointer<MyCustomClass, ScopedPointerCustomDeleter>
customPointer
(
new
MyCustomClass);
device
IOBluetoothDevice * device
Definition
btl2capchannel.mm:17
MyClass
[4]
Definition
doc_src_properties.cpp:58
MyClass::~MyClass
~MyClass()
Definition
src_corelib_tools_qscopedpointer.cpp:74
MyClass::MyClass
MyClass()
[4]
Definition
doc_src_resources.cpp:10
QIODevice
\inmodule QtCore \reentrant
Definition
qiodevice.h:34
QScopedPointer
\inmodule QtCore
Definition
qscopedpointer.h:71
QWidget
The QWidget class is the base class of all user interface objects.
Definition
qwidget.h:99
pointer
GLsizei const void * pointer
Definition
qopenglext.h:384
p
GLfloat GLfloat p
[1]
Definition
qopenglext.h:12698
myFunction
MyPrototype myFunction
[0]
Definition
src_corelib_plugin_qlibrary.cpp:7
p
const QWidget *const p
[1]
Definition
src_corelib_tools_qscopedpointer.cpp:45
arrayPointer
QScopedPointer< int, QScopedPointerArrayDeleter< int > > arrayPointer(new int[42])
[4]
podPointer
QScopedPointer< int, QScopedPointerPodDeleter > podPointer(reinterpret_cast< int * >(malloc(42)))
customPointer
QScopedPointer< MyCustomClass, ScopedPointerCustomDeleter > customPointer(new MyCustomClass)
ScopedPointerCustomDeleter
Definition
src_corelib_tools_qscopedpointer.cpp:92
ScopedPointerCustomDeleter::cleanup
static void cleanup(MyCustomClass *pointer)
Definition
src_corelib_tools_qscopedpointer.cpp:93
qtbase
src
corelib
doc
snippets
code
src_corelib_tools_qscopedpointer.cpp
Generated by
1.9.7