How to treat multiple QLineEdit
-
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 -
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
-
I thought of that, but will I be able to access and control each member individually?
-
yes, like you did with your first post:
@str.replace(0,1,ui->encodeIn->text());@
-
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 ;)