0
votes

I have a list of inputs from a csv document in a QListWidget, and I want to associate each item with an ID, so when I double click the specific item I can configure it. I tried with this "QListWidgetItem *item = rowData;", but it gave me an error. Code in the constructor:

 if (getin.open(QFile::ReadOnly)) {

    //Collect all data from the file
    items = getin.readAll();

    //Split all data line by line
     rowOfData = items.split("\n");

     //Close csv document
     getin.close();

} //Go through the data collected, and split them by two delimiters.
for (int x = 0; x < rowOfData.size(); x++)
{
    rowData = rowOfData.at(x).split(",").first().split(":");

    if(!rowData.isEmpty())
        ui->itemListWidget->addItem(rowData.first());
   QListWidgetItem *item = rowData;

}

The function for when an item is double-clicked:

void storage::on_itemListWidget_itemDoubleClicked(QListWidgetItem *item)
{
itemwindow = new itemWindow(this);
itemwindow->show();


}
1
What do you mean by configure it? Change the value? - Apin
So the QStringList holds different kind of data, a category, name and date. Which I would like to be able to configure in another file. - giggitygoat
What are you trying to achieve with QListWidgetItem *item = rowData;? - thuga
To see which item is double clicked, and thereby changing the QDialog accordingly to the item that is selected. - giggitygoat

1 Answers

0
votes

Let me try to answer. This will ofc error :

QListWidgetItem *item = rowData;

because rowData is a StringList not *QListWidgetitem.

If you want to get your full row data which is rowOfData. You can use the following slot :

void storage::on_itemListWidget_itemDoubleClicked(QListWidgetItem *item)
{
    QString yourRowData = rowOfData.at(ui->itemListWidget->row(item));
    itemwindow = new itemWindow(this);
    itemwindow->show();
}