Creating the line edits by code would get too complicated for me, I'm using a few stacked widgets.
As wysota and others have said, if you don't want to create the widgets in code, you can still retrieve their pointers and store them in a list or vector:
// In the constructor for each widget in the stack:
ui->setupUi( this );
pVector[ 0 ] = ui->t000;
pVector[ 1 ] = ui->t001;
// etc. for the next 98 line edits
// Then, you still retrieve the text for each widget using the vector
t[n] = pVector[n]->text().toDouble();
// In the constructor for each widget in the stack:
ui->setupUi( this );
pVector = new QVector< QLineEdit * >( 100 );
pVector[ 0 ] = ui->t000;
pVector[ 1 ] = ui->t001;
// etc. for the next 98 line edits
// Then, you still retrieve the text for each widget using the vector
t[n] = pVector[n]->text().toDouble();
To copy to clipboard, switch view to plain text mode
Edit: You could avoid the cut-and-paste if you are consistent in your names for the line edits. You can then use findChild, as Lesiok suggests:
for ( int i = 0; i < 100; i++ )
{
pVector
[ i
] = findChild<
QLineEdit * >
( name
);
}
pVector = new QVector< QLineEdit * >( 100 );
for ( int i = 0; i < 100; i++ )
{
QString name = QString( "t%1" ).arg( i, 3, '0' );
pVector[ i ] = findChild< QLineEdit * >( name );
}
To copy to clipboard, switch view to plain text mode
This assumes the line edits are named "t000", "t001", ... "t099".
Bookmarks