Calling setCurrentRow()
emits the signal currentRowChanged()
, which accepts an int
instead of a QModelIndex
.
Simply connect to that signal instead of to itemSelectionChanged()
.
Sample code:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->listWidget->setCurrentRow(1);
}
void MainWindow::on_listWidget_currentRowChanged(int currentRow)
{
qDebug() << currentRow;
}