Qt 4.8
Public Functions | Properties | List of all members
QWinSettingsPrivate Class Reference
Inheritance diagram for QWinSettingsPrivate:
QSettingsPrivate QObjectPrivate QObjectData

Public Functions

QStringList children (const QString &uKey, ChildSpec spec) const
 
void clear ()
 
QString fileName () const
 
void flush ()
 
bool get (const QString &uKey, QVariant *value) const
 
bool isWritable () const
 
 QWinSettingsPrivate (QSettings::Scope scope, const QString &organization, const QString &application)
 
 QWinSettingsPrivate (QString rKey)
 
bool readKey (HKEY parentHandle, const QString &rSubKey, QVariant *value) const
 
void remove (const QString &uKey)
 
void set (const QString &uKey, const QVariant &value)
 
void sync ()
 
HKEY writeHandle () const
 
 ~QWinSettingsPrivate ()
 
- Public Functions inherited from QSettingsPrivate
QString actualKey (const QString &key) const
 
void beginGroupOrArray (const QSettingsGroup &group)
 
 QSettingsPrivate (QSettings::Format format)
 
 QSettingsPrivate (QSettings::Format format, QSettings::Scope scope, const QString &organization, const QString &application)
 
void requestUpdate ()
 
void setStatus (QSettings::Status status) const
 
void update ()
 
virtual ~QSettingsPrivate ()
 
- Public Functions inherited from QObjectPrivate
void _q_reregisterTimers (void *pointer)
 
void addConnection (int signal, Connection *c)
 
void cleanConnectionLists ()
 
void connectNotify (const char *signal)
 
void deleteChildren ()
 
void disconnectNotify (const char *signal)
 
bool isSender (const QObject *receiver, const char *signal) const
 
bool isSignalConnected (uint signalIdx) const
 Returns true if the signal with index signal_index from object sender is connected. More...
 
void moveToThread_helper ()
 
 QObjectPrivate (int version=QObjectPrivateVersion)
 
QObjectList receiverList (const char *signal) const
 
QObjectList senderList () const
 
void setParent_helper (QObject *)
 
void setThreadData_helper (QThreadData *currentData, QThreadData *targetData)
 
int signalIndex (const char *signalName) const
 Returns the signal index used in the internal connectionLists vector. More...
 
virtual ~QObjectPrivate ()
 
- Public Functions inherited from QObjectData
virtual ~QObjectData ()=0
 

Properties

bool deleteWriteHandleOnExit
 
RegistryKeyList regList
 

Additional Inherited Members

- Public Types inherited from QSettingsPrivate
enum  {
  F_Application = 0x0, F_Organization = 0x1, F_User = 0x0, F_System = 0x2,
  NumConfFiles = 4
}
 
enum  ChildSpec { AllKeys, ChildKeys, ChildGroups }
 
- Public Types inherited from QObjectPrivate
typedef void(* StaticMetaCallFunction) (QObject *, QMetaObject::Call, int, void **)
 
- Static Public Functions inherited from QSettingsPrivate
static QSettingsPrivatecreate (QSettings::Format format, QSettings::Scope scope, const QString &organization, const QString &application)
 
static QSettingsPrivatecreate (const QString &fileName, QSettings::Format format)
 
static void iniEscapedKey (const QString &key, QByteArray &result)
 
static void iniEscapedString (const QString &str, QByteArray &result, QTextCodec *codec)
 
static void iniEscapedStringList (const QStringList &strs, QByteArray &result, QTextCodec *codec)
 
static bool iniUnescapedKey (const QByteArray &key, int from, int to, QString &result)
 
static bool iniUnescapedStringList (const QByteArray &str, int from, int to, QString &stringResult, QStringList &stringListResult, QTextCodec *codec)
 
static QString normalizedKey (const QString &key)
 
static void processChild (QString key, ChildSpec spec, QMap< QString, QString > &result)
 
static QStringList splitArgs (const QString &s, int idx)
 
static QVariant stringListToVariantList (const QStringList &l)
 
static QVariant stringToVariant (const QString &s)
 
static QStringList variantListToStringList (const QVariantList &l)
 
static QString variantToString (const QVariant &v)
 
- Static Public Functions inherited from QObjectPrivate
static void clearGuards (QObject *)
 
static QObjectPrivateget (QObject *o)
 
static void resetCurrentSender (QObject *receiver, Sender *currentSender, Sender *previousSender)
 
static SendersetCurrentSender (QObject *receiver, Sender *sender)
 
static void signalSignature (const QMetaMethod &signal, QVarLengthArray< char > *result)
 
- Public Variables inherited from QSettingsPrivate
QString applicationName
 
QSettings::Format format
 
QTextCodeciniCodec
 
QString organizationName
 
QSettings::Scope scope
 
- Public Variables inherited from QObjectPrivate
union {
   QObject *   currentChildBeingDeleted
 
   QAbstractDeclarativeData *   declarativeData
 
}; 
 
quint32 connectedSignals [2]
 
QObjectConnectionListVectorconnectionLists
 
SendercurrentSender
 
QList< QPointer< QObject > > eventFilters
 
ExtraDataextraData
 
QString objectName
 
Connectionsenders
 
QAtomicPointer< QtSharedPointer::ExternalRefCountData > sharedRefcount
 
QThreadDatathreadData
 
void * unused
 
- Public Variables inherited from QObjectData
uint blockSig: 1
 
QObjectList children
 
uint hasGuards: 1
 
uint inEventHandler: 1
 
uint inThreadChangeEvent: 1
 
uint isWidget: 1
 
QMetaObjectmetaObject
 
uint ownObjectName: 1
 
QObjectparent
 
uint pendTimer: 1
 
int postedEvents
 
QObjectq_ptr
 
uint receiveChildEvents: 1
 
uint sendChildEvents: 1
 
uint unused: 22
 
uint wasDeleted: 1
 
- Protected Variables inherited from QSettingsPrivate
bool fallbacks
 
QString groupPrefix
 
QStack< QSettingsGroupgroupStack
 
bool pendingChanges
 
int spec
 
QSettings::Status status
 

Detailed Description

Definition at line 378 of file qsettings_win.cpp.

Constructors and Destructors

◆ QWinSettingsPrivate() [1/2]

QWinSettingsPrivate::QWinSettingsPrivate ( QSettings::Scope  scope,
const QString organization,
const QString application 
)

Definition at line 403 of file qsettings_win.cpp.

Referenced by QSettingsPrivate::create(), and isWritable().

405  : QSettingsPrivate(QSettings::NativeFormat, scope, organization, application)
406 {
407  deleteWriteHandleOnExit = false;
408 
409  if (!organization.isEmpty()) {
410  QString prefix = QLatin1String("Software\\") + organization;
411  QString orgPrefix = prefix + QLatin1String("\\OrganizationDefaults");
412  QString appPrefix = prefix + QLatin1Char('\\') + application;
413 
414  if (scope == QSettings::UserScope) {
415  if (!application.isEmpty())
416  regList.append(RegistryKey(HKEY_CURRENT_USER, appPrefix, !regList.isEmpty()));
417 
418  regList.append(RegistryKey(HKEY_CURRENT_USER, orgPrefix, !regList.isEmpty()));
419  }
420 
421  if (!application.isEmpty())
422  regList.append(RegistryKey(HKEY_LOCAL_MACHINE, appPrefix, !regList.isEmpty()));
423 
424  regList.append(RegistryKey(HKEY_LOCAL_MACHINE, orgPrefix, !regList.isEmpty()));
425  }
426 
427  if (regList.isEmpty())
429 }
void setStatus(QSettings::Status status) const
Definition: qsettings.cpp:410
QSettingsPrivate(QSettings::Format format)
Definition: qsettings.cpp:302
QSettings::Scope scope
Definition: qsettings_p.h:259
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
RegistryKeyList regList
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ QWinSettingsPrivate() [2/2]

QWinSettingsPrivate::QWinSettingsPrivate ( QString  rKey)

Definition at line 431 of file qsettings_win.cpp.

433 {
434  deleteWriteHandleOnExit = false;
435 
436  if (rPath.startsWith(QLatin1String("\\")))
437  rPath = rPath.mid(1);
438 
439  if (rPath.startsWith(QLatin1String("HKEY_CURRENT_USER\\")))
440  regList.append(RegistryKey(HKEY_CURRENT_USER, rPath.mid(18), false));
441  else if (rPath == QLatin1String("HKEY_CURRENT_USER"))
442  regList.append(RegistryKey(HKEY_CURRENT_USER, QString(), false));
443  else if (rPath.startsWith(QLatin1String("HKEY_LOCAL_MACHINE\\")))
444  regList.append(RegistryKey(HKEY_LOCAL_MACHINE, rPath.mid(19), false));
445  else if (rPath == QLatin1String("HKEY_LOCAL_MACHINE"))
446  regList.append(RegistryKey(HKEY_LOCAL_MACHINE, QString(), false));
447  else if (rPath.startsWith(QLatin1String("HKEY_CLASSES_ROOT\\")))
448  regList.append(RegistryKey(HKEY_CLASSES_ROOT, rPath.mid(18), false));
449  else if (rPath == QLatin1String("HKEY_CLASSES_ROOT"))
450  regList.append(RegistryKey(HKEY_CLASSES_ROOT, QString(), false));
451  else if (rPath.startsWith(QLatin1String("HKEY_USERS\\")))
452  regList.append(RegistryKey(HKEY_USERS, rPath.mid(11), false));
453  else if (rPath == QLatin1String(QLatin1String("HKEY_USERS")))
454  regList.append(RegistryKey(HKEY_USERS, QString(), false));
455  else
456  regList.append(RegistryKey(HKEY_LOCAL_MACHINE, rPath, false));
457 }
QSettingsPrivate(QSettings::Format format)
Definition: qsettings.cpp:302
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
RegistryKeyList regList
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654

◆ ~QWinSettingsPrivate()

QWinSettingsPrivate::~QWinSettingsPrivate ( )

Definition at line 568 of file qsettings_win.cpp.

569 {
570  if (deleteWriteHandleOnExit && writeHandle() != 0) {
571 #if defined(Q_OS_WINCE)
572  remove(regList.at(0).key());
573 #else
574  QString emptyKey;
575  DWORD res = RegDeleteKey(writeHandle(), reinterpret_cast<const wchar_t *>(emptyKey.utf16()));
576  if (res != ERROR_SUCCESS) {
577  qWarning("QSettings: Failed to delete key \"%s\": %s",
579  }
580 #endif
581  }
582 
583  for (int i = 0; i < regList.size(); ++i)
584  regList[i].close();
585 }
QString key() const
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
The QString class provides a Unicode character string.
Definition: qstring.h:83
RegistryKeyList regList
HKEY writeHandle() const
static QString errorCodeToString(DWORD errorCode)
Q_CORE_EXPORT void qWarning(const char *,...)
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290

Functions

◆ children()

QStringList QWinSettingsPrivate::children ( const QString uKey,
ChildSpec  spec 
) const
virtual

Implements QSettingsPrivate.

Definition at line 760 of file qsettings_win.cpp.

761 {
762  NameSet result;
763  QString rKey = escapedKey(uKey);
764 
765  for (int i = 0; i < regList.size(); ++i) {
766  HKEY parent_handle = regList.at(i).handle();
767  if (parent_handle == 0)
768  continue;
769  HKEY handle = openKey(parent_handle, KEY_READ, rKey);
770  if (handle == 0)
771  continue;
772 
773  if (spec == AllKeys) {
774  NameSet keys;
775  allKeys(handle, QLatin1String(""), &keys);
776  mergeKeySets(&result, keys);
777  } else { // ChildGroups or ChildKeys
778  QStringList names = childKeysOrGroups(handle, spec);
779  mergeKeySets(&result, names);
780  }
781 
782  RegCloseKey(handle);
783 
784  if (!fallbacks)
785  return result.keys();
786  }
787 
788  return result.keys();
789 }
static void allKeys(HKEY parentHandle, const QString &rSubKey, NameSet *result)
static QStringList childKeysOrGroups(HKEY parentHandle, QSettingsPrivate::ChildSpec spec)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
QStringList keys
RegistryKeyList regList
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
HKEY handle() const
QList< Key > keys() const
Returns a list containing all the keys in the map in ascending order.
Definition: qmap.h:818
static void mergeKeySets(NameSet *dest, const NameSet &src)
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
static HKEY openKey(HKEY parentHandle, REGSAM perms, const QString &rSubKey)
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
static QString escapedKey(QString uKey)

◆ clear()

void QWinSettingsPrivate::clear ( )
virtual

Implements QSettingsPrivate.

Definition at line 791 of file qsettings_win.cpp.

792 {
793  remove(QString());
795 }
The QString class provides a Unicode character string.
Definition: qstring.h:83

◆ fileName()

QString QWinSettingsPrivate::fileName ( ) const
virtual

Implements QSettingsPrivate.

Definition at line 807 of file qsettings_win.cpp.

808 {
809  if (regList.isEmpty())
810  return QString();
811 
812  const RegistryKey &key = regList.at(0);
813  QString result;
814  if (key.parentHandle() == HKEY_CURRENT_USER)
815  result = QLatin1String("\\HKEY_CURRENT_USER\\");
816  else
817  result = QLatin1String("\\HKEY_LOCAL_MACHINE\\");
818 
819  return result + regList.at(0).key();
820 }
QString key() const
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
RegistryKeyList regList
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
int key
HKEY parentHandle() const
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139

◆ flush()

void QWinSettingsPrivate::flush ( )
virtual

Implements QSettingsPrivate.

Definition at line 802 of file qsettings_win.cpp.

803 {
804  // Windows does this for us.
805 }

◆ get()

bool QWinSettingsPrivate::get ( const QString uKey,
QVariant value 
) const
virtual

Implements QSettingsPrivate.

Definition at line 744 of file qsettings_win.cpp.

745 {
746  QString rKey = escapedKey(uKey);
747 
748  for (int i = 0; i < regList.size(); ++i) {
749  HKEY handle = regList.at(i).handle();
750  if (handle != 0 && readKey(handle, rKey, value))
751  return true;
752 
753  if (!fallbacks)
754  return false;
755  }
756 
757  return false;
758 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
RegistryKeyList regList
HKEY handle() const
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
bool readKey(HKEY parentHandle, const QString &rSubKey, QVariant *value) const
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
static QString escapedKey(QString uKey)

◆ isWritable()

bool QWinSettingsPrivate::isWritable ( ) const
virtual

Implements QSettingsPrivate.

Definition at line 822 of file qsettings_win.cpp.

823 {
824  return writeHandle() != 0;
825 }
HKEY writeHandle() const

◆ readKey()

bool QWinSettingsPrivate::readKey ( HKEY  parentHandle,
const QString rSubKey,
QVariant value 
) const

Definition at line 459 of file qsettings_win.cpp.

Referenced by get().

460 {
461  QString rSubkeyName = keyName(rSubKey);
462  QString rSubkeyPath = keyPath(rSubKey);
463 
464  // open a handle on the subkey
465  HKEY handle = openKey(parentHandle, KEY_READ, rSubkeyPath);
466  if (handle == 0)
467  return false;
468 
469  // get the size and type of the value
470  DWORD dataType;
471  DWORD dataSize;
472  LONG res = RegQueryValueEx(handle, reinterpret_cast<const wchar_t *>(rSubkeyName.utf16()), 0, &dataType, 0, &dataSize);
473  if (res != ERROR_SUCCESS) {
474  RegCloseKey(handle);
475  return false;
476  }
477 
478  // get the value
479  QByteArray data(dataSize, 0);
480  res = RegQueryValueEx(handle, reinterpret_cast<const wchar_t *>(rSubkeyName.utf16()), 0, 0,
481  reinterpret_cast<unsigned char*>(data.data()), &dataSize);
482  if (res != ERROR_SUCCESS) {
483  RegCloseKey(handle);
484  return false;
485  }
486 
487  switch (dataType) {
488  case REG_EXPAND_SZ:
489  case REG_SZ: {
490  QString s;
491  if (dataSize) {
492  s = QString::fromWCharArray(((const wchar_t *)data.constData()));
493  }
494  if (value != 0)
495  *value = stringToVariant(s);
496  break;
497  }
498 
499  case REG_MULTI_SZ: {
500  QStringList l;
501  if (dataSize) {
502  int i = 0;
503  for (;;) {
504  QString s = QString::fromWCharArray((const wchar_t *)data.constData() + i);
505  i += s.length() + 1;
506 
507  if (s.isEmpty())
508  break;
509  l.append(s);
510  }
511  }
512  if (value != 0)
513  *value = stringListToVariantList(l);
514  break;
515  }
516 
517  case REG_NONE:
518  case REG_BINARY: {
519  QString s;
520  if (dataSize) {
521  s = QString::fromWCharArray((const wchar_t *)data.constData(), data.size() / 2);
522  }
523  if (value != 0)
524  *value = stringToVariant(s);
525  break;
526  }
527 
528  case REG_DWORD_BIG_ENDIAN:
529  case REG_DWORD: {
530  Q_ASSERT(data.size() == sizeof(int));
531  int i;
532  memcpy((char*)&i, data.constData(), sizeof(int));
533  if (value != 0)
534  *value = i;
535  break;
536  }
537 
538  case REG_QWORD: {
539  Q_ASSERT(data.size() == sizeof(qint64));
540  qint64 i;
541  memcpy((char*)&i, data.constData(), sizeof(qint64));
542  if (value != 0)
543  *value = i;
544  break;
545  }
546 
547  default:
548  qWarning("QSettings: Unknown data %d type in Windows registry", static_cast<int>(dataType));
549  if (value != 0)
550  *value = QVariant();
551  break;
552  }
553 
554  RegCloseKey(handle);
555  return true;
556 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
Definition: qstring.cpp:1019
static QString keyName(const QString &rKey)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
static QString keyPath(const QString &rKey)
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
__int64 qint64
Definition: qglobal.h:942
static QVariant stringListToVariantList(const QStringList &l)
Definition: qsettings.cpp:444
static HKEY openKey(HKEY parentHandle, REGSAM perms, const QString &rSubKey)
QFactoryLoader * l
static QVariant stringToVariant(const QString &s)
Definition: qsettings.cpp:551
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290

◆ remove()

void QWinSettingsPrivate::remove ( const QString uKey)
virtual

Implements QSettingsPrivate.

Definition at line 587 of file qsettings_win.cpp.

588 {
589  if (writeHandle() == 0) {
591  return;
592  }
593 
594  QString rKey = escapedKey(uKey);
595 
596  // try to delete value bar in key foo
597  LONG res;
598  HKEY handle = openKey(writeHandle(), registryPermissions, keyPath(rKey));
599  if (handle != 0) {
600  res = RegDeleteValue(handle, reinterpret_cast<const wchar_t *>(keyName(rKey).utf16()));
601  RegCloseKey(handle);
602  }
603 
604  // try to delete key foo/bar and all subkeys
605  handle = openKey(writeHandle(), registryPermissions, rKey);
606  if (handle != 0) {
607  deleteChildGroups(handle);
608 
609  if (rKey.isEmpty()) {
611 
612  for (int i = 0; i < childKeys.size(); ++i) {
613  QString group = childKeys.at(i);
614 
615  LONG res = RegDeleteValue(handle, reinterpret_cast<const wchar_t *>(group.utf16()));
616  if (res != ERROR_SUCCESS) {
617  qWarning("QSettings: RegDeleteValue failed on subkey \"%s\": %s",
618  group.toLatin1().data(), errorCodeToString(res).toLatin1().data());
619  }
620  }
621  } else {
622 #if defined(Q_OS_WINCE)
623  // For WinCE always Close the handle first.
624  RegCloseKey(handle);
625 #endif
626  res = RegDeleteKey(writeHandle(), reinterpret_cast<const wchar_t *>(rKey.utf16()));
627 
628  if (res != ERROR_SUCCESS) {
629  qWarning("QSettings: RegDeleteKey failed on key \"%s\": %s",
630  rKey.toLatin1().data(), errorCodeToString(res).toLatin1().data());
631  }
632  }
633  RegCloseKey(handle);
634  }
635 }
void setStatus(QSettings::Status status) const
Definition: qsettings.cpp:410
static QString keyName(const QString &rKey)
static QStringList childKeysOrGroups(HKEY parentHandle, QSettingsPrivate::ChildSpec spec)
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
static const REGSAM registryPermissions
static QString keyPath(const QString &rKey)
The QString class provides a Unicode character string.
Definition: qstring.h:83
static void deleteChildGroups(HKEY parentHandle)
HKEY writeHandle() const
static QString errorCodeToString(DWORD errorCode)
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
Q_CORE_EXPORT void qWarning(const char *,...)
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
static HKEY openKey(HKEY parentHandle, REGSAM perms, const QString &rSubKey)
static QString escapedKey(QString uKey)
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290

◆ set()

void QWinSettingsPrivate::set ( const QString uKey,
const QVariant value 
)
virtual

Implements QSettingsPrivate.

Definition at line 646 of file qsettings_win.cpp.

647 {
648  if (writeHandle() == 0) {
650  return;
651  }
652 
653  QString rKey = escapedKey(uKey);
654 
655  HKEY handle = createOrOpenKey(writeHandle(), registryPermissions, keyPath(rKey));
656  if (handle == 0) {
658  return;
659  }
660 
661  DWORD type;
662  QByteArray regValueBuff;
663 
664  // Determine the type
665  switch (value.type()) {
666  case QVariant::List:
667  case QVariant::StringList: {
668  // If none of the elements contains '\0', we can use REG_MULTI_SZ, the
669  // native registry string list type. Otherwise we use REG_BINARY.
670  type = REG_MULTI_SZ;
673  for (; it != l.constEnd(); ++it) {
674  if ((*it).length() == 0 || stringContainsNullChar(*it)) {
675  type = REG_BINARY;
676  break;
677  }
678  }
679 
680  if (type == REG_BINARY) {
681  QString s = variantToString(value);
682  regValueBuff = QByteArray((const char*)s.utf16(), s.length() * 2);
683  } else {
685  for (; it != l.constEnd(); ++it) {
686  const QString &s = *it;
687  regValueBuff += QByteArray((const char*)s.utf16(), (s.length() + 1) * 2);
688  }
689  regValueBuff.append((char)0);
690  regValueBuff.append((char)0);
691  }
692  break;
693  }
694 
695  case QVariant::Int:
696  case QVariant::UInt: {
697  type = REG_DWORD;
698  qint32 i = value.toInt();
699  regValueBuff = QByteArray((const char*)&i, sizeof(qint32));
700  break;
701  }
702 
703  case QVariant::LongLong:
704  case QVariant::ULongLong: {
705  type = REG_QWORD;
706  qint64 i = value.toLongLong();
707  regValueBuff = QByteArray((const char*)&i, sizeof(qint64));
708  break;
709  }
710 
711  case QVariant::ByteArray:
712  // fallthrough intended
713 
714  default: {
715  // If the string does not contain '\0', we can use REG_SZ, the native registry
716  // string type. Otherwise we use REG_BINARY.
717  QString s = variantToString(value);
718  type = stringContainsNullChar(s) ? REG_BINARY : REG_SZ;
719  if (type == REG_BINARY) {
720  regValueBuff = QByteArray((const char*)s.utf16(), s.length() * 2);
721  } else {
722  regValueBuff = QByteArray((const char*)s.utf16(), (s.length() + 1) * 2);
723  }
724  break;
725  }
726  }
727 
728  // set the value
729  LONG res = RegSetValueEx(handle, reinterpret_cast<const wchar_t *>(keyName(rKey).utf16()), 0, type,
730  reinterpret_cast<const unsigned char*>(regValueBuff.constData()),
731  regValueBuff.size());
732 
733  if (res == ERROR_SUCCESS) {
734  deleteWriteHandleOnExit = false;
735  } else {
736  qWarning("QSettings: failed to set subkey \"%s\": %s",
737  rKey.toLatin1().data(), errorCodeToString(res).toLatin1().data());
739  }
740 
741  RegCloseKey(handle);
742 }
void setStatus(QSettings::Status status) const
Definition: qsettings.cpp:410
static QString keyName(const QString &rKey)
int type
Definition: qmetatype.cpp:239
int qint32
Definition: qglobal.h:937
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
static HKEY createOrOpenKey(HKEY parentHandle, REGSAM perms, const QString &rSubKey)
#define it(className, varName)
QByteArray & append(char c)
Appends the character ch to this byte array.
static const REGSAM registryPermissions
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
QList< QVariant > toList() const
Returns the variant as a QVariantList if the variant has type() List or StringList ; otherwise return...
Definition: qvariant.cpp:2751
static QString keyPath(const QString &rKey)
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QStringList variantListToStringList(const QVariantList &l)
Definition: qsettings.cpp:435
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
HKEY writeHandle() const
friend class const_iterator
Definition: qlist.h:264
static QString errorCodeToString(DWORD errorCode)
static bool stringContainsNullChar(const QString &s)
qlonglong toLongLong(bool *ok=0) const
Returns the variant as a long long int if the variant has type() LongLong , Bool , ByteArray , Char , Double , Int , String , UInt , or ULongLong ; otherwise returns 0.
Definition: qvariant.cpp:2659
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
Q_CORE_EXPORT void qWarning(const char *,...)
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
__int64 qint64
Definition: qglobal.h:942
static QString variantToString(const QVariant &v)
Definition: qsettings.cpp:464
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901
QFactoryLoader * l
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272
static QString escapedKey(QString uKey)
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290

◆ sync()

void QWinSettingsPrivate::sync ( )
virtual

Implements QSettingsPrivate.

Definition at line 797 of file qsettings_win.cpp.

798 {
799  RegFlushKey(writeHandle());
800 }
HKEY writeHandle() const

◆ writeHandle()

HKEY QWinSettingsPrivate::writeHandle ( ) const

Definition at line 558 of file qsettings_win.cpp.

Referenced by isWritable(), remove(), set(), sync(), and ~QWinSettingsPrivate().

559 {
560  if (regList.isEmpty())
561  return 0;
562  const RegistryKey &key = regList.at(0);
563  if (key.handle() == 0 || key.readOnly())
564  return 0;
565  return key.handle();
566 }
RegistryKeyList regList
HKEY handle() const
bool readOnly() const
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
int key
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139

Properties

◆ deleteWriteHandleOnExit

bool QWinSettingsPrivate::deleteWriteHandleOnExit
private

Definition at line 400 of file qsettings_win.cpp.

Referenced by clear(), QWinSettingsPrivate(), set(), and ~QWinSettingsPrivate().

◆ regList

RegistryKeyList QWinSettingsPrivate::regList
private

The documentation for this class was generated from the following file: