Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Recovering a pointer to QListWidget out of the QToolBox
Forum Updated to NodeBB v4.3 + New Features

Recovering a pointer to QListWidget out of the QToolBox

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Code_ReaQtor
    wrote on last edited by
    #1

    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

    Please visit my open-source projects at https://github.com/Code-ReaQtor.

    1 Reply Last reply
    0
    • _ Offline
      _ Offline
      _rmn
      wrote on last edited by
      #2

      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
      }
      @

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Code_ReaQtor
        wrote on last edited by
        #3

        Thanks _rmn. I will be testing your code ASAP.

        Please visit my open-source projects at https://github.com/Code-ReaQtor.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DerManu
          wrote on last edited by
          #4

          [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
          }@

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved