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();
}
相关推荐
李妍.1 小时前
02Numpy基础(上)
开发语言·python
TheBestRucy1 小时前
Python 九阳神功之贰:面向对象(下)
开发语言·python
AI_小站2 小时前
刚面完百度的 Agent 开发岗,我才发现:世界就是个巨大的草台班子
java·开发语言·人工智能·spring·百度·langchain
felixking3 小时前
C++20 协程
开发语言·c++·协程
Zane1994124 小时前
CAS 与原子类:Java 如何实现无锁编程
java·开发语言
码农颜5 小时前
6.3 主函数流程剖析
开发语言·php
TheBestRucy5 小时前
Python 九阳神功:从零筑基到线程飞升
服务器·开发语言·网络·人工智能·python
研☆香5 小时前
聊一聊前端的常见字 关键字
开发语言·前端·javascript
草莓橙子碗6 小时前
Claude 使用指南
开发语言·python
longxiaozhang66 小时前
C# Array类:数组其实没那么难
开发语言·c#