Results 1 to 5 of 5

Thread: problem with ui->pushButton->text()

  1. #1
    Join Date
    Jan 2012
    Posts
    15
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default problem with ui->pushButton->text()

    hy,
    i'm trying to create my first GUI application, I wanted to create a simple timer application, there is just one button on the interface with START write on it, when I press it I want my timer to start and the text to be changed in STOP. I can manage this, the problem is that when the text is STOP I want the timer to stop, to do this I have to undestrand if the button has got START or STOP write in it. I tried with
    Qt Code:
    1. void MainWindow::on_pushButton_clicked()
    2. {
    3. if(ui->pushButton->text()=="START")
    4. {
    5. ui->pushButton->setText("STOP");
    6. }
    7. else if(ui->pushButton->text()=="STOP")
    8. {
    9. ui->pushButton->setText("START");
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 
    but none of this statements seems to be true!
    can someone help me?
    thank's

  2. #2
    Join Date
    Jan 2012
    Location
    Argentina
    Posts
    167
    Thanks
    33
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem with ui->pushButton->text()

    try this...
    Qt Code:
    1. void MainWindow::on_pushButton_clicked()
    2. {
    3. if(ui->pushButton->text()== QString ("START"))
    4. {
    5. ui->pushButton->setText("STOP");
    6. }
    7. else if(ui->pushButton->text()== QString ("STOP"))
    8. {
    9. ui->pushButton->setText("START");
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

    but post all the code where you set the names please maybe its up the problem.,,,

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: problem with ui->pushButton->text()

    Quote Originally Posted by sax94 View Post
    but none of this statements seems to be true!
    can someone help me?
    ... then the button text is neither "START" nor "STOP". What do you want us to do about it? Have you thought to look at what the button text actually is? Perhaps the text is "&START" because you set a shortcut character. Perhaps the text is actually "Start". Perhaps this code is never reached.

  4. #4
    Join Date
    Jan 2012
    Posts
    15
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem with ui->pushButton->text()

    thank's for your help, solved the problem, don't know why, tried to restart everything and worked just fine!

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: problem with ui->pushButton->text()

    Changing the button text like that is not a very clever solution. Better have two buttons and either disable or hide one of them when the other one is active.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. vertical pushbutton text
    By eric in forum Qt Programming
    Replies: 11
    Last Post: 18th April 2019, 19:17
  2. How to resize pushbutton to fit text?
    By Dreamerzz in forum Qt Programming
    Replies: 9
    Last Post: 16th May 2012, 13:01
  3. How to resize pushbutton to fit text in mac os
    By tintu in forum Qt Programming
    Replies: 1
    Last Post: 1st December 2011, 13:41
  4. left alignment for pushbutton text
    By BalaQT in forum Qt Programming
    Replies: 7
    Last Post: 22nd September 2009, 08:41
  5. Wrap Text in PUSHBUTTON
    By BalaQT in forum Qt Programming
    Replies: 2
    Last Post: 16th September 2009, 13:54

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.