problem with qobject_cast<QWidget *>(object) (from QML object)
Code:
qmlView = new QDeclarativeView;
qmlView
->setSource
( QUrl::fromLocalFile( "modaldialog.qml" ) );
QObject *object
= qmlView
->rootObject
();
Q_RETURN_ARG
( QVariant, returnedValue
),
);
QWidget *widget
= qobject_cast<QWidget
*>
(object
);
//doesn't work, return null layout->addWidget( widget );//doesn't work, above is null
//however if i replace the above 2 lines of code with this:
QGraphicsObject* graphicsObject =qobject_cast<QGraphicsObject *>(object); //works fine
scene.addItem( graphicsObject ); //works fine
why qobject_cast works ok for a QGraphicsObject and not for a QWidget coming from QML?
Why use the "layout->addWidget(...)" option? because i want a QDialog with the stuff coming from QML
Re: problem with qobject_cast<QWidget *>(object) (from QML object)
because:
Quote:
Returns the given object cast to type T if the object is of type T (or of a subclass); otherwise returns 0. If object is 0 then it will also return 0.
QGraphicsObject is NOT a QWidget subclass which is why:
Code:
QWidget *widget
= qobject_cast<QWidget
*>
(object
);
wont work.
Quote:
because i want a QDialog with the stuff coming from QML
This technology does not exist yet.
You can have widgets in QGraphicsView, but you can't have QGraphicsObject as QWidgets. (unless these are QProxyWidget s, which means they have a QWidget counterparts to start with)
Re: problem with qobject_cast<QWidget *>(object) (from QML object)