没有这样的插槽按钮 QT [英] No such slot button QT

查看:60
本文介绍了没有这样的插槽按钮 QT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

for(i=0; i<height; i++)
{
    for(j=0; j<width; j++)
    {
        button[i][j] = new QPushButton("Empty", this);
        button[i][j]->resize(40, 40);
        button[i][j]->move(40*j, 40*i);
        connect(button[i][j], SIGNAL(clicked()), this, SLOT(changeText(button[i][j])));
    }
}

如果我用函数(例如全屏)改变了函数 changeText ,它就可以工作但是当我使用我定义的插槽(changeText)时出现此错误,我不知道如何解决

If i changed function changeText with function (fullScreen for example) it works but when i use a slot defined by me (changeText) this Error Appears and i don't know how to solve it

QObject::connect: No such slot buttons::changeText(&button[i][j])

这是函数changeText:

and this is the function changeText:

void buttons::changeText(QPushButton* button)
{
    button->setText("Fish");
}

注意:在头文件中,我像这样定义了插槽:

NOTE: in the header file i defined the slot like this :

类按钮:公共 QWidget

class buttons : public QWidget

    Q_OBJECT
public slots:
    void changeText(QPushButton* button);

推荐答案

如果 SIGNAL 没有提供某个参数,SLOT 将无法接收到它.clicked() 信号不提供任何参数.接收它的插槽也不应该有任何.在任何情况下,您都可以让 SLOT 接收的参数少于 SIGNAL 提供的参数(忽略其他一些),但不是其他情况.但是,您可以了解信号的发送者,将其投射到 QPushButton* 并对其进行处理:

If the SIGNAL doesn't provide certain parameter, the SLOT can't recieve it. The signal clicked() doesn't provide any parameter. SLOTs receiving it shouldn't have any, either. In any case, you can have a SLOT receiving less parameters than the SIGNAL provides (ignoring some others), but not otherwise. You can, however, get to know the sender of the signal, cast it to QPushButton* and work on it:

void buttons::changeText()
{
    QPushButton *pb = qobject_cast<QPushButton *>(sender());
    if (pb){
        pb->setText("fish");
    } else {
        qDebug() << "Couldn't make the conversion properly";
    }
} 

这篇关于没有这样的插槽按钮 QT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆