QT的slot和signal的簡單示例
阿新 • • 發佈:2018-12-19
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include<QPushButton> #include<QLineEdit> namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); private slots: void doTHE(); private: Ui::MainWindow *ui; }; #endif // MAINWINDOW_H #include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QPushButton* btn=ui->pushButton; connect(btn,SIGNAL(clicked()),this,SLOT(doTHE())); } void MainWindow::doTHE(){ ui->lineEdit->setText("hello mt"); } MainWindow::~MainWindow() { delete ui; }