qt - C++ - QListWidget select first item -
in qmainwindow
constructor read database , fill qlistwidget
items. apparently there no item selected have on own. have slot called when click on item in list.
i tried setcurrentrow( const int )
if slot won't called. i've seen function setcurrentindex( const qmodelindex & ) i'm not familiar qmodelindex.
how tell qlistwidget select first item , call on_list_clicked(const qmodelindex& index)
slot?
edit: also, cannot use other slot clicked because currentrowchanged(int)
, itemselectionchanged()
both make program crash when remove index list.
so somehow need perform click on list...
calling setcurrentrow()
emits signal currentrowchanged()
, accepts int
instead of qmodelindex
.
simply connect signal instead of 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; }
Comments
Post a Comment