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. QLabel doesn't change text on Ui, text() method returns changed value

QLabel doesn't change text on Ui, text() method returns changed value

Scheduled Pinned Locked Moved Solved General and Desktop
ui objectwidgetsnamespace
8 Posts 3 Posters 1.9k 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.
  • A Offline
    A Offline
    artwaw
    wrote on 22 Sept 2021, 15:05 last edited by artwaw
    #1

    Good afternoon,
    I have another silly error.

    Background:
    My small program sends ICMP packets using Windows API, then analyses the response.
    I had a few problems with implementing it, first I used standalone MSYS2 WinAPI libs, then switched to the ones provided by Qt.
    It worked, I focused on different parts of the program, then suddenly started to get over 1.5k errors, first that in c++config.h namespace std expected class and then series of type mismatches etc.
    I moved ICMP to the dll (descendant of QObject class) and use it that way, errors are gone.

    The problem:
    after fixing the above issues, two labels in UI stopped updating. I set their value (ui->conLabel->setText(QString::number(counter)); where counter is int), after settings I put

    qDebug() << counter << ui->conLabel->text() << QString::number(counter);
    

    to make sure everything is OK, response from that is correct:

    3 "3" "3"
    

    as I use three test cases for now, but Ui still shows "textLabel" in them.
    Funnily enough the Ui is not blocked, all the buttons work flawlessly, I can run the tests, change language via retranslateUI etc. Code completion works for those two too.

    Whiskey, Tango, Foxtrot, so to speak.
    I can provide the code, of course, but don't even know which part of it should I provide.

    Can anyone point me in towards possible solution here?
    Any hints much appreciated.

    Thank you,
    A.

    EDIT: It is Qt 5.15.2, unfortunately for Windows.

    For more information please re-read.

    Kind Regards,
    Artur

    J 1 Reply Last reply 22 Sept 2021, 15:46
    0
    • A artwaw
      22 Sept 2021, 15:05

      Good afternoon,
      I have another silly error.

      Background:
      My small program sends ICMP packets using Windows API, then analyses the response.
      I had a few problems with implementing it, first I used standalone MSYS2 WinAPI libs, then switched to the ones provided by Qt.
      It worked, I focused on different parts of the program, then suddenly started to get over 1.5k errors, first that in c++config.h namespace std expected class and then series of type mismatches etc.
      I moved ICMP to the dll (descendant of QObject class) and use it that way, errors are gone.

      The problem:
      after fixing the above issues, two labels in UI stopped updating. I set their value (ui->conLabel->setText(QString::number(counter)); where counter is int), after settings I put

      qDebug() << counter << ui->conLabel->text() << QString::number(counter);
      

      to make sure everything is OK, response from that is correct:

      3 "3" "3"
      

      as I use three test cases for now, but Ui still shows "textLabel" in them.
      Funnily enough the Ui is not blocked, all the buttons work flawlessly, I can run the tests, change language via retranslateUI etc. Code completion works for those two too.

      Whiskey, Tango, Foxtrot, so to speak.
      I can provide the code, of course, but don't even know which part of it should I provide.

      Can anyone point me in towards possible solution here?
      Any hints much appreciated.

      Thank you,
      A.

      EDIT: It is Qt 5.15.2, unfortunately for Windows.

      J Offline
      J Offline
      JonB
      wrote on 22 Sept 2021, 15:46 last edited by
      #2

      @artwaw
      You are asking us to stick a needle in a haystack and to whistle in the wind ;-)

      The most obvious first thought is: the UI element you are changing code is not the element you are seeing on the screen, for whatever reason. All you have tried is setText(). Change its color, or more pertinently delete it --- does it disappear?

      A 1 Reply Last reply 22 Sept 2021, 16:03
      0
      • J JonB
        22 Sept 2021, 15:46

        @artwaw
        You are asking us to stick a needle in a haystack and to whistle in the wind ;-)

        The most obvious first thought is: the UI element you are changing code is not the element you are seeing on the screen, for whatever reason. All you have tried is setText(). Change its color, or more pertinently delete it --- does it disappear?

        A Offline
        A Offline
        artwaw
        wrote on 22 Sept 2021, 16:03 last edited by artwaw
        #3

        @JonB Delete as in remove from Ui in design mode? I tried.
        I also deleted the build folders, tried in Debug/Release, verified if it is present in ui_(class_name).h (it is)...

        it is also properly constructed in the ui_.h file:

                conLabel = new QLabel(groupBox);
                conLabel->setObjectName(QString::fromUtf8("conLabel"));
                conLabel->setGeometry(QRect(686, 20, 71, 31));
        

        But - to satisfy you - I added ui->conLabel->hide(); to one of the buttons and indeed, after pressing that button is becomes hidden.

        EDIT:

        All you have tried is setText()

        Nah, I also tried text() after setting, I wrote that above.

        For more information please re-read.

        Kind Regards,
        Artur

        J 1 Reply Last reply 22 Sept 2021, 16:14
        0
        • A artwaw
          22 Sept 2021, 16:03

          @JonB Delete as in remove from Ui in design mode? I tried.
          I also deleted the build folders, tried in Debug/Release, verified if it is present in ui_(class_name).h (it is)...

          it is also properly constructed in the ui_.h file:

                  conLabel = new QLabel(groupBox);
                  conLabel->setObjectName(QString::fromUtf8("conLabel"));
                  conLabel->setGeometry(QRect(686, 20, 71, 31));
          

          But - to satisfy you - I added ui->conLabel->hide(); to one of the buttons and indeed, after pressing that button is becomes hidden.

          EDIT:

          All you have tried is setText()

          Nah, I also tried text() after setting, I wrote that above.

          J Offline
          J Offline
          JonB
          wrote on 22 Sept 2021, 16:14 last edited by
          #4

          @artwaw
          So try attributes other than text, e.g. color like I said.

          If it is only the text, then maybe attach a slot to textChanged signal to make sure something else is not setting to back?

          A 1 Reply Last reply 22 Sept 2021, 16:17
          0
          • J JonB
            22 Sept 2021, 16:14

            @artwaw
            So try attributes other than text, e.g. color like I said.

            If it is only the text, then maybe attach a slot to textChanged signal to make sure something else is not setting to back?

            A Offline
            A Offline
            artwaw
            wrote on 22 Sept 2021, 16:17 last edited by
            #5

            @JonB I will try those and get back here, thank you.

            For more information please re-read.

            Kind Regards,
            Artur

            1 Reply Last reply
            0
            • A Offline
              A Offline
              artwaw
              wrote on 22 Sept 2021, 16:37 last edited by
              #6

              Ok, so I tried changing the text attributes (colour, font, etc - to no avail). hide() and show() worked. I got mad and removed them, put QSpinBox in read only mode instead and it works.

              Although it doesn't matter how I show the values (spin box looks a bit out of place but nobody cares as long as it works) - I was hoping to understand what was going on. :(

              For more information please re-read.

              Kind Regards,
              Artur

              J 1 Reply Last reply 23 Sept 2021, 06:15
              1
              • A artwaw
                22 Sept 2021, 16:37

                Ok, so I tried changing the text attributes (colour, font, etc - to no avail). hide() and show() worked. I got mad and removed them, put QSpinBox in read only mode instead and it works.

                Although it doesn't matter how I show the values (spin box looks a bit out of place but nobody cares as long as it works) - I was hoping to understand what was going on. :(

                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 23 Sept 2021, 06:15 last edited by
                #7

                @artwaw said in QLabel doesn't change text on Ui, text() method returns changed value:

                I was hoping to understand what was going on

                One possibility would be that you're blocking the event loop somewhere after setting the text, so the UI can't update the label.

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

                A 1 Reply Last reply 23 Sept 2021, 08:14
                1
                • J jsulm
                  23 Sept 2021, 06:15

                  @artwaw said in QLabel doesn't change text on Ui, text() method returns changed value:

                  I was hoping to understand what was going on

                  One possibility would be that you're blocking the event loop somewhere after setting the text, so the UI can't update the label.

                  A Offline
                  A Offline
                  artwaw
                  wrote on 23 Sept 2021, 08:14 last edited by
                  #8

                  @jsulm That came to my mind too but considering that all the other parts of Ui work - push buttons, tool buttons, all the actions associated with tool buttons and menu, two table views with sql table models, status bar displays status tips on hover over elements... I had to ditch that idea.

                  For more information please re-read.

                  Kind Regards,
                  Artur

                  1 Reply Last reply
                  0

                  2/8

                  22 Sept 2021, 15:46

                  topic:navigator.unread, 6
                  • Login

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