windows 如何在调试期间查看 Qt 对象的内容?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1597022/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I see the contents of Qt objects during debugging?
提问by Macke
Many Qt classes uses pimpl, so they're very opaque to VS's debugger.
许多 Qt 类使用 pimpl,因此它们对 VS 的调试器非常不透明。
This is bothersome when I want to check some internal Qt state to see if my code is doing it wrong or if I'm having wrong expectations of how things stand.
当我想检查一些内部 Qt 状态以查看我的代码是否做错了或者我对事情的现状有错误的期望时,这很麻烦。
I'm using the Qt VS add-in (1.1.0), but that doesn't seem to help.
我正在使用 Qt VS 插件 (1.1.0),但这似乎没有帮助。
Any ideas?
有任何想法吗?
Update
更新
My autoexp.dat file is filled with Qt stuff, but I'm still not able to look inside the heavier classes (QWidget, QTcpSocket, etc).
我的 autoexp.dat 文件充满了 Qt 的东西,但我仍然无法查看更重的类(QWidget、QTcpSocket 等)。
I can see the simpler classes contents, so the autoexp.dat below seems to be working, but trying to look inside a QWidget doesn't work.
我可以看到更简单的类内容,所以下面的 autoexp.dat 似乎正在运行,但尝试查看 QWidget 内部不起作用。
Update 2
更新 2
For some reason, after reading comments and looking more, it does work, and I can see the data stuff.
出于某种原因,在阅读评论并查看更多之后,它确实有效,并且我可以看到数据内容。
I don't know what happened in the mean time (when I just worked and ignored it), but I did have problems seeing the data before.
我不知道同时发生了什么(当我刚刚工作并忽略它时),但我之前看到数据确实有问题。
I'm accepting the "just works" answer, because I can't delete a bountied question and that's the closest answer available. (The autoexp-dat just pretty-formats the debug lines, using data that's already visible if one digs down)
我接受“正常工作”的答案,因为我无法删除一个有问题的问题,而这是最接近的答案。(autoexp-dat 只是对调试行进行了漂亮的格式化,使用如果深入挖掘就已经可见的数据)
采纳答案by berkus
It's definitely possible to look into the pimpl when Qt is compiled with debugging information. Not sure about VS, but with gdb it Just Works?.
当使用调试信息编译 Qt 时,绝对可以查看 pimpl。不确定 VS,但使用 gdb 可以吗?
回答by Martin Beckett
This might help http://daniel-albuschat.blogspot.com/2008/02/qt-debugging-with-visual-studio-2005.html
这可能会有所帮助http://daniel-albuschat.blogspot.com/2008/02/qt-debugging-with-visual-studio-2005.html
IIRC the install of Qt for Windows includes an autoexp.dat file -
Correction, it's part of the the qt-vs-addin
IIRC Qt for Windows 安装包括一个 autoexp.dat 文件 -
更正,它是qt-vs-addin 的一部分
回答by Thomi
You need to add custom dumpers for your debugger.
您需要为调试器添加自定义转储程序。
There are pre-built ones for GDB. You may have to roll your own for other debuggers, although for visual studio it's possible to get some decent results pretty easily by tweaking the autoexp.dat
file. There are plenty of resources online for how to change this file.
GDB 有预构建的。您可能需要为其他调试器推出自己的调试器,但对于 Visual Studio,通过调整autoexp.dat
文件可以很容易地获得一些不错的结果。网上有很多关于如何更改此文件的资源。
回答by larsmoa
Editing autoexp.dat is an option. See http://eecs.vanderbilt.edu/research/hmtl/wiki/pmwiki.php?n=Knowledge.Qtfor a set of visualizers.
编辑 autoexp.dat 是一个选项。有关一组可视化工具,请参阅http://eecs.vanderbilt.edu/research/hmtl/wiki/pmwiki.php?n=Knowledge.Qt。
回答by Gyuri
It seems like you might be out of luck.
看起来你可能不走运。
Currently this page has the most complete list of macros for QT wariables that can be added to the autoexp.dat: QT with Visual Studio 2008 (updated for Qt 4.5.2)
目前这个页面有最完整的 QT 可扩展宏列表,可以添加到 autoexp.dat: QT with Visual Studio 2008(针对 Qt 4.5.2 更新)
ActiveQtalso sounds promising, but it might be a bit of an overkill for you.
ActiveQt听起来也很有前途,但对您来说可能有点矫枉过正。
Beyond this, you would have to roll your own expressions, or maybe write a Visual Studio Debugger Visualizer. (more about that is on CodeProjector MSDN)
除此之外,您将不得不推出自己的表达式,或者编写一个 Visual Studio Debugger Visualizer。(更多关于CodeProject或MSDN 的信息)
Since there is nothing like that out there, it might be a good opportunity for development from scratch. :)
既然没有这样的东西,那可能是一个从头开始发展的好机会。:)