Custom QWidgetListItem and casting



  • I have subclassed the QWidgetListItem and im trying to implement the ability of double clicking it and then populating the data into a dialog to give the user the ability to change the properties of the item.

    my problem is that i dont know how to cast the item properly.

    using qobject_cast doesnt seem to work properly.

    one of my problems is admittedly that im still new to c++ coming from c# world.

    so if i have

    @
    class CustomItem: public QListWidgetItem
    {
    }

    but in my qlistwidget i have

    void CustomListWidget::on_CustomListWidget_itemDoubleClicked(QListWidgetItem *item)
    {

    CustomItem* robot=qobject_cast<CustomItem*>(item);

        qDebug()<<"Show Item Dialog";
    

    }
    @

    how can i cast it so i can pass it along?

    [edit: Added missing coding tags @ SGaist]


  • Lifetime Qt Champion

    Hi,

    QListWidgetItem is not a QObject thus qobject_cast will fail. In this case, you can use a dynamic_cast.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.