c++ - get widget from QListWidget -
i have custom qwidget class called videowidget used populate qlistwidget ui->mylist. doubleclicking on item of list should give me videowidget.
connect(ui->mylist,signal(doubleclicked(qmodelindex)),this,slot(playclip(qmodelindex))); void mainwindow::playclip(qmodelindex index){ qlistwidgetitem* item = ui->mylist->itemat(0,index.row()); videowidget widget = <dynamic_cast>(videowidget*)( ui->mylist->itemwidget(item) ); cout << "custom widget data" << widget.getmydata() << endl; } it won't allow me compile line videowidget widget = <dynamic_cast>(videowidget*)( ui->mylist->itemwidget(item) );. i'm not sure missing here.
syntax of dynamic_cast is
videowidget *widget = dynamic_cast<videowidget*>(ui->mylist->itemwidget(item)); you should utilize qobject_cast instead, since qobject:
videowidget *widget = qobject_cast<videowidget*>(ui->mylist->itemwidget(item)); add code, @ to the lowest degree q_assert(widget);, after cast verify cast successful (returns nullptr failed cast).
c++ qt qwidget qlistwidget
No comments:
Post a Comment