#include <QtGui/QWidget>#include "mythread.h" namespace Ui{ class blinkWidgetClass;}class blinkWidget : public QWidget{ Q_OBJECTpublic: blinkWidget(QWidget *parent = 0); ~blinkWidget(); int currentRow;public slots: void changeRow( int newRow);private: Ui::blinkWidgetClass *ui; MyThread* mythread;};
#include "blinkwidget.h"#include "ui_blinkwidget.h"blinkWidget::blinkWidget(QWidget *parent) : QWidget(parent), ui(new Ui::blinkWidgetClass){ //currentRow = 2; ui->setupUi(this); QLabel* LabelArray[4] = { ui->myLab0, ui->myLab1, ui->myLab2, ui->myLab3 }; mythread = new MyThread(parent); connect(ui->myGoBut, SIGNAL(clicked()), mythread, SLOT(start())); connect(ui->myStopBut, SIGNAL(clicked()), mythread, SLOT(terminate())); connect(mythread, SIGNAL(update_row(int)), this, SLOT(changeRow(int))); connect(mythread, SIGNAL(update_hex(QString)), LabelArray[ currentRow ], SLOT(setText(QString)));}blinkWidget::~blinkWidget(){ delete ui;}void blinkWidget::changeRow( int newRow) { currentRow = newRow; }
#include <QThread>class MyThread : public QThread { Q_OBJECT public: MyThread(QObject* o):QThread(o) { } void run(); signals: void update_row(int); void update_hex( QString); };
#include "mythread.h"void MyThread::run() { int i = 0; int row = 2; while( i < 100) { i++; msleep(30); emit update_row( row ); emit update_hex( QString::number(i, 16).toUpper() ); row++; if(row == 4){row = 0;} } }
C++ (Qt)class MyThread : public QThread {...signals: void update_row(int, const QString &text);};
C++ (Qt)void MyThread::run(){... while( i < 100) { ... emit update_row( row, QString::number(i, 16).toUpper() ); .... }....}
C++ (Qt)class blinkWidget : public QWidget{...public slots: void updateRow(int newRow, const QString &text);...};
C++ (Qt)connect(mythread, SIGNAL(update_row(int, const QString &)), this, SLOT(updateRow(int, const QString &)));
C++ (Qt)void blinkWidget::updateRow( int newRow, const QString &text){ QLabel *label = LabelArray[newRow]; label->setText(text);}
class blinkWidget : public QWidget{ Q_OBJECTpublic: blinkWidget(QWidget *parent = 0); ~blinkWidget(); int currentRow; QLabel* LabelArray[4];...
class Ui_blinkWidgetClass{public: QPushButton *myQuitBut; QPushButton *myGoBut; QPushButton *myStopBut; QLabel *myLab0; QLabel *myLab1; QLabel *myLab2; QLabel *myLab3;QLabel* LabelArray[4];...
blinkWidget::blinkWidget(QWidget *parent) : QWidget(parent), ui(new Ui::blinkWidgetClass){ currentRow = 2; ui->setupUi(this); ui->LabelArray = { ui->myLab0, ui->myLab1, ui->myLab2, ui->myLab3 };...
blinkWidget::blinkWidget(QWidget *parent) : QWidget(parent), ui(new Ui::blinkWidgetClass){ ui->setupUi(this); ui->LabelArray[0] = ui->myLab0; ui->LabelArray[1] = ui->myLab1; ui->LabelArray[2] = ui->myLab2; ui->LabelArray[3] = ui->myLab3;...
C++ (Qt)#include <QList> class QLabel; class blinkWidget : public QWidget{ Q_OBJECT public: blinkWidget(QWidget *parent = 0); ~blinkWidget(); int currentRow; QList<QLabel *> LabelArray;..}
C++ (Qt)blinkWidget::blinkWidget(QWidget *parent) : QWidget(parent), ui(new Ui::blinkWidgetClass){ ui->setupUi(this); LabelArray.append(ui->myLab0); LabelArray.append(ui->myLab1); LabelArray.append(ui->myLab2); LabelArray.append(ui->myLab3);...}
C++ (Qt)QLabel *label = LabelArray.at(i);