Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qcomvariant_p.h
Go to the documentation of this file.
1
// Copyright (C) 2024 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#
ifndef
QCOMVARIANT_P_H
6
#
define
QCOMVARIANT_P_H
7
8
//
9
// W A R N I N G
10
// -------------
11
//
12
// This file is not part of the Qt API. It exists purely as an
13
// implementation detail. This header file may change from version to
14
// version without notice, or even be removed.
15
//
16
// We mean it.
17
//
18
19
#
if
defined
(
Q_OS_WIN
)
||
defined
(
Q_QDOC
)
20
21
// clang-format off
22
#
include
<
QtCore
/
private
/
qglobal_p
.
h
>
23
#
include
<
QtCore
/
qt_windows
.
h
>
24
#
include
<
QtCore
/
private
/
qbstr_p
.
h
>
25
#
include
<
QtCore
/
private
/
qcomptr_p
.
h
>
26
// clang-format on
27
28
QT_BEGIN_NAMESPACE
29
30
struct
QComVariant
31
{
32
// clang-format off
33
QComVariant()
noexcept
34
{
35
VariantInit(&m_variant);
36
}
37
38
~QComVariant()
noexcept
39
{
40
clear();
41
}
42
43
explicit
QComVariant(
bool
value)
noexcept
44
{
45
m_variant.vt = VT_BOOL;
46
m_variant.boolVal = value ? VARIANT_TRUE : VARIANT_FALSE;
47
}
48
49
explicit
QComVariant(
int
value)
noexcept
50
{
51
m_variant.vt = VT_INT;
52
m_variant.intVal = value;
53
}
54
55
explicit
QComVariant(
long
value)
noexcept
56
{
57
m_variant.vt = VT_I4;
58
m_variant.lVal = value;
59
}
60
61
explicit
QComVariant(
double
value)
noexcept
62
{
63
m_variant.vt = VT_R8;
64
m_variant.dblVal = value;
65
}
66
67
template
<
typename
T>
68
QComVariant(
const
ComPtr<T> &value)
noexcept
69
{
70
static_assert
(std::is_base_of_v<IUnknown, T>,
"Invalid COM interface"
);
71
ComPtr<IUnknown> unknown = value;
72
m_variant.vt = VT_UNKNOWN;
73
m_variant.punkVal = unknown.Detach();
// Transfer ownership
74
}
75
76
QComVariant(QBStr &&value)
noexcept
77
{
78
m_variant.vt = VT_BSTR;
79
m_variant.bstrVal = value.release();
// Transfer ownership
80
}
81
82
QComVariant(
const
QString &str)
83
{
84
m_variant.vt = VT_BSTR;
85
m_variant.bstrVal = QBStr{ str }.release();
// Transfer ownership of copy
86
}
87
88
const
VARIANT &get()
const
noexcept
89
{
90
return
m_variant;
91
}
92
93
VARIANT &get()
noexcept
94
{
95
return
m_variant;
96
}
97
// clang-format on
98
99
[[nodiscard]] VARIANT *operator&()
noexcept
// NOLINT(google-runtime-operator)
100
{
101
clear();
102
return
&m_variant;
103
}
104
105
VARIANT release()
noexcept
106
{
107
const
VARIANT detached{ m_variant };
108
VariantInit(&m_variant);
109
return
detached;
110
}
111
112
QComVariant(
const
QComVariant &) =
delete
;
113
QComVariant &operator=(
const
QComVariant &) =
delete
;
114
QComVariant(QComVariant && other) =
delete
;
115
QComVariant &operator=(QComVariant &&) =
delete
;
116
117
private
:
118
119
void
clear()
120
{
121
const
HRESULT hr = VariantClear(&m_variant);
122
Q_ASSERT(hr == S_OK);
123
Q_UNUSED(hr)
124
125
VariantInit(&m_variant);
// Clear value field
126
}
127
128
VARIANT m_variant{};
129
};
130
131
QT_END_NAMESPACE
132
133
#
endif
// Q_OS_WIN
134
135
#
endif
// QCOMVARIANT_P_H
qtbase
src
corelib
platform
windows
qcomvariant_p.h
Generated on
for Qt by
1.18.0