You can always create an array of QWidget pointers, but not QWidget instances themselves. This is because QWidget has no public copy constructor or assignment operator.
// You can do this:
// but not this:
// You can do this:
QVector< QWidget * > widgetVector;
// but not this:
QVector< QWidget > forbiddenVec;
To copy to clipboard, switch view to plain text mode
You can't create such a vector of pointers using Qt Designer; you can only do it in code. You -can- use Qt Designer to lay out your GUI using individual widgets, and then after you call setupUi() in the form's constructor, you can push copies of the pointers (not new widgets) onto a list or vector if it is more convenient to access them by index:
MyWidget
::MyWidget( QWidget * parent
) : BaseWidget
( parent
){
ui->setupUi();
widgetVector.push_back( ui->textEdit0 );
widgetVector.push_back( ui->textEdit1 );
// and so on
// later, you can get the nth text edit by
// which is the same as
}
MyWidget::MyWidget( QWidget * parent ) : BaseWidget( parent )
{
ui->setupUi();
widgetVector.push_back( ui->textEdit0 );
widgetVector.push_back( ui->textEdit1 );
// and so on
// later, you can get the nth text edit by
QTextEdit * pNth = widgetVector[ n ];
// which is the same as
QTextEdit * pNth = ui->textEditN;
}
To copy to clipboard, switch view to plain text mode
Bookmarks