I tried to open registry and modify it. This is how I open the registry:
HKEY hKey;
LPCTSTR subKey = TEXT("a registry subkey to be opened");
RegOpenKeyEx(HKEY_LOCAL_MACHINE, subKey, 0, KEY_ALL_ACCESS , &hKey);
But here is a problem, I want to use a QString
to change the subkey pragmatically. And put the QString
like this:
QString subKeyString = QString("%1").arg(subKeyName);
LPCTSTR subKey = TEXT(subKeyString); //but it's not working here
I thought it's because I did not change the QString
to LPCTSTR
, I tried this solution, but still I can't figure out a way to put a custom QString
into the TEXT
macro. I am not quite sure the WinApi under the hood, I just tried what I could possibly do.
Is there a way I can fix this problem?
Edit:
Here is how I convert QString
to LPCTSTR
:
QString testString = "converting QString to LPCSTR";
QByteArray testStringArr = testString.toLocal8Bit();
LPCSTR lp = LPCSTR(testStringArr.constData()); //the QString is converted to LPCTSTR
//but when I put the LPCSTR to the TEXT macro, the error is still there, like the next line below will not complie
LPCSTR lp = TEXT(LPCSTR(testStringArr.constData())); //This line will not work