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
qwinregistry_p.h
Go to the documentation of this file.
1// Copyright (C) 2019 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:trivial-impl-only
4
5#ifndef QWINREGISTRY_H
6#define QWINREGISTRY_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#include <QtCore/qstring.h>
20#include <QtCore/qstringview.h>
21#include <QtCore/qt_windows.h>
22#include <QtCore/qvariant.h>
23#include <QtCore/qobject.h>
24#include <QtCore/qmetaobject.h>
25#include <QtCore/private/quniquehandle_types_p.h>
26
28
29class Q_CORE_EXPORT QWinRegistryKey : public QObject
30{
31 Q_DISABLE_COPY(QWinRegistryKey)
32 Q_OBJECT
33
34public:
35 QWinRegistryKey(QObject *parent = nullptr);
36 explicit QWinRegistryKey(HKEY parentHandle, const wchar_t *subKey,
37 REGSAM permissions = KEY_READ, REGSAM access = 0,
38 QObject *parent = nullptr);
39 explicit QWinRegistryKey(HKEY parentHandle, const QString &subKey,
40 REGSAM permissions = KEY_READ, REGSAM access = 0,
41 QObject *parent = nullptr);
42 ~QWinRegistryKey();
43
44 QWinRegistryKey(QWinRegistryKey &&other) noexcept
45#if 1 // QTBUG-140725
46 = delete;
47 void operator=(QWinRegistryKey &&) = delete;
48#else
49 : m_key(std::exchange(other.m_key, nullptr)) {}
50 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QWinRegistryKey)
51 void swap(QWinRegistryKey &other) noexcept
52 {
53 qt_ptr_swap(m_key, other.m_key);
54 }
55#endif
56
57 [[nodiscard]] bool isValid() const { return m_key != nullptr; }
58
59 [[nodiscard]] HKEY handle() const { return m_key; }
60
61 operator HKEY() const { return handle(); }
62
63 void close();
64
65 QString name() const;
66
67 [[nodiscard]] QVariant value(const wchar_t *subKey) const;
68 [[nodiscard]] QVariant value(const QString &subKey) const;
69
70 template<typename T>
71 [[nodiscard]] std::optional<T> value(const wchar_t *subKey) const
72 {
73 return to_optional<T>(value(subKey));
74 }
75
76 template<typename T>
77 [[nodiscard]] std::optional<T> value(const QString &subKey) const
78 {
79 return to_optional<T>(value(subKey));
80 }
81
82 QString stringValue(const wchar_t *subKey) const;
83 QString stringValue(const QString &subKey) const;
84
85#ifndef QT_NO_DEBUG_STREAM
86 friend Q_CORE_EXPORT QDebug operator<<(QDebug dbg, const QWinRegistryKey &);
87#endif
88
89Q_SIGNALS:
90 void valueChanged();
91
92protected:
93 void connectNotify(const QMetaMethod &signal) override;
94
95private:
96 template<typename T>
97 static std::optional<T> to_optional(QVariant v)
98 {
99 if (v.isValid())
100 return qvariant_cast<T>(std::move(v));
101 return std::nullopt;
102 }
103
104 HKEY m_key = nullptr;
105 QUniqueWin32NullHandle m_keyChangedEvent;
106};
107
108QT_END_NAMESPACE
109
110#endif // QWINREGISTRY_H
QDebug operator<<(QDebug dbg, const QFileInfo &fi)
static const wchar_t * nullTerminate(const QString &s)