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. Text is not updated in qwidget.

Text is not updated in qwidget.

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
31 Posts 5 Posters 10.0k Views 2 Watching
  • 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.
  • S Offline
    S Offline
    sootoo23
    wrote on last edited by sootoo23
    #3

    @SGaist said in Text is not updated in qwidget.:

    Can you show how you initialise Label_SetVal ?
    Where exactly are you calling setText on it ?

    Thank you for your reply.
    source code---------------------------------------------------------------------------
    char keypadBuf[30] = {0,};
    QLabel* Label_SetVal ;

    Label_SetVal = ui->lb_NetSetVal;

    sprintf((char *)keypadBuf, "%s.%d", QByteArray(Label_SetVal ->text().toLocal8Bit()).data(),val);
    SetValue = QString(keypadBuf);
    Label_SetVal ->setText(SetValue);

    //qApp->processEvents();
    //qApp->sendPostedEvents();
    //qApp->processEvents(QEventLoop::ExcludeUserInput);
    //LB_SetVal->repaint();
    //LB_SetVal->parentWidget()->repaint();
    //LB_SetVal->update();
    //LB_SetVal->parentWidget()->update();
    
    jsulmJ 1 Reply Last reply
    0
    • S sootoo23

      @SGaist said in Text is not updated in qwidget.:

      Can you show how you initialise Label_SetVal ?
      Where exactly are you calling setText on it ?

      Thank you for your reply.
      source code---------------------------------------------------------------------------
      char keypadBuf[30] = {0,};
      QLabel* Label_SetVal ;

      Label_SetVal = ui->lb_NetSetVal;

      sprintf((char *)keypadBuf, "%s.%d", QByteArray(Label_SetVal ->text().toLocal8Bit()).data(),val);
      SetValue = QString(keypadBuf);
      Label_SetVal ->setText(SetValue);

      //qApp->processEvents();
      //qApp->sendPostedEvents();
      //qApp->processEvents(QEventLoop::ExcludeUserInput);
      //LB_SetVal->repaint();
      //LB_SetVal->parentWidget()->repaint();
      //LB_SetVal->update();
      //LB_SetVal->parentWidget()->update();
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #4

      @sootoo23 said in Text is not updated in qwidget.:

      sprintf((char *)keypadBuf, "%s.%d", QByteArray(Label_SetVal ->text().toLocal8Bit()).data(),val);

      Wow, this looks really complicated.
      Why not just use QString::arg(...)?

      SetValue = QString("%1.%2").arg(Label_SetVal ->text()).arg(val);
      

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 1 Reply Last reply
      1
      • jsulmJ jsulm

        @sootoo23 said in Text is not updated in qwidget.:

        sprintf((char *)keypadBuf, "%s.%d", QByteArray(Label_SetVal ->text().toLocal8Bit()).data(),val);

        Wow, this looks really complicated.
        Why not just use QString::arg(...)?

        SetValue = QString("%1.%2").arg(Label_SetVal ->text()).arg(val);
        
        S Offline
        S Offline
        sootoo23
        wrote on last edited by
        #5

        @jsulm

        I need to pass the char buffer of "keypadBuf" to the C library.
        It can not pass in the type of QString.

        jsulmJ 1 Reply Last reply
        0
        • S sootoo23

          @jsulm

          I need to pass the char buffer of "keypadBuf" to the C library.
          It can not pass in the type of QString.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by jsulm
          #6

          @sootoo23

          keypadBuf = SetValue.toLocal8Bit().data();
          

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          S 1 Reply Last reply
          0
          • jsulmJ jsulm

            @sootoo23

            keypadBuf = SetValue.toLocal8Bit().data();
            
            S Offline
            S Offline
            sootoo23
            wrote on last edited by
            #7

            @jsulm
            Thank you for your feedback.
            Is there a solution to my problem?

            jsulmJ 1 Reply Last reply
            0
            • S sootoo23

              @jsulm
              Thank you for your feedback.
              Is there a solution to my problem?

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by jsulm
              #8

              @sootoo23 Is this label visible? Does it already have any text? Also, what are you doing after setting the text - do you maybe block the event loop with a loop?
              Did you check what SetValue contains?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              S 1 Reply Last reply
              0
              • jsulmJ jsulm

                @sootoo23 Is this label visible? Does it already have any text? Also, what are you doing after setting the text - do you maybe block the event loop with a loop?
                Did you check what SetValue contains?

                S Offline
                S Offline
                sootoo23
                wrote on last edited by
                #9

                @jsulm said in Text is not updated in qwidget.:

                Is this label visible? Does it already have any text? Also, what are you doing after setting the text - do you maybe block the event loop with a loop?
                Did you check what SetValue contains?

                yes, it is visible.

                The default text is displayed when you load the initial QWidget.
                The problem is that if you change the value by the number of characters, it will not update.

                "printf("%s (%s)\n", keypadBuf, SetValue.toLocal8Bit().data());"
                data is output well.

                jsulmJ 1 Reply Last reply
                0
                • S sootoo23

                  @jsulm said in Text is not updated in qwidget.:

                  Is this label visible? Does it already have any text? Also, what are you doing after setting the text - do you maybe block the event loop with a loop?
                  Did you check what SetValue contains?

                  yes, it is visible.

                  The default text is displayed when you load the initial QWidget.
                  The problem is that if you change the value by the number of characters, it will not update.

                  "printf("%s (%s)\n", keypadBuf, SetValue.toLocal8Bit().data());"
                  data is output well.

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #10

                  @sootoo23 Do you block the event loop somewhere?

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  S 1 Reply Last reply
                  0
                  • jsulmJ jsulm

                    @sootoo23 Do you block the event loop somewhere?

                    S Offline
                    S Offline
                    sootoo23
                    wrote on last edited by
                    #11

                    @jsulm

                    I do not know what blocking an event loop is.

                    jsulmJ 1 Reply Last reply
                    0
                    • S sootoo23

                      @jsulm

                      I do not know what blocking an event loop is.

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #12

                      @sootoo23 Do you have any endless loops?

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      S 1 Reply Last reply
                      1
                      • jsulmJ jsulm

                        @sootoo23 Do you have any endless loops?

                        S Offline
                        S Offline
                        sootoo23
                        wrote on last edited by
                        #13

                        @jsulm
                        Yes, i have endless loop.
                        I’m using tow QTimers.

                        jsulmJ 1 Reply Last reply
                        0
                        • S sootoo23

                          @jsulm
                          Yes, i have endless loop.
                          I’m using tow QTimers.

                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by SGaist
                          #14

                          @sootoo23 Endless loops are a bad idea when using event driven frameworks like Qt...

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          S 2 Replies Last reply
                          1
                          • jsulmJ jsulm

                            @sootoo23 Endless loops are a bad idea when using event driven frameworks like Qt...

                            S Offline
                            S Offline
                            sootoo23
                            wrote on last edited by
                            #15

                            @jsulm
                            Instead of a regular endless loop,
                            Is it also a problem when using QTimer?

                            Also, how does the endless loop relate to the problem of not updating the text?

                            1 Reply Last reply
                            0
                            • jsulmJ jsulm

                              @sootoo23 Endless loops are a bad idea when using event driven frameworks like Qt...

                              S Offline
                              S Offline
                              sootoo23
                              wrote on last edited by
                              #16

                              @jsulm

                              I tried to remove the endless loop,
                              but The problem was not solved.

                              jsulmJ 1 Reply Last reply
                              0
                              • S sootoo23

                                @jsulm

                                I tried to remove the endless loop,
                                but The problem was not solved.

                                jsulmJ Offline
                                jsulmJ Offline
                                jsulm
                                Lifetime Qt Champion
                                wrote on last edited by
                                #17

                                @sootoo23 Endless loops block the Qt event loop. If this event loop is blocked no signals are emitted and no events are handled - the UI is not updated. I don't know what the problem with your code is as I don't have it.

                                https://forum.qt.io/topic/113070/qt-code-of-conduct

                                1 Reply Last reply
                                2
                                • SGaistS Offline
                                  SGaistS Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #18

                                  Can you show the latest complete version of that part of your code ?

                                  With only I removed something and it still doesn't work, there's no way to debug your problem.

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

                                  S 1 Reply Last reply
                                  2
                                  • SGaistS SGaist

                                    Can you show the latest complete version of that part of your code ?

                                    With only I removed something and it still doesn't work, there's no way to debug your problem.

                                    S Offline
                                    S Offline
                                    sootoo23
                                    wrote on last edited by sootoo23
                                    #19

                                    @SGaist

                                    ------------mainwindow.cpp------------
                                    MainWindow::MainWindow(QWidget *parent) :
                                    QMainWindow(parent),
                                    ui(new Ui::MainWindow)
                                    {
                                    ...
                                    ...
                                    #if (0)
                                    //Removed endless loop timer
                                    Hometimer = new QTimer(this);
                                    connect(Hometimer, SIGNAL(timeout()),this,SLOT(HomeInfo_Update()));
                                    Hometimer->start(1000);
                                    #endif
                                    }
                                    void MainWindow::HomeInfo_Update()
                                    {
                                    ...
                                    ...
                                    ui->lb_HomeClk->setText(QString(TimeBuf));
                                    ...
                                    }

                                    ------------menuQwidget.cpp------------
                                    wnd_menu::wnd_menu(QWidget *parent) :
                                    QWidget(parent),
                                    ui(new Ui::wnd_menu)
                                    {
                                    ...
                                    ...
                                    #if (0)
                                    //Removed endless loop timer
                                    Menu_Timer = new QTimer;
                                    connect(Menu_Timer, SIGNAL (timeout()), this, SLOT(MenuInfo_Update()));
                                    Menu_Timer->start(1000);
                                    Menu_Timer->blockSignals(true);
                                    #endif
                                    }

                                    void wnd_menu::MenuInfo_Update()
                                    {
                                    ...
                                    ...
                                    ui->lb_MenuClk->setText(QString(TimeBuf));
                                    ...
                                    ...
                                    }

                                    jsulmJ K 2 Replies Last reply
                                    0
                                    • S sootoo23

                                      @SGaist

                                      ------------mainwindow.cpp------------
                                      MainWindow::MainWindow(QWidget *parent) :
                                      QMainWindow(parent),
                                      ui(new Ui::MainWindow)
                                      {
                                      ...
                                      ...
                                      #if (0)
                                      //Removed endless loop timer
                                      Hometimer = new QTimer(this);
                                      connect(Hometimer, SIGNAL(timeout()),this,SLOT(HomeInfo_Update()));
                                      Hometimer->start(1000);
                                      #endif
                                      }
                                      void MainWindow::HomeInfo_Update()
                                      {
                                      ...
                                      ...
                                      ui->lb_HomeClk->setText(QString(TimeBuf));
                                      ...
                                      }

                                      ------------menuQwidget.cpp------------
                                      wnd_menu::wnd_menu(QWidget *parent) :
                                      QWidget(parent),
                                      ui(new Ui::wnd_menu)
                                      {
                                      ...
                                      ...
                                      #if (0)
                                      //Removed endless loop timer
                                      Menu_Timer = new QTimer;
                                      connect(Menu_Timer, SIGNAL (timeout()), this, SLOT(MenuInfo_Update()));
                                      Menu_Timer->start(1000);
                                      Menu_Timer->blockSignals(true);
                                      #endif
                                      }

                                      void wnd_menu::MenuInfo_Update()
                                      {
                                      ...
                                      ...
                                      ui->lb_MenuClk->setText(QString(TimeBuf));
                                      ...
                                      ...
                                      }

                                      jsulmJ Offline
                                      jsulmJ Offline
                                      jsulm
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #20

                                      @sootoo23

                                      • Are the slots you connected to the timers called?
                                      • Is TimeBuf set when these slots are called?

                                      //Removed endless loop timer - this is not the kind of endless loop I mentioned. It is fine to use timers this way. The problem is somewhere else. You need to debug your app or upload the code to somewhere so we can take a look.

                                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                                      1 Reply Last reply
                                      1
                                      • S sootoo23

                                        @SGaist

                                        ------------mainwindow.cpp------------
                                        MainWindow::MainWindow(QWidget *parent) :
                                        QMainWindow(parent),
                                        ui(new Ui::MainWindow)
                                        {
                                        ...
                                        ...
                                        #if (0)
                                        //Removed endless loop timer
                                        Hometimer = new QTimer(this);
                                        connect(Hometimer, SIGNAL(timeout()),this,SLOT(HomeInfo_Update()));
                                        Hometimer->start(1000);
                                        #endif
                                        }
                                        void MainWindow::HomeInfo_Update()
                                        {
                                        ...
                                        ...
                                        ui->lb_HomeClk->setText(QString(TimeBuf));
                                        ...
                                        }

                                        ------------menuQwidget.cpp------------
                                        wnd_menu::wnd_menu(QWidget *parent) :
                                        QWidget(parent),
                                        ui(new Ui::wnd_menu)
                                        {
                                        ...
                                        ...
                                        #if (0)
                                        //Removed endless loop timer
                                        Menu_Timer = new QTimer;
                                        connect(Menu_Timer, SIGNAL (timeout()), this, SLOT(MenuInfo_Update()));
                                        Menu_Timer->start(1000);
                                        Menu_Timer->blockSignals(true);
                                        #endif
                                        }

                                        void wnd_menu::MenuInfo_Update()
                                        {
                                        ...
                                        ...
                                        ui->lb_MenuClk->setText(QString(TimeBuf));
                                        ...
                                        ...
                                        }

                                        K Offline
                                        K Offline
                                        kumararajas
                                        wrote on last edited by kumararajas
                                        #21

                                        @sootoo23 Both, setText functions does not get called at all. Hence, text is not displayed.

                                        And I don't know why 'blocksignals' function is used here.

                                        jsulmJ 1 Reply Last reply
                                        3
                                        • K Offline
                                          K Offline
                                          kumararajas
                                          wrote on last edited by
                                          #22
                                          This post is deleted!
                                          1 Reply Last reply
                                          0

                                          • Login

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