Unfortunately QObject has nothing like a QString m_objectName member visible in the debugger as one might expect. Instead, all of the implementation data is hidden behind opaque pointers. Is there any way to view the objectName at runtime from within the Visual Studio debugger?
Background:
When debugging a Qt Application, there may be many instances of a particular QObject and it can be difficult to know which one triggered a crash, since that information may not available in the call stack. However in the case where they have all been given unique objectNames, that could in theory allow one to quickly pinpoint the problematic code area.
More Details:
qt5.natvis for Visual Studio (and it doesn't do this for you)QObject derived variable with an objectName, in order to display its objectName.qt5.natvis which prominently exposes objectName for any local QObject derived variables.Assuming Debug build (Qt5Cored.dll), add a variable watch as follows:
((Qt5Cored.dll!QObjectPrivate*)myQtObj->d_ptr.d)->extraData->objectName
myQtObj" to the local variable name of the relevant QObject* (or derived class extending QObject) that you wish to inspectI will leave how to add this to qt5.natvis for developer convenience as a future exercise, or another answerer may wish to contribute that information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With