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();
}
相关推荐
R-G-B1 天前
【02】C#入门到精通——C# 变量、输入/输出、类型转换
开发语言·c#·c# 变量·c#输入/输出·c#类型转换
星河队长1 天前
C# 软件加密方法,有使用时间限制,同时要防止拷贝
开发语言·c#
史迪奇_xxx1 天前
10、一个简易 vector:C++ 模板与 STL
java·开发语言·c++
2301_801252221 天前
Java中的反射
java·开发语言
Kiri霧1 天前
Rust开发环境搭建
开发语言·后端·rust
weixin-a153003083161 天前
[数据抓取-1]beautifulsoup
开发语言·python·beautifulsoup
小杨同学yx1 天前
有关maven的一些知识点
java·开发语言
重生之我要当java大帝1 天前
java微服务-尚医通-编写医院设置接口下
java·开发语言·sql
寻找华年的锦瑟1 天前
Qt-QDir
开发语言·qt
小妖6661 天前
vscode 怎么运行 c++ 文件
开发语言·c++