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();
}
相关推荐
索迪迈科技5 分钟前
STL库——map/set(类函数学习)
开发语言·c++·学习
ForteScarlet27 分钟前
Kotlin 2.2.20 现已发布!下个版本的特性抢先看!
android·开发语言·kotlin·jetbrains
anlogic36 分钟前
Java基础 9.10
java·开发语言·算法
yongche_shi40 分钟前
第二篇:Python“装包”与“拆包”的艺术:可迭代对象、迭代器、生成器
开发语言·python·面试·面试宝典·生成器·拆包·装包
Elastic 中国社区官方博客1 小时前
介绍 Python Elasticsearch Client 的 ES|QL 查询构建器
大数据·开发语言·数据库·python·elasticsearch·搜索引擎·全文检索
Hóng xīng qiáo1 小时前
swVBA自学笔记014、Lisp适合对SolidWorks进行二次开发吗 ?
开发语言·笔记·lisp
带鱼吃猫1 小时前
C++的诗行:一文读懂C++的继承机制
开发语言·c++·学习·visual studio
好多172 小时前
《Java中的IO流》
java·开发语言·php
MetaverseMan2 小时前
Golang单例模式和工厂模式详解
开发语言·golang·适配器模式
杏花春雨江南2 小时前
Spring Cloud Gateway 作为一个独立的服务进行部署吗
java·开发语言