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. QPushButton::text() returning another button's text

QPushButton::text() returning another button's text

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 4 Posters 584 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.
  • C Offline
    C Offline
    clarify
    wrote on last edited by
    #1

    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.

    Christian EhrlicherC 1 Reply Last reply
    0
    • JonBJ JonB

      @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.

      C Offline
      C Offline
      clarify
      wrote on last edited by clarify
      #8

      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.

      Pl45m4P 1 Reply Last reply
      0
      • C clarify

        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.

        Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #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.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        C 1 Reply Last reply
        2
        • Christian EhrlicherC Christian Ehrlicher

          @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.

          C Offline
          C Offline
          clarify
          wrote on last edited by clarify
          #3

          @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.

          JonBJ Pl45m4P 2 Replies Last reply
          0
          • C clarify

            @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.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #4

            @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.

            C 1 Reply Last reply
            2
            • C clarify

              @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.

              Pl45m4P Offline
              Pl45m4P Offline
              Pl45m4
              wrote on last edited by
              #5

              @clarify

              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.


              If debugging is the process of removing software bugs, then programming must be the process of putting them in.

              ~E. W. Dijkstra

              C 1 Reply Last reply
              0
              • Pl45m4P Pl45m4

                @clarify

                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.

                C Offline
                C Offline
                clarify
                wrote on last edited by clarify
                #6

                @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.

                Pl45m4P 1 Reply Last reply
                0
                • C clarify

                  @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.

                  Pl45m4P Offline
                  Pl45m4P Offline
                  Pl45m4
                  wrote on last edited by
                  #7

                  @clarify

                  What? Dont understand what you are saying there but as being said before, when you dont want to show what you've really done, nobody is able to provide useful help


                  If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                  ~E. W. Dijkstra

                  1 Reply Last reply
                  0
                  • JonBJ JonB

                    @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.

                    C Offline
                    C Offline
                    clarify
                    wrote on last edited by clarify
                    #8

                    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.

                    Pl45m4P 1 Reply Last reply
                    0
                    • C clarify

                      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.

                      Pl45m4P Offline
                      Pl45m4P Offline
                      Pl45m4
                      wrote on last edited by
                      #9

                      @clarify

                      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


                      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                      ~E. W. Dijkstra

                      1 Reply Last reply
                      1
                      • C clarify has marked this topic as solved on

                      • Login

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