參考鏈接1:http://blog.csdn.net/skyhawk452/article/details/6121407
參考鏈接2:http://blog.csdn.net/memory_exception/article/details/50953005
信號與槽可以通過使用手寫代碼顯式的實現關聯 ,也可以運用 QMetaObject 類規定的槽 函數命名范式來實現自動關聯。
#include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QString a = "calculate"; setWindowTitle(tr("%1").arg(a)); //connect(ui->calButton,SIGNAL(clicked()),this,SLOT(on_calButton_clicked())); //QMetaObject::connectSlotsByName(this); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_calButton_clicked() { int a = (ui->firstLineEdit->text()).toInt() + (ui->secondLineEdit->text()).toInt(); ui->resultLineEdit->setText(tr("%1").arg(a)); }