How to move content from QListWidget to a QStringList with PyQt4?
-
13-06-2021 - |
Question
I have a dialog in which a user selects the files that needs, it adds (via QPushButton) in a QListWidget, my problem it's that I need to recover all the files from the QListWidget in a QStringList.
I tried like this, but something is wrong:
self.file = QtCore.QStringList()
archivos = self.file
cuenta = self.ventana.listWidget.count()
for index in range(cuenta):
archivos.append(self.ventana.listWidget.item(index))
Solution
I think you're missing .text()
after the item:
self.file = QtCore.QStringList()
archivos = self.file
cuenta = self.ventana.listWidget.count()
for index in range(cuenta):
archivos.append(self.ventana.listWidget.item(index).text())
OTHER TIPS
As I understood, you need to add the selected item text value to a QStringList. Here's how to do it.
QStringList *mList = new QStringList();
QString currItem = ui->listWidget->currentItem()->text();
mList->append(currItem);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow