gpt4 book ai didi

c++ - 信号/槽连接总数?

转载 作者:行者123 更新时间:2023-11-30 05:38:02 25 4
gpt4 key购买 nike

有没有一种方法可以找到 Qt 应用程序中信号/槽连接的总数有人向我推荐 Gamma 射线,但有没有更简单的解决方案?

最佳答案

检查 Qt::UniqueConnection .

This is a flag that can be combined with any one of the above connection types, using a bitwise OR. When Qt::UniqueConnection is set, QObject::connect() will fail if the connection already exists (i.e. if the same signal is already connected to the same slot for the same pair of objects). [...]

然后在连接已经存在的情况下使用断言,这将使您的程序崩溃并指示编程错误:

QLabel *label = new QLabel;
QLineEdit *lineEdit = new QLineEdit;
auto ok = QObject::connect(lineEdit, &QLineEdit::textChanged,
label, &QLabel::setText,
Qt::UniqueConnection);
Q_ASSERT(ok);

免责声明:未经测试。

关于c++ - 信号/槽连接总数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32977420/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com