[Qt-interest] Sanity check on using dynamic_cast<> with Qt
Malyushytsky, Alex
alex at wai.com
Tue May 11 02:25:06 CEST 2010
Check documentation for:
T qobject_cast ( QObject * object )
Regards,
Alex
-----Original Message-----
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of K. Frank
Sent: Monday, May 10, 2010 3:33 PM
To: Qt-interest
Subject: [Qt-interest] Sanity check on using dynamic_cast<> with Qt
Hello List -
I get a QWidget* out of a QTableWidget cell and I need to cast it to
derived type.
Using C++'s dynamic_cast<> seems to do the trick, but I would like to check
that this is the Qt-approved way of doing things. (I seem to recall that Qt has
its own casting support, but that it is restricted to QVariant.) Is
this the right
approach?
More specifically,
QTableWidget::cellWidget (row, column)
returns a QWidget*, previously set with
QTableWidget::setCellWidget (row, column, new RadioBox())
where RadioBox is my class that derives from QGroupBox (which, itself, derives
from QWidget).
I need to access the value() member function of my RadioBox class, and I do so
as follows:
int value = dynamic_cast<RadioBox*>(tableWidget->cellWidget (row,
column))->value();
Is this the preferred Qt way of doing this?
(Like I said, it seems okay to me, and it does seem to work, so I'm
looking for a
sanity check that I'm going down the right path.)
Thanks.
K. Frank
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest
---------------------------------------------------------------------------------------------------
Weidlinger Associates, Inc. made the following annotations.
“This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you.”
“Please consider our environment before printing this email.”
More information about the Qt-interest-old
mailing list