from the other thread
Amleto, Yes i do use the designer, but of coruse i dont use lineedit1,...lineeditn to name my objects,I do use meaningful names.
The point is not the suitability of names, but the fact that there are so many.
If you design in designer, and then want to link lineedits to labels, you have to 'hard code' it using the variable names you gave each individual element in the designer.
If you do it in code you don't need to worry about variable names and you can set up a short factory pattern or loop that can deal with any number of elements.
e.g.
you have designed a form with a bunch of lineedits and then you need to connect them in a class ctor you end up with code like this
classX::classX()
{
connect(ui->lineedit1, SIGNAL(...), w1, SLOT(...));
connect(ui->lineedit2, SIGNAL(...), w1, SLOT(...));
connect(ui->lineedit3, SIGNAL(...), w1, SLOT(...));
connect(ui->lineedit4, SIGNAL(...), w1, SLOT(...));
connect(ui->lineedit5, SIGNAL(...), w1, SLOT(...));
}
classX::classX()
{
QWidget* w1 = new QWidget;
connect(ui->lineedit1, SIGNAL(...), w1, SLOT(...));
QWidget* w2 = new QWidget;
connect(ui->lineedit2, SIGNAL(...), w1, SLOT(...));
QWidget* w3 = new QWidget;
connect(ui->lineedit3, SIGNAL(...), w1, SLOT(...));
QWidget* w4 = new QWidget;
connect(ui->lineedit4, SIGNAL(...), w1, SLOT(...));
QWidget* w5 = new QWidget;
connect(ui->lineedit5, SIGNAL(...), w1, SLOT(...));
}
To copy to clipboard, switch view to plain text mode
c.f.
classX::classX()
{
for (int i = 0; i < N; ++i)
{
connect(le, SIGNAL(...), w, SLOT(...));
}
}
classX::classX()
{
for (int i = 0; i < N; ++i)
{
QLineEdit* le = new QLineEdit;
QWidget* w = new QWidget;
connect(le, SIGNAL(...), w, SLOT(...));
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks