Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    [Solved] QPushButton change text

    General and Desktop
    4
    7
    44445
    Loading More Posts
    • 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
      ohope5 last edited by

      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 Reply Quote 0
      • Q
        QMartin last edited by

        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 Reply Quote 0
        • O
          ohope5 last edited by

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

          1 Reply Last reply Reply Quote 0
          • Q
            QMartin last edited by

            Hmmm

            Could you provide some more code if possible please?

            Thanks!

            1 Reply Last reply Reply Quote 0
            • Q
              qxoz last edited by

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

              M 1 Reply Last reply Reply Quote 1
              • O
                ohope5 last edited by

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

                1 Reply Last reply Reply Quote 0
                • M
                  mandybuot @qxoz last edited by

                  @qxoz nine years later, thankyou for this.

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post