Search code examples
c++qtqlistwidget

Qt C++ | how can I get the string data that is linked to the index when I click an item in a QListWidget?


I have this slot and I want to be able to use the string that is at the index being passed through. How can I get to it?

void Dialog::on_list_Favorites_2_clicked(const QModelIndex &index)
{

}

Solution

  • Since you're using QListWidget instead of QListView you should also use the signal itemClicked(QListWidgetItem*) instead of clicked(const QModelIndex &).

    void Dialog::on_list_Favorites_2_itemClicked(QListWidgetItem* item)
    {
        qDebug() << item->text();
    }