当前位置:网站首页>Qt:qmessagebox message box, custom signal and slot
Qt:qmessagebox message box, custom signal and slot
2022-07-28 03:40:00 【@Bu Xiangwan spicy】
One 、QMessageBox Message box
#include "widget.h"
#include <QApplication>
#include <QMessageBox>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
// QMessageBox::information(&w," Tips "," Make nucleic acid ");
// QMessageBox::StandardButton ret = QMessageBox::question(&w," Tips "," Have you made nucleic acid ");
// if(ret == QMessageBox::Yes)
// {
// QMessageBox::information(&w," Tips "," That's great ");
// }
// else
// {
// QMessageBox::critical(&w," Tips "," Go and do it ");
// }
//
//
QMessageBox mb(QMessageBox::NoIcon," Tips "," Click ",QMessageBox::Yes|QMessageBox::No,&w);
// QMessageBox mb;
//
// mb.setWindowTitle(" Tips ");
// mb.setText(" Click ");
//
// mb.addButton(" Tips ",QMessageBox::AcceptRole);
// mb.addButton(" error ",QMessageBox::Cancel);
w.show();
int ret = mb.exec();
if(ret == QMessageBox::AcceptRole)
{
QMessageBox::information(&w," Tips "," That's great ");
}
else
{
QMessageBox::critical(&w," Tips "," Go and do it ");
}
return a.exec();
}Two 、 Custom signals and slots
1. Parameters of removing slots
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = nullptr);
~Widget();
public slots:
void MySlot();
private slots:
void on_pushButton_clicked();
private:
Ui::Widget *ui;
};
#endif // WIDGET_H#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
QObject::connect(ui->pushButton,&QPushButton::clicked,this,&Widget::MySlot);
}
Widget::~Widget()
{
delete ui;
}
void Widget::MySlot()
{
ui->label->setText(" Big xx");
}
2. Small examples
#include "student.h"
Student::Student(QObject *parent) : QObject(parent)
{
}
void Student::Treat()
{
QMessageBox::information(nullptr," Tips "," Dinner ");
}
#include "teacher.h"
Teacher::Teacher(QObject *parent) : QObject(parent)
{
}
void Teacher::ClassOver()
{
QMessageBox::information(nullptr," Tips "," i am hungry , Class is over ");
emit Hungry();
}
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
pTe = new Teacher;
pSt = new Student;
QObject::connect(ui->pushButton,&QPushButton::clicked,pTe,&Teacher::ClassOver);
QObject::connect(pTe,&Teacher::Hungry,pSt,&Student::Treat);
}
Widget::~Widget()
{
delete ui;
delete pTe;
delete pSt;
}
Output :

边栏推荐
- Response to questions about the balanced beacon group of Hubei University of Arts and Sciences
- 动态规划——63. 不同路径 II
- 如何让外网访问内网IP(esp8266网页使用)
- BRD,MRD,PRD的区别
- CH340 RTS DTR引脚编程驱动OLED
- 每周推荐短视频:如何正确理解“精益”这个词?
- [wrong question]
- Push chart written by helm to harbor warehouse
- Capacity expansion and reduction of RBD block storage device (VI)
- After reading MySQL database advanced practice (SQL xiaoxuzhu)
猜你喜欢

20220726汇承科技的蓝牙模块HC-05的AT命令测试

Weekly recommended short video: how to correctly understand the word "lean"?

LabVIEW loads and uses custom symbols in tree control projects
![[force deduction] 1337. Row K with the weakest combat effectiveness in the matrix](/img/6c/b5fd3350886fd74557439f5361e7f8.png)
[force deduction] 1337. Row K with the weakest combat effectiveness in the matrix

How to arrange PCB screen printing? Please check this manual!

20220726 at command test of Bluetooth module hc-05 of Huicheng Technology

如何让外网访问内网IP(esp8266网页使用)

8000 word explanation of OBSA principle and application practice

Leetcode skimming: dynamic programming 08 (segmentation and subsets)

Redis basic operation
随机推荐
Super nice PHP program source code of nteam official website
玩一玩WolframAlpha计算知识引擎
每日练习------实现双色球的彩票功能。规则:从36个红球中随机选择不重复的6个数,从15个篮球中随机选择1个组成一注彩票。可以选择买多注。
Weekly recommended short video: how to correctly understand the word "lean"?
⽇志分析⼯具(Splunk)
ES6 从入门到精通 # 08:扩展的对象的功能
数据丰富的计算:M.2在边缘遇到AI
Outlook 教程,如何在 Outlook 中使用颜色类别和提醒?
单调栈——739. 每日温度
Prefix-Tuning: Optimizing Continuous Prompts for Generation
695. Maximum area of the island
Responsive high-end website template source code Gallery material resource download platform source code
动态规划——509. 斐波那契数
Robot development -- lead screw and guide rail
How to solve the problem of win11 black desktop background?
D2DEngine食用教程(4)———绘制文本
An article grasps the calculation and processing of date data in PostgreSQL
Airiot Q & A issue 6 | how to use the secondary development engine?
Push chart written by helm to harbor warehouse
Collection | 0 basic open source data visualization platform flyfish large screen development guide