This library allows you to perform several Windows Registry operations in Qt.
You can use these functions with QString and other typical Qt data types as arguments.
How to get started:
• Add the 4 files: registryqt.cpp, registryqt.h, regvalue.cpp, regvalue.h to your project.
• #include "registryqt.h"
• LIBS += -lAdvapi32
• Read/Write all types of Registry values: Binary, DWORD, ExpandSZ, MultiSZ, QWORD, SZ.
• Use the Qt data types you know and love: QByteArray, QString, QStringList.
• Easily convert a read value to a Qt data type.
• Delete a Registry key and all of its subkeys.
• Expand both expandable and non-expandable strings!
• Value names are allowed to contain both \ and /.
• Keys are allowed to contain /.
• Keys, value names and values are allowed to contain for instance Japanese or Chinese characters.
• I am not certain that all errors are handled correctly.
• Some functions and variables should probably be renamed. it's looking pretty snazzy now
• Maybe I want a RegOperation struct that contains information on an attempted operation. (probably not)
• Make sure that it compiles and works on Windows XP, Windows 7, Windows 8.1, Windows 10.
• Do so that Expandable String values are easily expanded. done
• More tests?
• I want "keyExists()" and "valueExists()" functions. done
• I want to be able to get a list of all valueNames in a key. done
QString value = "value";
RegistryQt::insertValueSZ( HKEY_LOCAL_MACHINE, "Software\\1337-test", "hello there", value);
RegValue regValue = RegistryQt::getValue( HKEY_LOCAL_MACHINE, "Software\\1337-test", "hello there");
qDebug() << regValue.toString();
Qt prints out: "value" to the console.
QStringList list;
list << "first list item" << "second list item" << "third list item";
RegistryQt::insertValueMultiSZ( HKEY_LOCAL_MACHINE, "Software\\1337-test", "cool, a list", list);
RegValue regValue = RegistryQt::getValue( HKEY_LOCAL_MACHINE, "Software\\1337-test", "cool, a list");
qDebug() << regValue.toStringList();
Qt prints out: ("first list item", "second list item", "third list item") to the console.
QImage img (75,75, QImage::Format_RGBA8888);
img.fill(Qt::red);
QByteArray bytes;
QBuffer buffer(&bytes);
buffer.open(QIODevice::WriteOnly);
img.save(&buffer, "PNG");
RegistryQt::insertValueBinary( HKEY_LOCAL_MACHINE, "Software\\1337-test", "great", bytes);
RegValue value = RegistryQt::getValue( HKEY_LOCAL_MACHINE, "Software\\1337-test", "great");
QByteArray bytes2 = value.toByteArray();
qDebug() << (bytes == bytes2);
bytes2 now contains the data of bytes. So Qt prints out: true.
RegistryQt::insertValueDWORD( HKEY_LOCAL_MACHINE, "Software\\1337-test", "word", 56456);
RegValue regValue = RegistryQt::getValue( HKEY_LOCAL_MACHINE, "Software\\1337-test", "word");
qDebug() << (regValue.type == REG_DWORD);
qDebug() << regValue.toDword();
Qt prints out: true
56456
RegistryQt::insertValueExpandSZ(HKEY_LOCAL_MACHINE, "Software\\1-test", "test", "%windir%");
RegValue value = RegistryQt::value(HKEY_LOCAL_MACHINE, "Software\\1-test", "test");
qDebug() << "expanded:" << value.toExpandedString();
qDebug() << "as string:" << value.toString();
Qt prints out:
expanded: "C:\Windows"
as string: "%windir%"
You could as well store an expandable string in a regular reg_sz, and expand that, but that would defeat the purpose of having the reg_expand_sz type.