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
4#ifndef QWINREGISTRY_H
5#define QWINREGISTRY_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/qstring.h>
19#include <QtCore/qstringview.h>
20#include <QtCore/qt_windows.h>
21#include <QtCore/qvariant.h>
22#include <QtCore/qobject.h>
23#include <QtCore/qmetaobject.h>
24#include <QtCore/private/quniquehandle_types_p.h>
25
27
28class Q_CORE_EXPORT QWinRegistryKey : public QObject
29{
30 Q_DISABLE_COPY(QWinRegistryKey)
31 Q_OBJECT
32
33public:
34 QWinRegistryKey(QObject *parent = nullptr);
35 explicit QWinRegistryKey(HKEY parentHandle, const wchar_t *subKey,
36 REGSAM permissions = KEY_READ, REGSAM access = 0,
37 QObject *parent = nullptr);
38 explicit QWinRegistryKey(HKEY parentHandle, const QString &subKey,
39 REGSAM permissions = KEY_READ, REGSAM access = 0,
40 QObject *parent = nullptr);
41 ~QWinRegistryKey();
42
43 QWinRegistryKey(QWinRegistryKey &&other) noexcept
44 : m_key(std::exchange(other.m_key, nullptr)) {}
45 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QWinRegistryKey)
46 void swap(QWinRegistryKey &other) noexcept
47 {
48 qt_ptr_swap(m_key, other.m_key);
49 }
50
51 [[nodiscard]] bool isValid() const { return m_key != nullptr; }
52
53 [[nodiscard]] HKEY handle() const { return m_key; }
54
55 operator HKEY() const { return handle(); }
56
57 void close();
58
59 QString name() const;
60
61 [[nodiscard]] QVariant value(const wchar_t *subKey) const;
62 [[nodiscard]] QVariant value(const QString &subKey) const;
63
64 template<typename T>
65 [[nodiscard]] std::optional<T> value(const wchar_t *subKey) const
66 {
67 return to_optional<T>(value(subKey));
68 }
69
70 template<typename T>
71 [[nodiscard]] std::optional<T> value(const QString &subKey) const
72 {
73 return to_optional<T>(value(subKey));
74 }
75
76 QString stringValue(const wchar_t *subKey) const;
77 QString stringValue(const QString &subKey) const;
78
79#ifndef QT_NO_DEBUG_STREAM
80 friend Q_CORE_EXPORT QDebug operator<<(QDebug dbg, const QWinRegistryKey &);
81#endif
82
83Q_SIGNALS:
84 void valueChanged();
85
86protected:
87 void connectNotify(const QMetaMethod &signal) override;
88
89private:
90 template<typename T>
91 static std::optional<T> to_optional(QVariant v)
92 {
93 if (v.isValid())
94 return qvariant_cast<T>(std::move(v));
95 return std::nullopt;
96 }
97
98 HKEY m_key = nullptr;
99 QUniqueWin32NullHandle m_keyChangedEvent;
100};
101
102QT_END_NAMESPACE
103
104#endif // QWINREGISTRY_H
QDebug operator<<(QDebug dbg, const QFileInfo &fi)
static const wchar_t * nullTerminate(const QString &s)