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();
}
相关推荐
iiiiyu14 分钟前
常用API(SimpleDateFormat类 & Calendar类 & JDK8日期 时间 日期时间 & JDK8日期(时区) )
java·大数据·开发语言·数据结构·编程语言
故事和你9116 分钟前
洛谷-数据结构1-4-图的基本应用2
开发语言·数据结构·算法·深度优先·动态规划·图论
qq_120840937125 分钟前
Three.js 工程向:Clock、deltaTime 与固定步长主循环
开发语言·javascript·ecmascript
小菜同学爱学习27 分钟前
夯实基础!MySQL数据类型进阶、约束详解与报错排查
开发语言·数据库·sql·mysql
源码站~38 分钟前
基于机器学习的社交媒体舆情分析系统
开发语言·python
jieyucx1 小时前
Go 语言零基础入门:编写第一个 Hello World 程序
开发语言·后端·golang
沐知全栈开发1 小时前
Rust 数据类型
开发语言
jieyucx1 小时前
Go 语言基础语法:变量、常量与数据类型详解
开发语言·后端·golang
光影少年1 小时前
Python+LangGraph学习路线及发展前景
开发语言·人工智能·python·学习
NOCSAH1 小时前
统好AI:Java技术生态下的智能知识管理新选择
java·开发语言·人工智能