[QUOTE=Santosh Reddy;241542]All items in a QLayout may not be QLineEdits (not event QWidgets), there are some layout space management items (which are QWidgets/QLineEdits). You need to take text() only from valid QLineEdit items, also I am wondring why does you program does not crash !
Do something like this
for(int i = 0; i < iCount; i++)
{
QLineEdit* pLineEdit
= dynamic_cast<QLineEdit
*>
(pLine
->widget
());
//<<<<<<<<<<<<<<<<<<<
if(pLineEdit != 0) //<<<<<<<<<<<<<<<<<<<
{
str = pLineEdit->text();
ui->listWidget->addItem(str);
}
qDebug() << str;
}
for(int i = 0; i < iCount; i++)
{
QLayoutItem* pLine = ui->gridLayout->itemAt(i);
QLineEdit* pLineEdit = dynamic_cast<QLineEdit*>(pLine->widget()); //<<<<<<<<<<<<<<<<<<<
if(pLineEdit != 0) //<<<<<<<<<<<<<<<<<<<
{
str = pLineEdit->text();
ui->listWidget->addItem(str);
}
qDebug() << str;
}
To copy to clipboard, switch view to plain text mode
[/QUxtOTE]
Thanks but this does not solve my problem. The qlistwidget still adds extra spacing inbetween each text. This is a problem because if i want to read all the text in, I would be reading some spacing. How do i dynamically delete the text that was added? Right now the program is storing the text in a variable called str but I want to delete it from the qlistwidget and later read the text values in from there.
Bookmarks