coderbob
28th February 2008, 09:14
I have a QAction that I wish to use setData() on so I can reference a QWidget at a later date rather then using a QHash for a lookup table.
QAction *act = new QAction(this);
QWidget *randomWidget = new QWidget(this);
act->setData(randomWidget);
Problem is when I want to get that QWidget back and use it. If I try to cast it
QWidget *returnWidget = qobject_cast<QWidget *>(act->data());
I get "error: no matching function for call to ‘qobject_cast(QVariant)’"
If I try to set it directly
QWidget *widget = act->data();
I get "error: cannot convert ‘QVariant’ to ‘QWidget*’ in initialization".
In QVariant docs I am allowed to set my own user type data; so am I just misunderstanding the use of a QVariant?
Bob
QAction *act = new QAction(this);
QWidget *randomWidget = new QWidget(this);
act->setData(randomWidget);
Problem is when I want to get that QWidget back and use it. If I try to cast it
QWidget *returnWidget = qobject_cast<QWidget *>(act->data());
I get "error: no matching function for call to ‘qobject_cast(QVariant)’"
If I try to set it directly
QWidget *widget = act->data();
I get "error: cannot convert ‘QVariant’ to ‘QWidget*’ in initialization".
In QVariant docs I am allowed to set my own user type data; so am I just misunderstanding the use of a QVariant?
Bob