Hello,
I'm developing an app that has 100 line edits.
I named them t001, t002, t003, ..., t100
I want to convert the value of each text in the line edits to double (no problem there) and save it in a vector, called t[].
I don't want to repeat the following code a hundred times over:
double t[100];
int count1 = 0;
if(ui->t001->text() != "")
{
t[count1] = ui->t001->text().toDouble();
count1++;
}
double t[100];
int count1 = 0;
if(ui->t001->text() != "")
{
t[count1] = ui->t001->text().toDouble();
count1++;
}
To copy to clipboard, switch view to plain text mode
So, is there anyway I can use the name of the object as a string variable, so I can use a loop? Like:
double t[100];
int count1 = 0;
for(count1 = 0; count1 < 100; count1++)
{
current_element = "t" + count1+1;
if(ui->current_element->text() != "")
t[count1] = ui->current_element->text().toDouble();
}
double t[100];
int count1 = 0;
QString current_element;
for(count1 = 0; count1 < 100; count1++)
{
current_element = "t" + count1+1;
if(ui->current_element->text() != "")
t[count1] = ui->current_element->text().toDouble();
}
To copy to clipboard, switch view to plain text mode
edited: I know this code wouldn't work and needs adapting in at least 2 parts, but still, what I need answered is the main question in the thread.
Thanks in advance.
Bookmarks