当前位置:网站首页>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 :

边栏推荐
- AI首席架构师12-AICA-百度OCR垂类规模化落地实践
- How to make the Internet access the intranet IP (used by esp8266 web pages)
- CH340 RTS DTR引脚编程驱动OLED
- 2022-07-27: Xiao Hong got an array arr with a length of N. she is going to modify it only once. She can modify any number arr[i] in the array to a positive number not greater than P (the modified numb
- 每周推荐短视频:如何正确理解“精益”这个词?
- Play WolframAlpha computing knowledge engine
- An article grasps the calculation and processing of date data in PostgreSQL
- 玩一玩WolframAlpha计算知识引擎
- 12月份PMP考试首次采用新考纲,该怎么学?
- Redis basic operation
猜你喜欢

Daily practice ----- realize the lottery function of two-color ball. Rules: Six non repeating numbers are randomly selected from 36 red balls, and one from 15 basketball is randomly selected to form a

Shell writing specifications and variables

Integrate SSM to realize search of addition, deletion, modification and query

Differences among BRD, MRD and PRD

AIRIOT答疑第6期|如何使用二次开发引擎?
![[5g NR] RRC reject analysis](/img/51/fc39804b39a9014be3130c09e5444c.png)
[5g NR] RRC reject analysis

The latest version of pagoda installs the zip extension, and PHP -m does not display the processing method

Outlook 教程,如何在 Outlook 中使用颜色类别和提醒?

Unity简单实现对话功能

单调栈——42. 接雨水——面大厂必须会的困难题
随机推荐
deepstream 检测结果截图
leetcode刷题:动态规划08(分割等和子集)
Shell: one click deployment PXE
【OPENVX】对象基本使用之vx_distribution
Capacity expansion and reduction of RBD block storage device (VI)
Tensorboard usage record
Server memory failure prediction can actually do this!
Play WolframAlpha computing knowledge engine
Vertical align align the elements in the row are vertically centered
2022-07-27: Xiao Hong got an array arr with a length of N. she is going to modify it only once. She can modify any number arr[i] in the array to a positive number not greater than P (the modified numb
2022 summary of the latest Android handler related interview questions
53. Maximum subarray maximum subarray sum
Super nice PHP program source code of nteam official website
如何让外网访问内网IP(esp8266网页使用)
ES6 从入门到精通 # 08:扩展的对象的功能
TypeError: ufunc ‘bitwise_and‘ not supported for the input types, and the inputs could not be safely
Malloc, free, calloc, realloc dynamic memory development functions in dynamic memory management
Response to questions about the balanced beacon group of Hubei University of Arts and Sciences
"Xiaodeng" network equipment monitoring in operation and maintenance
Digital economy has become the biggest attraction