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] Need help with QLineEdit
Forum Updated to NodeBB v4.3 + New Features

[solved] Need help with QLineEdit

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.1k Views 1 Watching
  • 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.
  • G Offline
    G Offline
    GoldyGuy
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      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.

      (Z(:^

      1 Reply Last reply
      0
      • G Offline
        G Offline
        GoldyGuy
        wrote on last edited by
        #3

        [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%.

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          You are welcome, happy coding :)

          (Z(:^

          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