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.
Qt Code:
  1. QAction *act = new QAction(this);
  2.  
  3. QWidget *randomWidget = new QWidget(this);
  4.  
  5. act->setData(randomWidget);
To copy to clipboard, switch view to plain text mode 

Problem is when I want to get that QWidget back and use it. If I try to cast it
Qt Code:
  1. QWidget *returnWidget = qobject_cast<QWidget *>(act->data());
To copy to clipboard, switch view to plain text mode 
I get "error: no matching function for call to ‘qobject_cast(QVariant)’"

If I try to set it directly
Qt Code:
  1. QWidget *widget = act->data();
To copy to clipboard, switch view to plain text mode 
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