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. How to treat multiple QLineEdit

How to treat multiple QLineEdit

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 3.9k 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.
  • Q Offline
    Q Offline
    QTDavid
    wrote on last edited by
    #1

    Hello,

    In my .ui file I have built a window where I have a lot of QLineEdit, as I need to get several single char inputs from the user (42 to be precise). I wanted to know if there was a way to change the following code to make it neater (with a loop possibly):

    @str.replace(0,1,ui->encodeIn->text());
    str.replace(1,1,ui->encodeIn_2->text());
    str.replace(2,1,ui->encodeIn_3->text());
    str.replace(3,1,ui->encodeIn_4->text());
    str.replace(4,1,ui->encodeIn_5->text());
    ...
    ...@

    In my case I want to replace the contents of the QString str with the inputs that I read from the QLineEdit boxes.
    I know I could make a single QLineEdit 42 characters long, but for the moment I would like to stick with 42 single char QLineEdit boxes.

    Any pointers?
    Thank You
    David

    1 Reply Last reply
    0
    • D Offline
      D Offline
      deimos
      wrote on last edited by
      #2

      First think comes into my mind is to group all and only your QLineEdits for example into a QWidget or QFrame, then you could try with a loop:

      @QObject *le;
      int n=0;
      foreach ( le, ui->your_new_QWidget_group.children() ) {
      str.replace(n,1, static_cast<QLineEdit *>( le )->text() );
      n++;
      }@

      regards

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        QTDavid
        wrote on last edited by
        #3

        I thought of that, but will I be able to access and control each member individually?

        1 Reply Last reply
        0
        • D Offline
          D Offline
          deimos
          wrote on last edited by
          #4

          yes, like you did with your first post:

          @str.replace(0,1,ui->encodeIn->text());@

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DerManu
            wrote on last edited by
            #5

            I guess you create those 42 line edits programmatically (and not by dragging 42 widgets in QtDesigner), so it should be no problem of obtaining a QList<QLineEdit*>. Then just iterate through the list and append the respective char to an empty string.

            //EDIT: Hah, well, you got answers already... obviously it took me 40 minutes to get to this tab in my browser ;)

            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