用 Qt实现三个窗口,一个label,两个button,
答案:1 悬赏:60 手机版
解决时间 2021-11-21 08:07
- 提问者网友:骑士
- 2021-11-21 00:04
用 Qt实现三个窗口,一个label,两个button,
最佳答案
- 五星知识达人网友:十鸦
- 2021-11-21 01:03
简单的问题我解决,这为原创,转载请注明
------kingboy12345
///////widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include
#include
#include
#include
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = 0);
~Widget();
QPushButton *clearNO,*addNO;
QLabel *label;
QHBoxLayout *qhboxlayout;
private slots:
void clearNOhandle();
void addNOhandle();
};
#endif // WIDGET_H
///////////widget.cpp
#include "widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
clearNO =new QPushButton("CLEAR");
addNO =new QPushButton("ADD");
label =new QLabel("0");
qhboxlayout =new QHBoxLayout(this);
qhboxlayout->addWidget(label);
qhboxlayout->addWidget(clearNO);
qhboxlayout->addWidget(addNO);
connect(clearNO,SIGNAL(clicked()),this,SLOT(clearNOhandle()));
connect(addNO,SIGNAL(clicked()),this,SLOT(addNOhandle()));
}
void Widget::addNOhandle(){
QString nostr;
int no;
nostr = label->text();
no = nostr.toInt();
no++;
nostr.setNum(no);
label->setText(nostr);
}
////////main函数
void Widget::clearNOhandle(){
label->setText("0");
}
Widget::~Widget()
{
}
#include
#include "widget.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
------kingboy12345
///////widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include
#include
#include
#include
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = 0);
~Widget();
QPushButton *clearNO,*addNO;
QLabel *label;
QHBoxLayout *qhboxlayout;
private slots:
void clearNOhandle();
void addNOhandle();
};
#endif // WIDGET_H
///////////widget.cpp
#include "widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
clearNO =new QPushButton("CLEAR");
addNO =new QPushButton("ADD");
label =new QLabel("0");
qhboxlayout =new QHBoxLayout(this);
qhboxlayout->addWidget(label);
qhboxlayout->addWidget(clearNO);
qhboxlayout->addWidget(addNO);
connect(clearNO,SIGNAL(clicked()),this,SLOT(clearNOhandle()));
connect(addNO,SIGNAL(clicked()),this,SLOT(addNOhandle()));
}
void Widget::addNOhandle(){
QString nostr;
int no;
nostr = label->text();
no = nostr.toInt();
no++;
nostr.setNum(no);
label->setText(nostr);
}
////////main函数
void Widget::clearNOhandle(){
label->setText("0");
}
Widget::~Widget()
{
}
#include
#include "widget.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯