QPushButton::text() returning another button's text
-
I have two QPushButtons in a simple app.
I create each with a different string.
Each button displays its own specific string.
Later however, when I read the strings out using text(), I find that they both provide the same string (that of the first button).
Does anyone know what might cause this?
I'm using Qt 5.15.2. -
@clarify
If Qt code incorrectly returned button texts don't you think the thousands [millions? ;-) ] of people who use it would have noticed?Your code is wrong. If you don't show your code (some minimal example) nobody can tell you where. Assuming your unshown code is correct and Qt code is wrong is "not productive", but up to you.
Hmm, looking at the code I don't think this is my bug after all.
I obtain a QString from each push button.
I convert it to a std::string.
I extract the C String from that and print it.The C String I'm getting is wrong, sometimes garbled depending on how I obtain it.
Update: OK the issue was with that conversion. Solved.
-
I have two QPushButtons in a simple app.
I create each with a different string.
Each button displays its own specific string.
Later however, when I read the strings out using text(), I find that they both provide the same string (that of the first button).
Does anyone know what might cause this?
I'm using Qt 5.15.2.@clarify said in QPushButton::text() returning another button's text:
Does anyone know what might cause this?
You did something wrong. Please show us the relevant code.
-
@clarify said in QPushButton::text() returning another button's text:
Does anyone know what might cause this?
You did something wrong. Please show us the relevant code.
@Christian-Ehrlicher I don't think I did. What happens is, if I click on button A, the text returned for buttons B or C is that of button A. It's like Qt is caching the text somewhere. I'm printing to the terminal the text of each button as well as the pointer to each QPushButton and the pointers differ but the text does not. And yet what is displayed inside each button in the GUI is different.
-
@Christian-Ehrlicher I don't think I did. What happens is, if I click on button A, the text returned for buttons B or C is that of button A. It's like Qt is caching the text somewhere. I'm printing to the terminal the text of each button as well as the pointer to each QPushButton and the pointers differ but the text does not. And yet what is displayed inside each button in the GUI is different.
@clarify
If Qt code incorrectly returned button texts don't you think the thousands [millions? ;-) ] of people who use it would have noticed?Your code is wrong. If you don't show your code (some minimal example) nobody can tell you where. Assuming your unshown code is correct and Qt code is wrong is "not productive", but up to you.
-
@Christian-Ehrlicher I don't think I did. What happens is, if I click on button A, the text returned for buttons B or C is that of button A. It's like Qt is caching the text somewhere. I'm printing to the terminal the text of each button as well as the pointer to each QPushButton and the pointers differ but the text does not. And yet what is displayed inside each button in the GUI is different.
-
I bet there is something wrong with your connection. Maybe typo?
I assume you connect all three buttons and print the text. Maybe code copied for all three and vars not changed or misspelled so that you see the text of the same button.@Pl45m4 said in QPushButton::text() returning another button's text:
I assume you connect all three buttons and print the text. Maybe code copied for all three and vars not changed or misspelled so that you see the text of the same button.
Correction:
These are widget objects, so obtaining the text involves calling the text() method of each.
Yes, I do connect via the click signal, from that point I print the object's text. -
@Pl45m4 said in QPushButton::text() returning another button's text:
I assume you connect all three buttons and print the text. Maybe code copied for all three and vars not changed or misspelled so that you see the text of the same button.
Correction:
These are widget objects, so obtaining the text involves calling the text() method of each.
Yes, I do connect via the click signal, from that point I print the object's text. -
@clarify
If Qt code incorrectly returned button texts don't you think the thousands [millions? ;-) ] of people who use it would have noticed?Your code is wrong. If you don't show your code (some minimal example) nobody can tell you where. Assuming your unshown code is correct and Qt code is wrong is "not productive", but up to you.
Hmm, looking at the code I don't think this is my bug after all.
I obtain a QString from each push button.
I convert it to a std::string.
I extract the C String from that and print it.The C String I'm getting is wrong, sometimes garbled depending on how I obtain it.
Update: OK the issue was with that conversion. Solved.
-
Hmm, looking at the code I don't think this is my bug after all.
I obtain a QString from each push button.
I convert it to a std::string.
I extract the C String from that and print it.The C String I'm getting is wrong, sometimes garbled depending on how I obtain it.
Update: OK the issue was with that conversion. Solved.
Show the code, provide an example for others to reproduce it, or it doesnt happened :)
If it would be like you said, millions of Qt users and devs would face the same behavior. Like @JonB and @Christian-Ehrlicher said, I doubt that it is a bug in Qt ifself and not something wrong with your code -