Reputation: 87
I create A list widget in which I add items...my items are the filenames. Is any way to store the filepaths of this filenames? I want to know how to set a specific value to an item in the listwidget?
Upvotes: 1
Views: 1216
Reputation: 2161
You can use:
ListWidgetItem::setData(int role,Qvariant data);
to store your filePath;
like this:
QString fileName = "hello.txt";
QString filePath = "/home/user/hello.txt";
//Adding to listWidget
QListWidgetItem *item =new QListWidgetItem();
item->setText(fileName);
item->setData(1,filePath);//here role is set as 1
listWidget->addItem(item);
//For taking back that filePath
QString filePath = listWidget->currentItem()->data(1); //note::: role equals 1
Upvotes: 1