【问题标题】:QtCreator debug helpers "hello world"QtCreator 调试助手“hello world”
【发布时间】:2020-04-04 19:20:56
【问题描述】:

我正在尝试开始使用debug helpers in QtCreator

但我什至无法得到任何简单的工作。

我制作了这个简单的python文件:

from dumper import *

def qdump_TestClass(d, value):
    d.putNumChild(0)
    d.putValue("hi")

然后在此处添加该文件:

这是类的 C++ 定义:

struct TestClass {
    int x, y;
};

我一直按照this other question 中的步骤进行操作。但这对我不起作用。

【问题讨论】:

    标签: c++ qt-creator


    【解决方案1】:

    在函数名中使用双下划线:

    def qdump__TestClass(d, value):
             ^^
    

    并且,根据文档更正您的路径:

    ~/<Qt>/Tools/QtCreator/share/qtcreator/debugger/personaltypes.py
    

    使用您的 Qt 文件夹名称(或路径,如果它不在 ~)。

    该对话框中显示的路径是相对于您的app

    这是一个完整的工作示例:

    ma​​in.cpp

    struct TestClass
    {
        int x {12}, y {34};
    };
    
    int main()
    {
        TestClass t;
        (void) t;
        return 0;
    }
    

    personaltypes.py

    from dumper import *
    
    def qdump__TestClass(d, value):
        d.putValue("TestClass")
        d.putNumChild(2)
        if d.isExpanded():
            with Children(d):
                d.putSubItem("x", value["x"])
                d.putSubItem("y", value["y"])
    

    截图:

    【讨论】:

    • 感谢您的回答。你是什​​么意思“对我的应用来说是真实的”?我的Qt安装在“/opt/Qt”目录下,对话框中的路径是相对于那个目录的吗?我的用户目录中不能有文件吗?
    • @tuket:不客气!我的意思是您需要使用标准 Qt 路径来编辑 personaltypes.py 文件,因为相关的 Python 文件例如dumper.py 在那里。您可以检查自己的安装路径。我考虑了一个自定义路径,但还没有测试它。您可以在使用时自行检查,例如通过添加到PATH
    • 是的,就是这样,我需要在安装路径中编辑personaltypes.py。我不确定如何添加自定义路径,但我认为我现在可以使用此设置。谢谢!
    猜你喜欢
    • 2013-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-25
    • 1970-01-01
    • 1970-01-01
    • 2022-01-22
    • 1970-01-01
    相关资源
    最近更新 更多