PDA

View Full Version : using QStringList as QList<QListWidgetItem*>



geleven
8th April 2010, 17:26
dear all,

i have some problem, which is described by code below :



void lists::removeList()
{
QStringList temp = this->readListDoc();
QStringList removes = this->ui->ListPic->selectedItems();
//this->ui->ListPic->clear();
}


ListPic is a QListWidget, and the function selectedItems() suppose to return a QList<QListWidgetItem*>. The problem is i want to use QList<QListWidgetItem*> as a QStringList.

the error give statement like this
conversion from 'QList<QListWidgetItem*>' to non-scalar type 'QStringList' requested.

how i can solve this problem?

Lykurg
8th April 2010, 17:44
It seems that you do some simple things very complicated... But anyway:
QStringList removes;
QList<QListWidgetItem*> tmpList = this->ui->ListPic->selectedItems();
for (int i = 0; i < tmpList.size(); ++i)
removes.append(tmpList.at(i)->text());

^NyAw^
8th April 2010, 17:44
Hi,

You can't. QStringList is QList<QString> and QListWidget is QList<QListWidgetItem*>. So it's impossible to convert QListWidgetItem pointers to QStrings.
Maybe if you ask what your code is suposed to do we could help you.

geleven
8th April 2010, 19:13
It seems that you do some simple things very complicated... But anyway:
QStringList removes;
QList<QListWidgetItem*> tmpList = this->ui->ListPic->selectedItems();
for (int i = 0; i < tmpList.size(); ++i)
removes.append(tmpList.at(i)->text());

woah... it's that simple.. it seems i thinking too far away.. thanks for the help