#ifndef WIN_H#define WIN_H#include <QWidget>#include <QtWidgets>class win : public QWidget{public: win(QString str); QProgressBar *pgb1; QPushButton *btn_plus; QVBoxLayout *lay_main; int count;signals: void set_pos(int);public slots: void increase(bool);};#endif // WIN_H
#include "win.h"win::win(QString str){ setWindowTitle(str); pgb1 = new QProgressBar; pgb1->setOrientation(Qt::Vertical); btn_plus = new QPushButton("+"); lay_main = new QVBoxLayout; lay_main->addWidget(pgb1); lay_main->addWidget(btn_plus); setLayout(lay_main); QObject::connect(btn_plus, SIGNAL(clicked()), this, SLOT(increase())); QObject::connect(this, SIGNAL(set_pos(int)), pgb1, SLOT(setValue(int)));}void win::increase(bool){ count++; emit set_pos(count);}void win::set_pos(int){}
#include <QApplication>#include <QtWidgets>#include "win.h"int main(int argc, char *argv[]){ QApplication app(argc, argv); win win1("This is a window"); win1.show(); return app.exec();}
class win : public QWidget{ Q_OBJECTpublic: win(QString str); QProgressBar *pgb1; QPushButton *btn_plus; QVBoxLayout *lay_main; int count;public slots: void increase();signals: void set_pos(int data);};