[Solved] QPushButton change text



  • 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?



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



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



  • Hmmm

    Could you provide some more code if possible please?

    Thanks!



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



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.