Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-394

Suggestion: Make it easier to use QVariant with pointers

    XMLWordPrintable

Details

    Description

      It would be nice if using QVariant with pointers were made easier, for instance, by somehow eliminating the need to cast to and from void *.

      Example usage case:

      This comes up, for example, when populating a combo box and attaching an object to each item. If we want to attach a Foo* type of object to a combo box entry we do:

      cb->addItem( QString(str.c_str()), QVariant::fromValue((void*)obj) );

      where cb is the combo box, obj is the Foo object and str is a std::string representation of that object.

      Once the user has selected an item we get the associated Foo object back
      with:

      int idx = cb->currentIndex();
      // [...] check that idx != -1
      const QVariant& data = cb->itemData( idx );
      const Foo* obj = static_cast<Foo*>( data.value<void*>() );

      This would be typesafe if we did not have to cast to/from void*.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            stormols Marius Storm-Olsen
            admin Administrator
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes