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. Replacing a character in a QLineEdit text
Forum Updated to NodeBB v4.3 + New Features

Replacing a character in a QLineEdit text

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 2.5k 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.
  • P Offline
    P Offline
    phil63
    wrote on last edited by
    #1

    Hi,

    To simplify, I am using a QlineEdit line that contains : PRTU
    I would like to replace the character 'R' by ' S'.
    I tried :
    line.text().replace('R','S') But it seems not to work.
    I tried also:
    text=""
    if(line.text().contains('P') text=text+"P";
    if (line.text().contains('R') text=text+"S"
    if(line.text().contains('T') text=text+"T";
    if(line.text().contains('U') text=text+"U";
    line.setText(text);
    but with no avail.
    Could you help me, please

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

      @
      QString text = line.text();
      text.replace("R", "S");
      line.setText(text);
      @

      That should work.

      (Z(:^

      1 Reply Last reply
      0
      • P Offline
        P Offline
        phil63
        wrote on last edited by
        #3

        Thank you for your reply.
        As you advised I wrote:

        QString text=line.text();
        text.replace('R','S');
        line.setText(text);

        But the computer erases the charactere 'R' but put nothing instead.
        What do I do wrong?
        Thank you

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

          I don't know. Code looks ok.

          (Z(:^

          1 Reply Last reply
          0
          • P Offline
            P Offline
            phil63
            wrote on last edited by
            #5

            I found my mistake. I feel so stupid.
            I made the changes in a constructor window that it not read at the beginning.
            Well sorry for my stupidity.
            Thanks for your help.

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

              No problem, we all make mistakes in our apps :)

              (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