[SailfishDevel] QML C++ Integration not working in Sailfish
Stefan Brand
stefan.brand at seiichiro0185.org
Tue Feb 25 15:14:58 UTC 2014
Hi,
On 25.02.2014 15:06, antonio.cano.gomez at ovi.com wrote:
> An I try to connect this with my sailfish application with the code:
>
> QGuiApplication *app = SailfishApp::application(argc, argv);
> QQuickView *view = SailfishApp::createView();
> Bloomfilters * bloomfilters = new Bloomfilters();
> view->rootContext()->setContextProperty("Bloomfilters",
> bloomfilters);
> view->setSource(SailfishApp::pathTo("qml/bloomfilter.qml"));
> view->showFullScreen();
> return app->exec();
>
> But this is not working.
>
> Someone have any idea about what am I doing wrong?
>
You can use qmlRegisterType to pass the Info of the C++ class to QML
like this in the cpp:
#include "bloomfilters.h"
int main(int argc, char *argv[])
{
// Get App and QML-View objects
QScopedPointer<QGuiApplication> app(SailfishApp::application(argc,
argv));
QScopedPointer<QQuickView> view(SailfishApp::createView());
// Register Bloomfilter Class
qmlRegisterType<Bloomfilter, 1>("harbour.myapp.Bloomfilter", 1, 0,
"Bloomfilter");
// Prepare the QML
view->setSource(SailfishApp::pathTo("qml/bloomfilter.qml"));
view->show();
// Run the app
return app->exec();
}
Afterwards you can create a Bloomfilter-Object in QML:
Bloomfilter {
id: bloom
}
and use the methods with
bloom.insertElement("myelement")
I hope this helps.
Regards
Stefan Brand
More information about the Devel
mailing list