15#ifndef KEY_WOW64_64KEY
17# define KEY_WOW64_64KEY 0x0100
20#ifndef KEY_WOW64_32KEY
22# define KEY_WOW64_32KEY 0x0200
48 return rKey.
left(idx + 1);
61 if (
res ==
"Default"_L1 ||
res ==
"."_L1)
71 for (
int i = 0;
i < l; ++
i) {
72 auto &ucs =
data[
i].unicode();
112 HKEY resultHandle = 0;
113 LONG
res = RegOpenKeyEx(parentHandle,
reinterpret_cast<const wchar_t *
>(rSubKey.
utf16()),
114 0, perms |
access, &resultHandle);
116 if (
res == ERROR_SUCCESS)
127 HKEY resultHandle =
openKey(parentHandle, perms, rSubKey,
access);
128 if (resultHandle != 0)
132 LONG
res = RegCreateKeyEx(parentHandle,
reinterpret_cast<const wchar_t *
>(rSubKey.
utf16()), 0, 0,
133 REG_OPTION_NON_VOLATILE, perms |
access, 0, &resultHandle, 0);
135 if (
res == ERROR_SUCCESS)
150 if (resultHandle != 0) {
158 if (resultHandle != 0) {
172 DWORD maxSubgroupSize;
175 LONG
res = RegQueryInfoKey(parentHandle, 0, 0, 0, &numSubgroups, &maxSubgroupSize, 0,
176 &numKeys, &maxKeySize, 0, 0, 0);
178 if (
res != ERROR_SUCCESS) {
201 for (
int i = 0;
i <
n; ++
i) {
203 DWORD l = DWORD(buff.
size()) / DWORD(
sizeof(
wchar_t));
205 res = RegEnumValue(parentHandle,
i,
reinterpret_cast<wchar_t *
>(buff.
data()), &l, 0, 0, 0, 0);
207 res = RegEnumKeyEx(parentHandle,
i,
reinterpret_cast<wchar_t *
>(buff.
data()), &l, 0, 0, 0, 0);
209 if (
res == ERROR_SUCCESS)
212 if (
res != ERROR_SUCCESS) {
233 for (
int i = 0;
i < childKeys.size(); ++
i) {
237 s += childKeys.at(
i);
241 for (
int i = 0;
i < childGroups.size(); ++
i) {
245 s += childGroups.at(
i);
254 for (
int i = 0;
i < childGroups.size(); ++
i) {
259 if (childGroupHandle == 0)
262 RegCloseKey(childGroupHandle);
265 LONG
res = RegDeleteKey(parentHandle,
reinterpret_cast<const wchar_t *
>(
group.utf16()));
266 if (
res != ERROR_SUCCESS) {
288 HKEY m_parent_handle;
289 mutable HKEY m_handle;
291 mutable bool m_read_only;
296 : m_parent_handle(parent_handle),
299 m_read_only(read_only),
315 m_handle =
openKey(m_parent_handle, KEY_READ, m_key, m_access);
317 m_handle =
createOrOpenKey(m_parent_handle, m_key, &m_read_only, m_access);
324 return m_parent_handle;
335 RegCloseKey(m_handle);
356 std::optional<QVariant>
get(
const QString &uKey)
const override;
358 void clear()
override;
359 void sync()
override;
360 void flush()
override;
363 std::optional<QVariant>
readKey(HKEY parentHandle,
const QString &rSubKey)
const;
368 bool deleteWriteHandleOnExit;
377 deleteWriteHandleOnExit =
false;
380 QString prefix =
"Software\\"_L1 + organization;
381 QString orgPrefix = prefix +
"\\OrganizationDefaults"_L1;
382 QString appPrefix = prefix + u
'\\' + application;
385 if (!application.isEmpty())
391 if (!application.isEmpty())
405 deleteWriteHandleOnExit =
false;
413 if (rPath.
startsWith(
"HKEY_CURRENT_USER"_L1)) {
419 }
else if (rPath.
startsWith(
"HKEY_LOCAL_MACHINE"_L1)) {
425 }
else if (rPath.
startsWith(
"HKEY_CLASSES_ROOT"_L1)) {
431 }
else if (rPath.
startsWith(
"HKEY_USERS"_L1)) {
441 if (rPath.
length() == keyLength)
443 else if (rPath[keyLength] == u
'\\')
462 LONG
res = RegQueryValueEx(
handle,
reinterpret_cast<const wchar_t *
>(rSubkeyName.
utf16()), 0, &dataType, 0, &
dataSize);
463 if (
res != ERROR_SUCCESS)
467 if (dataType == REG_SZ || dataType == REG_EXPAND_SZ)
469 else if (dataType == REG_MULTI_SZ)
474 res = RegQueryValueEx(
handle,
reinterpret_cast<const wchar_t *
>(rSubkeyName.
utf16()), 0, 0,
475 reinterpret_cast<unsigned char*
>(
data.data()), &
dataSize);
476 if (
res != ERROR_SUCCESS)
514 case REG_DWORD_BIG_ENDIAN:
518 memcpy(
reinterpret_cast<char*
>(&
i),
data.constData(),
sizeof(
int));
525 memcpy(
reinterpret_cast<char*
>(&
i),
data.constData(),
sizeof(
qint64));
530 qWarning(
"QSettings: Unknown data %d type in Windows registry",
static_cast<int>(dataType));
542 if (
key.handle() == 0 ||
key.readOnly())
549 if (deleteWriteHandleOnExit &&
writeHandle() != 0) {
551 DWORD
res = RegDeleteKey(
writeHandle(),
reinterpret_cast<const wchar_t *
>(emptyKey.
utf16()));
552 if (
res != ERROR_SUCCESS) {
558 for (
int i = 0;
i < regList.
size(); ++
i)
575 res = RegDeleteValue(
handle,
reinterpret_cast<const wchar_t *
>(
keyName(rKey).utf16()));
588 LONG
res = RegDeleteValue(
handle,
reinterpret_cast<const wchar_t *
>(
group.utf16()));
589 if (
res != ERROR_SUCCESS) {
590 qErrnoWarning(
int(
res),
"QSettings: RegDeleteValue failed on subkey \"%ls\"",
597 if (
res != ERROR_SUCCESS) {
625 switch (
value.typeId()) {
626 case QMetaType::QVariantList:
627 case QMetaType::QStringList: {
632 QStringList::const_iterator
it = l.constBegin();
633 for (;
it != l.constEnd(); ++
it) {
640 if (
type == REG_BINARY) {
642 regValueBuff =
QByteArray(
reinterpret_cast<const char *
>(
s.data()),
s.length() * 2);
644 QStringList::const_iterator
it = l.constBegin();
645 for (;
it != l.constEnd(); ++
it) {
647 regValueBuff +=
QByteArray(
reinterpret_cast<const char*
>(
s.utf16()), (
s.length() + 1) * 2);
649 regValueBuff.
append((
char)0);
650 regValueBuff.
append((
char)0);
656 case QMetaType::UInt: {
663 case QMetaType::LongLong:
664 case QMetaType::ULongLong: {
671 case QMetaType::QByteArray:
682 regValueBuff =
QByteArray(
reinterpret_cast<const char *
>(
s.utf16()),
683 int(
sizeof(
wchar_t)) *
length);
689 LONG
res = RegSetValueEx(
handle,
reinterpret_cast<const wchar_t *
>(
keyName(rKey).utf16()), 0,
type,
690 reinterpret_cast<const unsigned char*
>(regValueBuff.
constData()),
691 regValueBuff.
size());
693 if (
res == ERROR_SUCCESS) {
694 deleteWriteHandleOnExit =
false;
727 HKEY parent_handle =
r.handle();
728 if (parent_handle == 0) {
761 deleteWriteHandleOnExit =
true;
781 if (
key.parentHandle() == HKEY_CURRENT_USER)
782 result =
"\\HKEY_CURRENT_USER\\"_L1;
784 result =
"\\HKEY_LOCAL_MACHINE\\"_L1;
800 case QSettings::Registry32Format:
802 case QSettings::Registry64Format:
815 case QSettings::Registry32Format:
817 case QSettings::Registry64Format:
char * data()
\macro QT_NO_CAST_FROM_BYTEARRAY
qsizetype size() const noexcept
Returns the number of bytes in this byte array.
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
QByteArray & append(char c)
This is an overloaded member function, provided for convenience. It differs from the above function o...
qsizetype size() const noexcept
bool isEmpty() const noexcept
const_reference at(qsizetype i) const noexcept
const T & constFirst() const noexcept
void append(parameter_type t)
iterator insert(const Key &key, const T &value)
const_iterator constBegin() const noexcept
const_iterator constEnd() const noexcept
bool contains(const T &value) const
virtual QString fileName() const =0
static QStringList variantListToStringList(const QVariantList &l)
static QSettingsPrivate * create(QSettings::Format format, QSettings::Scope scope, const QString &organization, const QString &application)
void setStatus(QSettings::Status status) const
static QVariant stringListToVariantList(const QStringList &l)
static QVariant stringToVariant(const QString &s)
static QString variantToString(const QVariant &v)
Format
This enum type specifies the storage format used by QSettings.
Scope
This enum specifies whether settings are user-specific or shared by all users of the same system.
\macro QT_RESTRICTED_CAST_FROM_ASCII
qsizetype lastIndexOf(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
const ushort * utf16() const
Returns the QString as a '\0\'-terminated array of unsigned shorts.
QString mid(qsizetype position, qsizetype n=-1) const
Returns a string that contains n characters of this string, starting at the specified position index.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
QChar * data()
Returns a pointer to the data stored in the QString.
static QString fromWCharArray(const wchar_t *string, qsizetype size=-1)
QString left(qsizetype n) const
Returns a substring that contains the n leftmost characters of the string.
QString & remove(qsizetype i, qsizetype len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
qsizetype length() const
Returns the number of characters in this string.
~QWinSettingsPrivate() override
bool isWritable() const override
void set(const QString &uKey, const QVariant &value) override
void remove(const QString &uKey) override
QWinSettingsPrivate(QSettings::Scope scope, const QString &organization, const QString &application, REGSAM access=0)
std::optional< QVariant > get(const QString &uKey) const override
std::optional< QVariant > readKey(HKEY parentHandle, const QString &rSubKey) const
QString fileName() const override
HKEY parentHandle() const
RegistryKey(HKEY parent_handle=0, const QString &key=QString(), bool read_only=true, REGSAM access=0)
QSet< QString >::iterator it
void qErrnoWarning(const char *msg,...)
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLuint64 GLenum void * handle
GLenum GLuint GLenum GLsizei length
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint GLsizei GLsizei GLenum format
QScopeGuard< typename std::decay< F >::type > qScopeGuard(F &&f)
[qScopeGuard]
static void deleteChildGroups(HKEY parentHandle, REGSAM access=0)
QMap< QString, QString > NameSet
static QString escapedKey(QString uKey)
static void mergeKeySets(NameSet *dest, const NameSet &src)
static QString unescapedKey(QString rKey)
static void allKeys(HKEY parentHandle, const QString &rSubKey, NameSet *result, REGSAM access=0)
static HKEY createOrOpenKey(HKEY parentHandle, REGSAM perms, const QString &rSubKey, REGSAM access=0)
static QString keyPath(const QString &rKey)
static QString keyName(const QString &rKey)
static QStringList childKeysOrGroups(HKEY parentHandle, QSettingsPrivate::ChildSpec spec)
static const REGSAM registryPermissions
static HKEY openKey(HKEY parentHandle, REGSAM perms, const QString &rSubKey, REGSAM access=0)
QList< RegistryKey > RegistryKeyList
#define qUtf16Printable(string)
QFuture< QSet< QChar > > set
[10]