[solved] Need help with QLineEdit



  • Hello!
    I am a person who loves to "learn by discovery" and I've done a decent job so far.
    Here is a picture of my current project:

    The problem is, when I type "Start", the text changes as I need,
    but when I try to type "Yes", the text won't change.
    Code:
    @
    void PlayingScreen::on_lineEdit_returnPressed()
    {
    QString lineEditText = ui->lineEdit->text();
    if(lineEditText == "Start")
    {
    ui->lineEdit->clear();
    ui->textEdit->setText("Ugh...my head hurts...\n\n"
    "How long was I knocked out?\n\n"
    "Shady man: Ahh! you're finally awake.You were knocked out for a couple of hours.As you can see, we are in a prison cell right now.Wanna get out?\n\n");
    on_lineEdit_returnPressed();
    if(lineEditText2 == "Yes")
    {
    ui->lineEdit->clear();
    ui->textEdit->setText("Shady man: Great! follow me, hurry!");
    }
    }

    }
    

    @

    Could someone please tell me how can I accept input more than 2 times on QLineEdit and change the text accordingly?


  • Moderators

    Your "if" statements are nested (the "yes" one is inside the "start" one). This means that both need to be true for "Yes" to take effect, because the program will first check if the text equals "Start" and only if that is true it will continue checking for "Yes".

    The solution is to move the secon "if" outside of the first one. You can also delete the call to on_lineEdit_returnPressed(), as it is completely unnecessary.



  • [quote author="sierdzio" date="1405669473"]Your "if" statements are nested (the "yes" one is inside the "start" one). This means that both need to be true for "Yes" to take effect, because the program will first check if the text equals "Start" and only if that is true it will continue checking for "Yes".

    The solution is to move the secon "if" outside of the first one. You can also delete the call to on_lineEdit_returnPressed(), as it is completely unnecessary.[/quote]

    Thanks, that works 100%.


  • Moderators

    You are welcome, happy coding :)


Log in to reply
 

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