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();
}
相关推荐
C+++Python15 分钟前
C++类型判断
开发语言·c++
黎雁·泠崖23 分钟前
整数的N进制字符串表示【递归+循环双版满分实现】
c语言·开发语言
张张努力变强28 分钟前
C++类和对象(一):inline函数、nullptr、类的定义深度解析
开发语言·前端·jvm·数据结构·c++·算法
独自破碎E29 分钟前
Java的CMS垃圾回收流程
java·开发语言
oioihoii35 分钟前
C++线程编程模型演进:从Pthread到jthread的技术革命
java·开发语言·c++
2501_9413220339 分钟前
道路检测新突破:Cascade R-CNN在COCO数据集上的实战应用详解
开发语言·r语言·cnn
且去填词1 小时前
深入理解 GMP 模型:Go 高并发的基石
开发语言·后端·学习·算法·面试·golang·go
哪有时间简史1 小时前
Python程序设计基础
开发语言·python
zh_xuan1 小时前
kotlin对集合数据的操作
开发语言·kotlin
a程序小傲1 小时前
京东Java面试被问:多活数据中心的流量调度和数据同步
java·开发语言·面试·职场和发展·golang·边缘计算