Qt 1. 按键QPushButton和文本框QTextEdit

cpp 复制代码
//ex2.cpp
#include "ex2.h"
#include "ui_ex2.h"

int static cnt = 0;

Ex2::Ex2(QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::Ex2)
{
    ui->setupUi(this);
}

Ex2::~Ex2()
{
    delete ui;
}


void Ex2::on_pushButtonMy1_clicked()
{
    cnt ++;
    QString str = QString::number(cnt,10);
    ui->textEditMy1->setText(str);
}

void Ex2::on_pushButtonMy2_clicked()
{
    if(cnt > 0) cnt --;
    QString str = QString::number(cnt,10);
    ui->textEditMy1->setText(str);
}

//main.cpp
#include "ex2.h"
#include <QtSerialPort/QtSerialPort>
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Ex2 w;
    w.show();
    return a.exec();
}
相关推荐
笨笨马甲几秒前
Qt Http Server模块功能及架构
qt·http·架构
豆豆(设计前端)4 分钟前
在 JavaScript 中,你可以使用 Date 对象来获取 当前日期 和 当前时间、当前年份。
开发语言·javascript·ecmascript
freyazzr28 分钟前
TCP/IP 网络编程 | Reactor事件处理模式
开发语言·网络·c++·网络协议·tcp/ip
电院工程师35 分钟前
SM3算法Python实现(无第三方库)
开发语言·python·算法·安全·密码学
YuTaoShao42 分钟前
Java八股文——MySQL「存储引擎篇」
java·开发语言·mysql
AI风老师44 分钟前
通信网络基础概念
开发语言·网络·php
王德博客1 小时前
【Java课堂笔记】Java 入门基础语法与面向对象三大特性详解
java·开发语言
wkj0011 小时前
接口实现类向上转型和向上转型解析
java·开发语言·c#
寒士obj2 小时前
类加载的过程
java·开发语言
无名之逆2 小时前
大三自学笔记:探索Hyperlane框架的心路历程
java·开发语言·前端·spring boot·后端·rust·编程