如何在一个插槽或更多个插槽上连接多个信号,我的代码有什么问题?

时间:2019-07-08 06:25:03

标签: qt signals-slots

我使用QT-Creator 5.12.3,并且使用了用于终端的designertool的触摸键盘。在键盘上,我有57个按钮,1个工具按钮和56个按钮。我想我已经准备好了,但是将按钮连接到插槽时出现错误,所以请告诉我我做错了什么。我已经读过https://doc.qt.io/archives/qq/qq10-signalmapper.html,但是找不到错误。

插槽tastatur.cpp:

void Tastatur::pushButton_clicked()
{

QObject *senderObj = QObject::sender();
QString senderName = senderObj->objectName();

// The name of all buttons is toolbuttonxx or pushbuttonxx the xx stay for 
// a number(11-69), i cut the toolbutton or pushbutton away that i have only 
// the number xx 
QString subString = senderName.mid(10, 2);
int buttonnummer = subString.toInt();
switch(buttonnummer)
{
    case 11:
        if(shift == 0)
            shift = 1;
        else
            shift = 0;
        break;
    case 12:
        text = text + "\"";   //text is a global string variable
        break;
     ...
    case 66://Exit
        this->reject();
        break;
    case 67://Del;
        text.chop(1);
        break;
    case 68://Enter
        this->accept();
        emit enterButtonTastaturClick();
        break;
    }
}

初始化按钮并连接

Tastatur::Tastatur(QWidget *parent) : QDialog(parent), ui(new Ui::Tastatur)
{
ui->setupUi(this);
ui->setupUi(this);
QToolButton toolbutton11;
QPushButton pushbutton12, pushbutton13, ... , pushbutton69;

connect(toolbutton11, SIGNAL(clicked()), this, SLOT(button_clicked)); //Error no matching member function for call to connect
connect(pushbutton12, SIGNAL(clicked()), this, SLOT(button_clicked)); //Error no matching member function for call to connect
...
connect(pushbutton69, SIGNAL(clicked()), this, SLOT(button_clicked)); //Error no matching member function for call to connect
}

编辑:更好地构造问题并完成代码

0 个答案:

没有答案