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. [Solved] QPushButton change text
QtWS25 Last Chance

[Solved] QPushButton change text

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 48.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.
  • O Offline
    O Offline
    ohope5
    wrote on last edited by
    #1

    I am trying to make it so that when the pushButton is clicked the text on it changes. At the moment my programming in the slot is
    @Ui_MainWindow::pushButton->setText("helloworld");@
    When I compile the code it says: Invalid use of non-static data member 'pushButton'
    How do I get around this problem?

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      QMartin
      wrote on last edited by
      #2

      Hello

      I think you shouldn't access your pushButton like that, it's not a static member. Try with

      @Ui_MainWindow->pushButton->setText("clicked")@

      Or

      @Ui_MainWindow.pushButton->setText("clicked")@

      Whether your Ui_mainWindow is created on heap or stack. Does this work?

      Regards.

      PS: next time, type your code between "@", that will make things neat and clear.

      1 Reply Last reply
      0
      • O Offline
        O Offline
        ohope5
        wrote on last edited by
        #3

        Thanks, but unfortunately this doen't work either. The compiler now gives the error: "expected unqualified-id" for both options.

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          QMartin
          wrote on last edited by
          #4

          Hmmm

          Could you provide some more code if possible please?

          Thanks!

          1 Reply Last reply
          0
          • Q Offline
            Q Offline
            qxoz
            wrote on last edited by
            #5

            Do this:
            @ui->pushButton->setText("clicked")@

            M 1 Reply Last reply
            1
            • O Offline
              O Offline
              ohope5
              wrote on last edited by
              #6

              Thanks, that worked. I see what I was doing wrong now.

              1 Reply Last reply
              0
              • Q qxoz

                Do this:
                @ui->pushButton->setText("clicked")@

                M Offline
                M Offline
                mandybuot
                wrote on last edited by
                #7

                @qxoz nine years later, thankyou for this.

                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