Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Class variable updating / QLabel | Thread
QtWS25 Last Chance

Class variable updating / QLabel | Thread

Scheduled Pinned Locked Moved Unsolved General and Desktop
classqlabelupdatvariable
2 Posts 2 Posters 1.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    paul_b
    wrote on 1 Jul 2016, 21:03 last edited by
    #1

    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 .

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 1 Jul 2016, 21:45 last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      1/2

      1 Jul 2016, 21:03

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved