QLabel doesn't change text on Ui, text() method returns changed value
-
wrote on 22 Sept 2021, 15:05 last edited by artwaw
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.hnamespace 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 putqDebug() << 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.
-
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.hnamespace 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 putqDebug() << 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.
wrote on 22 Sept 2021, 15:46 last edited by@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? -
@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?wrote on 22 Sept 2021, 16:03 last edited by artwaw@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. -
@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. -
@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? -
wrote on 22 Sept 2021, 16:37 last edited by
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. :(
-
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. :(
@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.
-
@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.
wrote on 23 Sept 2021, 08:14 last edited by@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.
1/8