Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Unresolved External Symbol - GetRegValueA()
Core2 last edited by Core2
I get a unresolved externals error when I have this function in my code. I am including windows.h
As I'm typing the name of the function, the function name pops up in a list to autocomplete for me.
What am I forgetting here?
const char* key = "Software\\blah\\Foo"; const char& subkey = "bar"; RegGetValueA(HKEY_LOCAL_MACHINE, key, subkey, RRF_RT_REG_SZ, NULL, (PVOID)&RegValue, &BufferSize);
Through searching for a solution I see people are using some Qsettings class. I'd prefer to use the RegGetValueA because that is what I have used in pure C++ in the past. I hope I'm not locked into using the QSettings class. But in the end whatever it takes to get this working will be what I use.
EDIT: maybe of importance, I'm compiling for release. In the past I had troubles after compiling for debug, and switched to release. I had to add "C:\Qt\5.9.1\msvc2013_64\include\QtNetwork"
to the "Tools->Options->C++->FileNaming->Search Paths" so all the includes in my code could be found.
JonB last edited by JonB
I don't really understand. Above is pure Windows code, so nothing to do with Qt? So you'd need to link against standard Windows libs for where
RegGetValueAis defined (
Up to you, but the point of using Qt is often to use Qt approaches like
QSettingsrather than native Windows ones. The whole idea of having
#include <windows.h>in your code is strange.
Core2 last edited by
Thanks for the quick response. I'm new to using QT so any advice is helpful.
If i didn't have the "#include <windows.h>" in my code I would get errors like:
C2065: 'DWORD' : undeclared identifier
C2065: 'BufferSize' : undeclared identifier
C2065: 'HKEY_LOCAL_MACHINE' : undeclared identifier'
Maybe off topic but I began using QT because i needed to develop GUI quickly. (Serious) What is the point of using Qt approaches if you could use c++ approaches? Why did they reinvent the wheel? Am I missing the point?
JonB last edited by
But the point is you shouldn't be using
RegGetValueAetc. etc. in the first place, that's what I meant. If you use Qt instead of Windows calls, you won't need them.
Don't confuse Qt with C++. What you called earlier:
I'd prefer to use the RegGetValueA because that is what I have used in pure C++ in the past
is no more "pure C++" than using Qt calls. C++ is a language. Qt is not. It's an SDK (toolkit). Just as you use a Windows toolkit to get
Qt offers a lot of things, just as a native Windows toolkit does, but differently. For one it is cross-platform, which Windows code is not, though you may or may not care about that. As for which to use "to develop GUI quickly", that's up to you. You could use Visual Studio + Microsoft libraries instead of, say, Qt Creator + Qt libraries. Horses for courses.
Uncle_Masta last edited by
@Core2 RegGetValueA is not pure C++ (as indicated by windows.h).
Stick with Qt's API. I'm even surprised Qt knows where that header is. Once you link with the dll that exports RegGetValueA, you'll probably have a whole bunch of other symbols that are required by that dll. And further down, some stuff may not play well with Qt.
Paul Colby last edited by
Again, avoid whenever possible, but in this case, if you need to use
RegGetValueA(maybe you're porting existing code one function at a time, for example), then include
<Windows.h>, and then add to your
win32:LIBS += -ladvapi32
Of course, this is not portable - will only work on Windows. But it is perfectly valid (on Windows), using both MS's compiler, and MinGW.
Also note, that since you're using
RegGetValueAexplicitly (and not
RegGetValueW), your code doesn't support Unicode. You can make it support Unicode with a little extra work, but another good reason to just use Qt's APIs instead ;)
Core2 last edited by
Thank you! I appreciate the advice.
Adding the win32:LIBS += -ladvapi32 to the .pro file fixed my issue.
Now that I have it fixed I can spend some time studying the QSettings API.