Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to change label value?

How to change label value?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
6 Posts 2 Posters 568 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.
  • E Offline
    E Offline
    ELIF
    wrote on last edited by ELIF
    #1

    I would like to change textmessage in a while loop how can I get it? Now same value is coming screen only once.Although I print ethernetThread->buffer[i] to console in a while loop, different values are coming
    In header file I have

     public slots:
        void messageSlot();
     public:
        QLabel *radar_data_label;
    

    In mainWindow.cpp

     void MainWindow::messageSlot(){
      int i=0;
      while(1){
        QString textmessage = QString(QChar::fromLatin1(ethernetThread->buffer[i]));
        radar_data_label->setText(textmessage);
        radar_data_label->setStyleSheet("QLabel { font: 18pt; color : white; }");
        i++;
      }
    
     }
    
    JonBJ 1 Reply Last reply
    0
    • E ELIF

      I would like to change textmessage in a while loop how can I get it? Now same value is coming screen only once.Although I print ethernetThread->buffer[i] to console in a while loop, different values are coming
      In header file I have

       public slots:
          void messageSlot();
       public:
          QLabel *radar_data_label;
      

      In mainWindow.cpp

       void MainWindow::messageSlot(){
        int i=0;
        while(1){
          QString textmessage = QString(QChar::fromLatin1(ethernetThread->buffer[i]));
          radar_data_label->setText(textmessage);
          radar_data_label->setStyleSheet("QLabel { font: 18pt; color : white; }");
          i++;
        }
      
       }
      
      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by JonB
      #2

      @ELIF
      You can't while you have a while(1), which blocks the Qt event loop and updates to the display. (Not to mention, your code runs forever keeping incrementing i, how does ethernetThread->buffer[i] not error?)

      Use proper signals & slots to do your UI updating, when new characters are present in ethernetThread->buffer[i], allowing the Qt event loop to be re-entered so it can show the updated text.

      And while I think of it, if ethernetThread is truly a thread you need to understand generally how to access/share data safely across threads before you go directly reading from buffers in one thread which another thread is writing to.....

      1 Reply Last reply
      2
      • E Offline
        E Offline
        ELIF
        wrote on last edited by
        #3

        Can you write a simple code about signal slot for this code,really cant understand it.

        JonBJ 1 Reply Last reply
        0
        • E ELIF

          Can you write a simple code about signal slot for this code,really cant understand it.

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by JonB
          #4

          @ELIF
          If you don't understand how to write signals & slots in Qt you won't get anywhere. You don't want someone else to write it for you, you need to know how to write it yourself. There are thousands of examples in the Qt docs, examples and out there on the web. You need to read and understand https://doc.qt.io/qt-5/signalsandslots.html for a start.

          1 Reply Last reply
          2
          • E Offline
            E Offline
            ELIF
            wrote on last edited by
            #5

            thank you I did it. :)

            JonBJ 1 Reply Last reply
            0
            • E ELIF

              thank you I did it. :)

              JonBJ Online
              JonBJ Online
              JonB
              wrote on last edited by
              #6

              @ELIF
              Now that is good, well done! Sorry to have been harsh, but this is much better so that you will understand signals, slots & connects going forward :)

              1 Reply Last reply
              1

              • Login

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