Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to get multiple selected Items from a QListwidget



  • Hello everyone,

    in my GUI I have a QListwidget called TargetList.
    09eff2de-3e0c-4fde-bb35-45e24bb02133-image.png

    After starting the search I get a List of the available Devices. Now the User can choose to which Devices he wants to connet. Till now I had no problem with only one Target.

    But if the User selects multiple Targets I need a List of the Devices he selected so I can adapt the actions to be done for multiple Devices. The Question is how to get that List? I enabled multiple Selections in Qt Creator.

    I tried the following Code

    connect(ui->TargetList, SIGNAL(itemSelectionChange()), this, SLOT(SelectedTargets()));
    

    Whenever the Selection changes the Signal fires and the Slot i have the following Lines:

    QStringList ListSelected;
    QString selected = ui->TargetList->currentItem()->text();
    printf(selected.toStdString().c_str());
    ListSelected.append(selected);
    

    This should construct the needed List. But when Running i get the error that there's no such Signal as itemselectionchanged().

    Thanks !



  • @JohnSRV said in How to get multiple selected Items from a QListwidget:

    connect(ui->TargetList, SIGNAL(itemSelectionChange()), this, SLOT(SelectedTargets()));

    itemSelectionChanged()
    And, use QListWidget::selectedItems() to get all selected items.


Log in to reply