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.
Qt 6.11 is out! See what's new in the release blog

Text is not updated in qwidget.

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
31 Posts 5 Posters 10.3k 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 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
              • K kumararajas

                @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 Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #23

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

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

                Wow, I didn't notice at all!

                @sootoo23 Why do you block the timer signals? This way you cannot expect the signals to be emitted and the slots called!

                Menu_Timer->blockSignals(true); // WHY?
                

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

                S 2 Replies Last reply
                4
                • jsulmJ jsulm

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

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

                  Wow, I didn't notice at all!

                  @sootoo23 Why do you block the timer signals? This way you cannot expect the signals to be emitted and the slots called!

                  Menu_Timer->blockSignals(true); // WHY?
                  
                  S Offline
                  S Offline
                  sootoo23
                  wrote on last edited by sootoo23
                  #24

                  @jsulm @kumararajas
                  The main problem is not a block signal.
                  The Timer is already blocked from use.

                  Timer has nothing to do with the problem.

                  The code that I uploaded is the code that removed the infinite loop (timer).

                  Mainwindow.cpp -> menuQwidget->show();
                  menuQwidget.cpp -> Dialog_Keypad->exec();

                  ------------DialogKeypad.cpp------------
                  my problem... not updated >>>>> LB_SetVal->setText(SetValue);

                  1 Reply Last reply
                  0
                  • jsulmJ jsulm

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

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

                    Wow, I didn't notice at all!

                    @sootoo23 Why do you block the timer signals? This way you cannot expect the signals to be emitted and the slots called!

                    Menu_Timer->blockSignals(true); // WHY?
                    
                    S Offline
                    S Offline
                    sootoo23
                    wrote on last edited by sootoo23
                    #25

                    @jsulm @kumararajas
                    ------------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));
                    ...
                    ...
                    }

                    ------------DialogKeypad.cpp------------
                    Dialog_Keypad::Dialog_Keypad(QWidget *parent) :
                    QDialog(parent),
                    ui(new Ui::Dialog_Keypad)
                    {
                    ui->setupUi(this);

                    QString img_path = "/images/Keypad.jpg";
                    QImage img(img_path);    
                    QPixmap buf = QPixmap::fromImage(img);    
                    QGraphicsScene* MenuScene = new QGraphicsScene;
                    
                    ui->KeypadFrame->setScene(MenuScene);
                    MenuScene->addPixmap(buf);
                    
                    //text color setting
                    QPalette* palette = new QPalette();
                    palette->setColor(QPalette::WindowText,Qt::yellow);
                    ui->lb_SettingValue->setPalette(*palette);	
                    
                    
                    connect(ui->Keypad_Num0, SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                    connect(ui->Keypad_Num1, SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                    connect(ui->Keypad_Num2, SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                    connect(ui->Keypad_Num3, SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                    connect(ui->Keypad_Num4, SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                    connect(ui->Keypad_Num5, SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                    connect(ui->Keypad_Num6, SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                    connect(ui->Keypad_Num7, SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                    connect(ui->Keypad_Num8, SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                    connect(ui->Keypad_Num9, SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                    connect(ui->Keypad_Dot,  SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                    
                    KeyPadMapper.setMapping(ui->Keypad_Num0, 0);
                    KeyPadMapper.setMapping(ui->Keypad_Num1, 1);
                    KeyPadMapper.setMapping(ui->Keypad_Num2, 2);
                    KeyPadMapper.setMapping(ui->Keypad_Num3, 3);
                    KeyPadMapper.setMapping(ui->Keypad_Num4, 4);
                    KeyPadMapper.setMapping(ui->Keypad_Num5, 5);
                    KeyPadMapper.setMapping(ui->Keypad_Num6, 6);
                    KeyPadMapper.setMapping(ui->Keypad_Num7, 7);
                    KeyPadMapper.setMapping(ui->Keypad_Num8, 8);
                    KeyPadMapper.setMapping(ui->Keypad_Num9, 9);
                    KeyPadMapper.setMapping(ui->Keypad_Dot, 100);
                    
                    connect(&KeyPadMapper, SIGNAL(mapped(int)), this, SLOT(SetKeypadData(int)));
                    

                    }

                    void Dialog_Keypad::SetKeypadData(int val)
                    {
                    char keypadBuf[30] = {0,};
                    QLabel* LB_SetVal;

                    if(CurKeypadType == KEYPAD_NORMAL)
                    	LB_SetVal = ui->lb_SettingValue;
                    else if(CurKeypadType == KEYPAD_NETWORK)
                    	LB_SetVal = ui->lb_NetSetVal;
                    else if(CurKeypadType == KEYPAD_PASSWORD)
                    	LB_SetVal = ui->lb_PWSetVal;
                    else 
                    	LB_SetVal = ui->lb_SettingValue;
                    
                    if(CurKeypadType == KEYPAD_PASSWORD)
                    {
                    	if(LB_SetVal->text().size() > 3)
                    	{
                    		printf("[%s] Password Length Over. :%s \n", __FUNCTION__, QByteArray(LB_SetVal->text().toLocal8Bit()).data());
                    		return;
                    	}
                    	
                    	SetValue = SetValue + QString::number(val);
                    	sprintf((char *)keypadBuf, "%s%s", QByteArray(LB_SetVal->text().toLocal8Bit()).data(), "*");
                    	LB_SetVal->setText(QString(keypadBuf));
                    	return;
                    }
                    else if(CurKeypadType == KEYPAD_NETWORK)
                    {
                    	if(LB_SetVal->text().size() > 14)
                    	{
                    		printf("[%s] Network Setting Str Length Over.\n", __FUNCTION__);
                    		return;
                    	}
                    	
                    	if(val == 100) //dot.
                    		sprintf((char *)keypadBuf, "%s%s", QByteArray(LB_SetVal->text().toLocal8Bit()).data(),".");
                    	else if((LB_SetVal->text().size() == 3)
                    			|| (LB_SetVal->text().size() == 7)
                    			|| (LB_SetVal->text().size() == 11))
                    		sprintf((char *)keypadBuf, "%s.%d", QByteArray(LB_SetVal->text().toLocal8Bit()).data(),val);
                    	else
                    		sprintf((char *)keypadBuf, "%s%d", QByteArray(LB_SetVal->text().toLocal8Bit()).data(),val);
                    }
                    else
                    {		
                    	if(val == 100) //dot.
                    		sprintf((char *)keypadBuf, "%s%s", QByteArray(LB_SetVal->text().toLocal8Bit()).data(),".");
                    	else
                    		sprintf((char *)keypadBuf, "%s%d", QByteArray(LB_SetVal->text().toLocal8Bit()).data(),val);
                    }
                    
                    SetValue = QString(keypadBuf);
                     My Problem >> LB_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();
                    
                    printf("[%s] %s\n", __FUNCTION__, keypadBuf);
                    

                    }

                    J.HilkJ 1 Reply Last reply
                    0
                    • S sootoo23

                      @jsulm @kumararajas
                      ------------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));
                      ...
                      ...
                      }

                      ------------DialogKeypad.cpp------------
                      Dialog_Keypad::Dialog_Keypad(QWidget *parent) :
                      QDialog(parent),
                      ui(new Ui::Dialog_Keypad)
                      {
                      ui->setupUi(this);

                      QString img_path = "/images/Keypad.jpg";
                      QImage img(img_path);    
                      QPixmap buf = QPixmap::fromImage(img);    
                      QGraphicsScene* MenuScene = new QGraphicsScene;
                      
                      ui->KeypadFrame->setScene(MenuScene);
                      MenuScene->addPixmap(buf);
                      
                      //text color setting
                      QPalette* palette = new QPalette();
                      palette->setColor(QPalette::WindowText,Qt::yellow);
                      ui->lb_SettingValue->setPalette(*palette);	
                      
                      
                      connect(ui->Keypad_Num0, SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                      connect(ui->Keypad_Num1, SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                      connect(ui->Keypad_Num2, SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                      connect(ui->Keypad_Num3, SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                      connect(ui->Keypad_Num4, SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                      connect(ui->Keypad_Num5, SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                      connect(ui->Keypad_Num6, SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                      connect(ui->Keypad_Num7, SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                      connect(ui->Keypad_Num8, SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                      connect(ui->Keypad_Num9, SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                      connect(ui->Keypad_Dot,  SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                      
                      KeyPadMapper.setMapping(ui->Keypad_Num0, 0);
                      KeyPadMapper.setMapping(ui->Keypad_Num1, 1);
                      KeyPadMapper.setMapping(ui->Keypad_Num2, 2);
                      KeyPadMapper.setMapping(ui->Keypad_Num3, 3);
                      KeyPadMapper.setMapping(ui->Keypad_Num4, 4);
                      KeyPadMapper.setMapping(ui->Keypad_Num5, 5);
                      KeyPadMapper.setMapping(ui->Keypad_Num6, 6);
                      KeyPadMapper.setMapping(ui->Keypad_Num7, 7);
                      KeyPadMapper.setMapping(ui->Keypad_Num8, 8);
                      KeyPadMapper.setMapping(ui->Keypad_Num9, 9);
                      KeyPadMapper.setMapping(ui->Keypad_Dot, 100);
                      
                      connect(&KeyPadMapper, SIGNAL(mapped(int)), this, SLOT(SetKeypadData(int)));
                      

                      }

                      void Dialog_Keypad::SetKeypadData(int val)
                      {
                      char keypadBuf[30] = {0,};
                      QLabel* LB_SetVal;

                      if(CurKeypadType == KEYPAD_NORMAL)
                      	LB_SetVal = ui->lb_SettingValue;
                      else if(CurKeypadType == KEYPAD_NETWORK)
                      	LB_SetVal = ui->lb_NetSetVal;
                      else if(CurKeypadType == KEYPAD_PASSWORD)
                      	LB_SetVal = ui->lb_PWSetVal;
                      else 
                      	LB_SetVal = ui->lb_SettingValue;
                      
                      if(CurKeypadType == KEYPAD_PASSWORD)
                      {
                      	if(LB_SetVal->text().size() > 3)
                      	{
                      		printf("[%s] Password Length Over. :%s \n", __FUNCTION__, QByteArray(LB_SetVal->text().toLocal8Bit()).data());
                      		return;
                      	}
                      	
                      	SetValue = SetValue + QString::number(val);
                      	sprintf((char *)keypadBuf, "%s%s", QByteArray(LB_SetVal->text().toLocal8Bit()).data(), "*");
                      	LB_SetVal->setText(QString(keypadBuf));
                      	return;
                      }
                      else if(CurKeypadType == KEYPAD_NETWORK)
                      {
                      	if(LB_SetVal->text().size() > 14)
                      	{
                      		printf("[%s] Network Setting Str Length Over.\n", __FUNCTION__);
                      		return;
                      	}
                      	
                      	if(val == 100) //dot.
                      		sprintf((char *)keypadBuf, "%s%s", QByteArray(LB_SetVal->text().toLocal8Bit()).data(),".");
                      	else if((LB_SetVal->text().size() == 3)
                      			|| (LB_SetVal->text().size() == 7)
                      			|| (LB_SetVal->text().size() == 11))
                      		sprintf((char *)keypadBuf, "%s.%d", QByteArray(LB_SetVal->text().toLocal8Bit()).data(),val);
                      	else
                      		sprintf((char *)keypadBuf, "%s%d", QByteArray(LB_SetVal->text().toLocal8Bit()).data(),val);
                      }
                      else
                      {		
                      	if(val == 100) //dot.
                      		sprintf((char *)keypadBuf, "%s%s", QByteArray(LB_SetVal->text().toLocal8Bit()).data(),".");
                      	else
                      		sprintf((char *)keypadBuf, "%s%d", QByteArray(LB_SetVal->text().toLocal8Bit()).data(),val);
                      }
                      
                      SetValue = QString(keypadBuf);
                       My Problem >> LB_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();
                      
                      printf("[%s] %s\n", __FUNCTION__, keypadBuf);
                      

                      }

                      J.HilkJ Offline
                      J.HilkJ Offline
                      J.Hilk
                      Moderators
                      wrote on last edited by
                      #26

                      @sootoo23 Maybe you're doing the mapping wrong? I don't use it often, once in years I believe. So I'm not sure.

                      Since I'm assuming your running Qt 5.X try it with lambdas

                      replace

                      connect(ui->Keypad_Num0, SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                      connect(ui->Keypad_Num1, SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                      connect(ui->Keypad_Num2, SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                      connect(ui->Keypad_Num3, SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                      connect(ui->Keypad_Num4, SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                      connect(ui->Keypad_Num5, SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                      connect(ui->Keypad_Num6, SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                      connect(ui->Keypad_Num7, SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                      connect(ui->Keypad_Num8, SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                      connect(ui->Keypad_Num9, SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                      connect(ui->Keypad_Dot,  SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                      
                      KeyPadMapper.setMapping(ui->Keypad_Num0, 0);
                      KeyPadMapper.setMapping(ui->Keypad_Num1, 1);
                      KeyPadMapper.setMapping(ui->Keypad_Num2, 2);
                      KeyPadMapper.setMapping(ui->Keypad_Num3, 3);
                      KeyPadMapper.setMapping(ui->Keypad_Num4, 4);
                      KeyPadMapper.setMapping(ui->Keypad_Num5, 5);
                      KeyPadMapper.setMapping(ui->Keypad_Num6, 6);
                      KeyPadMapper.setMapping(ui->Keypad_Num7, 7);
                      KeyPadMapper.setMapping(ui->Keypad_Num8, 8);
                      KeyPadMapper.setMapping(ui->Keypad_Num9, 9);
                      KeyPadMapper.setMapping(ui->Keypad_Dot, 100);
                      
                      connect(&KeyPadMapper, SIGNAL(mapped(int)), this, SLOT(SetKeypadData(int)));
                      

                      with

                      connect(ui->Keypad_Num0, QPusButton::clicked, this, [=]{SetKeypadData(0);});
                      connect(ui->Keypad_Num1, QPusButton::clicked, this, [=]{SetKeypadData(1);});
                      connect(ui->Keypad_Num2, QPusButton::clicked, this, [=]{SetKeypadData(2);});
                      connect(ui->Keypad_Num3, QPusButton::clicked, this, [=]{SetKeypadData(3);});
                      connect(ui->Keypad_Num4, QPusButton::clicked, this, [=]{SetKeypadData(4);});
                      connect(ui->Keypad_Num5, QPusButton::clicked, this, [=]{SetKeypadData(5);});
                      connect(ui->Keypad_Num6, QPusButton::clicked, this, [=]{SetKeypadData(6);});
                      connect(ui->Keypad_Num7, QPusButton::clicked, this, [=]{SetKeypadData(7);});
                      connect(ui->Keypad_Num8, QPusButton::clicked, this, [=]{SetKeypadData(8);});
                      connect(ui->Keypad_Num9, QPusButton::clicked, this, [=]{SetKeypadData(9);});
                      connect(ui->Keypad_Dot,  QPusButton::clicked, this, [=]{SetKeypadData(100);});
                      

                      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                      Q: What's that?
                      A: It's blue light.
                      Q: What does it do?
                      A: It turns blue.

                      S 1 Reply Last reply
                      0
                      • J.HilkJ J.Hilk

                        @sootoo23 Maybe you're doing the mapping wrong? I don't use it often, once in years I believe. So I'm not sure.

                        Since I'm assuming your running Qt 5.X try it with lambdas

                        replace

                        connect(ui->Keypad_Num0, SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                        connect(ui->Keypad_Num1, SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                        connect(ui->Keypad_Num2, SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                        connect(ui->Keypad_Num3, SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                        connect(ui->Keypad_Num4, SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                        connect(ui->Keypad_Num5, SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                        connect(ui->Keypad_Num6, SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                        connect(ui->Keypad_Num7, SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                        connect(ui->Keypad_Num8, SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                        connect(ui->Keypad_Num9, SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                        connect(ui->Keypad_Dot,  SIGNAL(clicked()), &KeyPadMapper, SLOT(map()));
                        
                        KeyPadMapper.setMapping(ui->Keypad_Num0, 0);
                        KeyPadMapper.setMapping(ui->Keypad_Num1, 1);
                        KeyPadMapper.setMapping(ui->Keypad_Num2, 2);
                        KeyPadMapper.setMapping(ui->Keypad_Num3, 3);
                        KeyPadMapper.setMapping(ui->Keypad_Num4, 4);
                        KeyPadMapper.setMapping(ui->Keypad_Num5, 5);
                        KeyPadMapper.setMapping(ui->Keypad_Num6, 6);
                        KeyPadMapper.setMapping(ui->Keypad_Num7, 7);
                        KeyPadMapper.setMapping(ui->Keypad_Num8, 8);
                        KeyPadMapper.setMapping(ui->Keypad_Num9, 9);
                        KeyPadMapper.setMapping(ui->Keypad_Dot, 100);
                        
                        connect(&KeyPadMapper, SIGNAL(mapped(int)), this, SLOT(SetKeypadData(int)));
                        

                        with

                        connect(ui->Keypad_Num0, QPusButton::clicked, this, [=]{SetKeypadData(0);});
                        connect(ui->Keypad_Num1, QPusButton::clicked, this, [=]{SetKeypadData(1);});
                        connect(ui->Keypad_Num2, QPusButton::clicked, this, [=]{SetKeypadData(2);});
                        connect(ui->Keypad_Num3, QPusButton::clicked, this, [=]{SetKeypadData(3);});
                        connect(ui->Keypad_Num4, QPusButton::clicked, this, [=]{SetKeypadData(4);});
                        connect(ui->Keypad_Num5, QPusButton::clicked, this, [=]{SetKeypadData(5);});
                        connect(ui->Keypad_Num6, QPusButton::clicked, this, [=]{SetKeypadData(6);});
                        connect(ui->Keypad_Num7, QPusButton::clicked, this, [=]{SetKeypadData(7);});
                        connect(ui->Keypad_Num8, QPusButton::clicked, this, [=]{SetKeypadData(8);});
                        connect(ui->Keypad_Num9, QPusButton::clicked, this, [=]{SetKeypadData(9);});
                        connect(ui->Keypad_Dot,  QPusButton::clicked, this, [=]{SetKeypadData(100);});
                        
                        S Offline
                        S Offline
                        sootoo23
                        wrote on last edited by
                        #27

                        @J.Hilk said in Text is not updated in qwidget.:

                        @sootoo23 Maybe you're doing the mapping wrong? I don't use it often, once in years I believe. So I'm not sure.
                        Since I'm assuming your running Qt 5.X try it with lambdas
                        replace

                        mapping is not wrong.
                        The function connected is called well and the output from the function is coming out well.

                        J.HilkJ 1 Reply Last reply
                        0
                        • S sootoo23

                          @J.Hilk said in Text is not updated in qwidget.:

                          @sootoo23 Maybe you're doing the mapping wrong? I don't use it often, once in years I believe. So I'm not sure.
                          Since I'm assuming your running Qt 5.X try it with lambdas
                          replace

                          mapping is not wrong.
                          The function connected is called well and the output from the function is coming out well.

                          J.HilkJ Offline
                          J.HilkJ Offline
                          J.Hilk
                          Moderators
                          wrote on last edited by
                          #28

                          @sootoo23 you're going through a loot of loops to create your QString,
                          are you sure that QString(keypadBuf) returns a valid QString? and not an empty one for example?

                          as a side not this one, for example could be reduced

                          {		
                             if(val == 100) //dot.
                             	sprintf((char *)keypadBuf, "%s%s", QByteArray(LB_SetVal->text().toLocal8Bit()).data(),".");
                             else
                             	sprintf((char *)keypadBuf, "%s%d", QByteArray(LB_SetVal->text().toLocal8Bit()).data(),val);
                          }
                          SetValue = QString(keypadBuf);
                          LB_SetVal->setText(SetValue);
                          
                          //to
                          QString str = LB_SetVal->text() + val == 100 ? "." : QString::number(val);
                          
                          LB_SetVal->setText(str);
                          

                          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                          Q: What's that?
                          A: It's blue light.
                          Q: What does it do?
                          A: It turns blue.

                          S 1 Reply Last reply
                          0
                          • J.HilkJ J.Hilk

                            @sootoo23 you're going through a loot of loops to create your QString,
                            are you sure that QString(keypadBuf) returns a valid QString? and not an empty one for example?

                            as a side not this one, for example could be reduced

                            {		
                               if(val == 100) //dot.
                               	sprintf((char *)keypadBuf, "%s%s", QByteArray(LB_SetVal->text().toLocal8Bit()).data(),".");
                               else
                               	sprintf((char *)keypadBuf, "%s%d", QByteArray(LB_SetVal->text().toLocal8Bit()).data(),val);
                            }
                            SetValue = QString(keypadBuf);
                            LB_SetVal->setText(SetValue);
                            
                            //to
                            QString str = LB_SetVal->text() + val == 100 ? "." : QString::number(val);
                            
                            LB_SetVal->setText(str);
                            
                            S Offline
                            S Offline
                            sootoo23
                            wrote on last edited by
                            #29

                            @J.Hilk
                            The value is always good.
                            The problem is that settext can not be updated even if you put any value.

                            J.HilkJ 1 Reply Last reply
                            0
                            • S sootoo23

                              @J.Hilk
                              The value is always good.
                              The problem is that settext can not be updated even if you put any value.

                              J.HilkJ Offline
                              J.HilkJ Offline
                              J.Hilk
                              Moderators
                              wrote on last edited by
                              #30

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

                              @J.Hilk
                              The value is always good.
                              The problem is that settext can not be updated even if you put any value.

                              I'm sorry, but the problem is with 99.9% certainty not the setText function I would say 1 of 4 things is the case:

                              • LB_SetVal is invalid or wrong. Doubtful because you say you calculate the correct value
                              • SetValue = QString(keypadBuf); returns an invalid or incorrect string. You can test this by setting a breakpoint and debuging, or printing SetValue to the console. e.g qDebug() << SetValue;
                              • You're blocking the event loop and your ui doesnt get updated
                              • Maybe you have set bool QObject::blockSignals(bool block) to true somewhere that is messing things up

                              also, what Qt-Version and compiler is this btw?


                              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                              Q: What's that?
                              A: It's blue light.
                              Q: What does it do?
                              A: It turns blue.

                              S 1 Reply Last reply
                              2
                              • J.HilkJ J.Hilk

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

                                @J.Hilk
                                The value is always good.
                                The problem is that settext can not be updated even if you put any value.

                                I'm sorry, but the problem is with 99.9% certainty not the setText function I would say 1 of 4 things is the case:

                                • LB_SetVal is invalid or wrong. Doubtful because you say you calculate the correct value
                                • SetValue = QString(keypadBuf); returns an invalid or incorrect string. You can test this by setting a breakpoint and debuging, or printing SetValue to the console. e.g qDebug() << SetValue;
                                • You're blocking the event loop and your ui doesnt get updated
                                • Maybe you have set bool QObject::blockSignals(bool block) to true somewhere that is messing things up

                                also, what Qt-Version and compiler is this btw?

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

                                @J.Hilk

                                I found something strange.
                                 After changing the data to "Settext", execute hide () on the QWidget and show () again.
                                 I confirmed that it was updated.

                                1. LB_SetVal is always good.
                                  -> printf("LB_SetVal: %s, KeypadBuf: %s \n", QByteArray(LB_SetVal->text().toLocal8Bit()).data(),keypadBuf);
                                2. I removed all blockSignals.
                                  -> The QWidget in problem has no Timer and no BlockSignal.
                                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