[英]View QObject's objectName in Visual Studio Debugger
Unfortunately QObject
has nothing like a QString
m_objectName
member visible in the debugger as one might expect.不幸的是,
QObject
没有像人们预期的那样在调试器中可见的QString
m_objectName
成员。 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?
有什么方法可以在运行时从 Visual Studio 调试器中查看 objectName 吗?
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.在调试 Qt 应用程序时,可能有许多特定 QObject 的实例,并且很难知道哪个实例触发了崩溃,因为该信息可能在调用堆栈中不可用。 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.
然而,如果它们都被赋予了唯一的 objectNames,那么理论上可以让人们快速查明有问题的代码区域。
More Details:更多细节:
qt5.natvis
for Visual Studio (and it doesn't do this for you)qt5.natvis
(它不会为你做这个)QObject
derived variable with an objectName, in order to display its objectName.QObject
派生变量与 objectName 的调试器的工作 watch-expression,以显示其 objectName。qt5.natvis
which prominently exposes objectName for any local QObject
derived variables.qt5.natvis
,它突出显示任何本地QObject
派生变量的 objectName。 Debugger can't (shouldn't?) call object's member function for display purposes, as it can have side effects.调试器不能(不应该?)出于显示目的调用对象的成员 function,因为它可能有副作用。
The solution is to write or find "native visualizer" ( natvis
) for the types you are interested in.解决方案是为您感兴趣的类型编写或查找“原生可视化工具”(
natvis
)。
Luckily, Qt people did this: https://wiki.qt.io/IDE_Debug_Helpers .幸运的是,Qt 人这样做了: https://wiki.qt.io/IDE_Debug_Helpers 。
You may be able to do a better custom job following this doc: https://learn.microsoft.com/en-us/visualstudio/debugger/create-custom-views-of-native-objects?view=vs-2019您可以按照此文档做更好的自定义工作: https://learn.microsoft.com/en-us/visualstudio/debugger/create-custom-views-of-native-objects?view=vs-2019
This may point to the data member name (from qobject.cpp
):这可能指向数据成员名称(来自
qobject.cpp
):
QString QObject::objectName() const
{
Q_D(const QObject);
return d->extraData ? d->extraData->objectName : QString();
}
Assuming Debug build ( Qt5Cored.dll
), add a variable watch as follows:假设调试构建(
Qt5Cored.dll
),添加一个变量 watch 如下:
((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 inspectmyQtObj
”更改为您希望检查的相关QObject*
(或派生的 class 扩展QObject
)的局部变量名称I 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.为了开发人员的方便,我将把如何将其添加到
qt5.natvis
作为未来的练习,或者其他回答者可能希望提供该信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.