目錄
1、創(chuàng)建 Qt 應(yīng)用
?2、項(xiàng)目創(chuàng)建成功
3、直接點(diǎn)擊打開 mainwindow.ui 文件
4、隨便從左邊側(cè)邊欄拖拽一個(gè)空間到 界面設(shè)計(jì)區(qū)域
5、在右側(cè)邊欄右鍵點(diǎn)擊 pushButton 控件,點(diǎn)擊轉(zhuǎn)到槽
6、根據(jù)實(shí)際需要選擇對(duì)應(yīng)的信號(hào),我這里方便演示選擇 clicked()信號(hào),直接點(diǎn)擊 OK
7、自動(dòng)在 mainwindow.h 中定義槽函數(shù)
8、同時(shí)在 mainwindow.cpp中有槽函數(shù)的實(shí)現(xiàn)
9、對(duì) mainwindow.h 中的?void MainWindow::on_pushButton_clicked() 函數(shù)定義自己的操作
10、按照如下操作點(diǎn)擊編譯整個(gè)項(xiàng)目文件,出現(xiàn)如下界面
11、總結(jié)
12、傳統(tǒng)方式實(shí)現(xiàn)信號(hào)槽機(jī)制
1、創(chuàng)建 Qt 應(yīng)用
?
2、項(xiàng)目創(chuàng)建成功
3、直接點(diǎn)擊打開 mainwindow.ui 文件
4、隨便從左邊側(cè)邊欄拖拽一個(gè)空間到 界面設(shè)計(jì)區(qū)域
5、在右側(cè)邊欄右鍵點(diǎn)擊 pushButton 控件,點(diǎn)擊轉(zhuǎn)到槽
6、根據(jù)實(shí)際需要選擇對(duì)應(yīng)的信號(hào),我這里方便演示選擇 clicked()信號(hào),直接點(diǎn)擊 OK
7、自動(dòng)在 mainwindow.h 中定義槽函數(shù)
8、同時(shí)在 mainwindow.cpp中有槽函數(shù)的實(shí)現(xiàn)
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
}
9、對(duì) mainwindow.h 中的?void MainWindow::on_pushButton_clicked() 函數(shù)定義自己的操作
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
qDebug()<<"click the pushButton!";
}
10、按照如下操作點(diǎn)擊編譯整個(gè)項(xiàng)目文件,出現(xiàn)如下界面
點(diǎn)擊 PushButton 按鈕可以實(shí)現(xiàn)打印下面的英語(yǔ)短??!
11、總結(jié)
? ? ? ?上面的操作就是如何使用 ui 資源文件進(jìn)行 Qt 界面設(shè)計(jì),在界面設(shè)計(jì)完成之后,為了方便實(shí)現(xiàn)整個(gè)界面的互操性,必須實(shí)現(xiàn) 信號(hào)槽的定義,上面的 5、6、7、8、9、10都是實(shí)現(xiàn)信號(hào)槽的操作步驟,相比較于使用傳統(tǒng)方式實(shí)現(xiàn) Qt 中的信號(hào)槽機(jī)制,這種使用 ui 資源文件的方式無(wú)疑更快、更方便!文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-443942.html
12、傳統(tǒng)方式實(shí)現(xiàn)信號(hào)槽機(jī)制
點(diǎn)擊跳轉(zhuǎn)到傳統(tǒng)方式實(shí)現(xiàn)信號(hào)槽機(jī)制文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-443942.html
到了這里,關(guān)于qt中使用 ui 文件進(jìn)行界面設(shè)計(jì)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!