[Qt-qml] A simple, complete example of QML onvoking C++?
Colin Kern
colin.kern at gmail.com
Tue Apr 13 21:04:42 CEST 2010
On Tue, Apr 13, 2010 at 2:52 PM, Peter Matuchniak
<pmatuchniak at imsco-us.com> wrote:
> Hello Colin
>
> Thanks for the input. Although it compiles fine and appears to run without any errors, I don't actually see the QML page appear (i.e. myqml.qml is never displayed).
>
> I'm using Qt 4.7 that I built from source on Ubuntu.
>
Ok, I guess that code in main.cpp never actually displays the widget.
I took that from the QDeclarative documentation, but I'm not sure what
its use is if it doesn't display anything. Try this main.cpp:
#include "foo.h"
#include <QDeclarativeView>
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QDeclarativeView *view = new QDeclarativeView();
view->rootContext()->setContextProperty("myFoo", new Foo);
view->setSource(QUrl("myqml.qml"));
view->show();
return app.exec();
}
Colin
More information about the Qt-qml
mailing list