先假设你点击button会输出12345
class ourbutton : public QPushButton
{
Q_OBJECT
public:
ourbutton(QWidget *parent = 0) : QPushButton(parent)
{
connect(this, SIGNAL(clicked()),
this, SLOT(getText()))
}
signals:
void sendText(const QString &text)
private slots:
void getText() { emit sendText(tr("12345")) }
}
QLineEdit *edit = new QLineEdit()
ourbutton *button = new ourbutton()
connect(button, SIGNAL(sendText(const QString &text)),
)
要将button的信号事件和对应的槽函数连接起来:用这句QObject::connect( button, SIGNAL(clicked()), textedit, SLOT(on_button_clicked()) )
其中button的类申明内要加信号函数clicked的申明,要用signals关键字,处理该事件的类(你这边应该是计算器类吧)内申明on_button_clicked()
显示的 *** 作在 on_button_clicked()内处理。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)