Recovering a pointer to QListWidget out of the QToolBox



  • Hi!

    I have a QToolBox with multiple QListWidget as items/widgets inserted.
    This QListWidget contains QListWidgetItem's that are checkable (Qt::ItemIsUserCheckable).

    I have a certain button that when clicked scans each QListWidgetItem on all these QListWidgets if they were checked or unchecked by the user.

    I have a problem recovering the QListWidget out of the QToolbBox. Apparently, QToolBox doesn't have a member for QListwidget, instead it only have a member for QWidget (QToolBox::widget()).

    How can I convert this QWidget to QListWidget? Though it is a QListWidget in the first place.

    Thanks



  • you need to cast pointer from QWidget to QListWidget.
    e.g.:
    @
    QListWidget* listWidget = qobject_cast<QListWidget*>(toolBox->widget(index));
    if (listWidget != 0)
    {
    // success
    }
    else
    {
    // fail
    }
    @



  • Thanks _rmn. I will be testing your code ASAP.



  • [quote author="_rmn" date="1358500944"]you need to cast pointer from QWidget to QListWidget.
    e.g.:(...)[/quote]

    Or a bit more common (and less scope polluting):
    @
    if (QListWidget* listWidget = qobject_cast<QListWidget*>(toolBox->widget(index)))
    {
    // success, use listWidget here
    }
    else
    {
    // fail
    }@


Log in to reply
 

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