【问题标题】:C++ & PyQt | User Defined Slot and Connect for QCheckBoxC++ 和 PyQt |用于 QCheckBox 的用户定义插槽和连接
【发布时间】:2014-03-13 20:51:13
【问题描述】:

除了对话框中的复选框之外,我还想实现一个用户定义的插槽,它将发送者对象作为参数传递。

我尝试了以下方法:

插槽:

public slots:
    void updateUI(int, QCheckBox *sender);

连接:

connect(this->allLayersetsCheckBox, SIGNAL(stateChanged(int)), this, SLOT(updateUI(int, QCheckBox*)));
connect(this->selectedLayersetsCheckBox, SIGNAL(stateChanged(int)), this, SLOT(updateUI(int, QCheckBox*)));
connect(this->unselectedLayersetsCheckBox, SIGNAL(stateChanged(int)), this, SLOT(updateUI(int, QCheckBox*)));

方法:

void MyDialog::updateUI(int state, QCheckBox *sender) {
    cout << "updateUI" << endl;
    cout << qPrintable( sender->text() ) << endl;
}

我收到以下错误:

QObject::connect: Incompatible sender/receiver arguments
            QCheckBox::stateChanged(int) --> MyDialog::updateUI(int,QCheckBox*) QObject::connect: Incompatible sender/receiver arguments
            QCheckBox::stateChanged(int) --> MyDialog::updateUI(int,QCheckBox*) QObject::connect: Incompatible sender/receiver arguments
            QCheckBox::stateChanged(int) --> MyDialog::updateUI(int,QCheckBox*)

这不可能吗? 或者如何实现这一点?

我真的很想知道哪个 CheckBox 正在调用 updateUI 方法。 我将不胜感激。

提前致谢!

【问题讨论】:

    标签: c++ pyqt


    【解决方案1】:

    如果你想知道是什么对象发送了信号,那么只需在接收槽中使用QObject::sender。这将为您提供一个 QObject 指针,您可以尝试将其动态转换为适当的类型。

    【讨论】:

      猜你喜欢
      • 2013-01-11
      • 2014-02-10
      • 2010-11-11
      • 2012-07-13
      • 1970-01-01
      • 2016-06-19
      相关资源
      最近更新 更多