来自 QObject::connect 的详细信息
有没有办法在发生故障时从 QObjet::connect 获取详细的故障信息?
返回的布尔值不提供有关失败原因的任何信息。
我希望异常在 C++ 中能够像在 Java 中一样广泛使用。
Is there a way to get a detailed failure information from QObjet::connect
in case of its failure?
Returned boolean value doesn't give any information about reason of failure.
I wish exception were so widely used in C++ as they are in Java.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
除了其他答案之外,您还可以安装自己的函数来调用 Qt 调试、警告或致命消息。 我们的程序有这个,对于调试版本,我们会弹出一个对话框,详细说明问题(如果它是警告或致命消息)。 我相信大多数错过的插槽连接都会显示为警告消息,其中详细说明了它尝试连接的内容。 很多时候,我查看它显示的内容,发现它与我想象的连接有点不同。
In addition to the other answers, you can install your own function that is called for Qt debug, warning, or fatal messages. Our program has this, and for debug builds, we pop up a dialog detailing the problem if it is a warning or fatal message. I believe most of the missed slot connections appear as warning messages, which details what it is trying to connect. Many times, I look at what it shows and it is a bit different than what I thought I was connecting.
正如 OregonGhost 所说,您必须在运行时检查输出才能查看有关连接失败的更多信息。
为了确保 Qt 在运行时显示的信息有帮助,请确保为 QObject 指定一个不同的名称 (QObject::setObjectName())。
As OregonGhost said, you'll have to check the output during runtime to see more informations about a connect failure.
To make sure the information displayed by Qt during runtime is helpful, ensure your give your QObjects a distinct name (QObject::setObjectName()).
如果我没记错的话,调试版本将向调试器输出更详细的错误消息。 不止一次帮助我修复错误。
If I remember correctly, the debug build will output a more detailled error message to the debugger. Helped me more than once to fix a bug.