Class variable updating / QLabel | Thread
-
Hello guys , i'm totally new to Qt and i have installed the Visual studio add-in for Qt .
I have some c++ knowledge but i'm kind of self-educated with programmations (mainly tutorial etc) so i make a lot of mistake ^^ .I was wondering where in your code the gui you are coding are 'updating' because if i want to update a class variable you'll need to :
- Create a new Thread for updating those
- Find where in your code the gui is updated to put your own update function
I have a problem doing each of them , for the new thread i can't see how can i pass a class object through a LPVOID params .
And finally i have tried to implement a push button which call a function to update the variable but it's not working either .
Code :
Class constructor :
MaFenetre::MaFenetre() : QDialog() { labelTime = new QLabel("TIME : " + timeString , this); labelTime->move(800, 20); boutonRefresh = new QPushButton("Refresh", this); boutonRefresh->move(600, 450); // CONNECTIION BOUTON ETC QObject::connect(boutonRefresh, SIGNAL(pressed()), this, SLOT(update())); }
Class defenition :
class MaFenetre : public QDialog // On hérite de QWidget (IMPORTANT) { Q_OBJECT; public: MaFenetre(); QString timeString; public slots: void update(){ QTime time = QTime::currentTime(); timeString = time.toString(); } private : QPushButton *boutonRefresh; QPushButton *boutonSettings; QPushButton *boutonQuit; QLabel *labelUserName; QLabel *labelTime; // PAGE 1 QGroupBox *box; QGroupBox *box2; QLabel *labelGame; QLabel *labelVersion; QLabel *labelPatch; QLabel *labelDeveloppers; QLabel *labelDriver; };
Thanks .
-
Hi and welcome to devnet,
What variable do you want to update ?
Why do you think you need a thread for that ?
On a side note, update is a QWidget non virtual slot so you can't use that name.
In any case you should call
labelTimr->setText("TIME :" + timeValue)
to update the content of your QLabel.