PDA

View Full Version : foreach QTextEdit in Layout



slc
1st September 2010, 23:52
I dynamically added QTextEdit items in a particular layout (QGrigLayout).
Later I want to to extract the values of each QTextEdit item and merge them into a single QString.

Any thoughts?

The following does not work:
QString msg;
QLayoutItem *item;
foreach (item, ui->toPlainText)
{
msg+= item->text();
}

slc
2nd September 2010, 00:45
Ok I did the following as a work around (is there a better method?):

// Create a list of QTextEdit
QList<QTextEdit *> list;

// Everytime I create a new QTextEdit, I add it to the 'list'
QTextEdit *qe = new QTextEdit();
pageEdits.append(qe);


// Then I iterate through the list:
QString combined;
foreach (QTextEdit *q, list)
{
combined.append(q->toPlainText());
}