[SailfishDevel] QML C++ Integration not working in Sailfish
Jonni Rainisto
jonni.rainisto at jolla.com
Thu Feb 27 10:37:49 UTC 2014
Yes, if you read the documentation pragma library cannot access qml properties directly. So its a feature.
http://qt-project.org/doc/qt-5.0/qtqml/qtqml-javascript-resources.html#shared-javascript-resources-libraries
re, Jonni
________________________________
From: devel-bounces at lists.sailfishos.org [devel-bounces at lists.sailfishos.org] on behalf of antonio.cano.gomez at ovi.com [antonio.cano.gomez at ovi.com]
Sent: Thursday, February 27, 2014 12:17 PM
To: Sylvain B.; Sailfish OS Developers
Subject: Re: [SailfishDevel] QML C++ Integration not working in Sailfish
Hi sylvain,
This is not the case a renamed the variable so the have exactly the same name.
On the other hand, may be the problem is that I am calling it from .js file by the next code:
.pragma library
.import QtQuick 2.0 as QQ
var appState;
function getAppState() { return appState; }
function newAppState(page)
{
appState = page;
getAppState().k=1;
getAppState().m=2;
return appState;
}
// Funciones especificas
function createBloomFilter() {
console.log("Voy a llamar a generate filter")
bloomfiltersdata.generateFilterInvokable2()
console.log("Ya he llamado a generate filter")
}
And I call this from the qml by:
import QtQuick 2.0
import Sailfish.Silica 1.0
import "pages"
import "pages/content"
import "pages/content/logic.js" as Logic
import fi.helsinki.cs 1.0
ApplicationWindow
{
initialPage: Component { FirstPage { } }
cover: Qt.resolvedUrl("cover/CoverPage.qml")
id: appWin
property var appState: Logic.newAppState(appWin);
property ApplicationWindow appWin: appWin
property Bloomfilters bloomfilters: bloomfilters
property var k
property var m
property bool filterCharged: false
}
Someone seems something unusual in this code?
Best Regards and Thanks,
A. Cano
El Miércoles 26 de febrero de 2014 13:24, Sylvain B. <sthocs at hotmail.com> escribió:
Yes, add a "s"
You declared "bloomfiltersdata" and you are trying to use bloomfilterdata...
________________________________
Date: Wed, 26 Feb 2014 04:02:22 -0800
From: antonio.cano.gomez at ovi.com
To: devel at lists.sailfishos.org
Subject: Re: [SailfishDevel] QML C++ Integration not working in Sailfish
Hi Andrey,
The output is: ReferenceError: bloomfilterdata is not defined
I am calling it from a .js
Some idea about how can I make that this is also defined there.
Thanks!
El Miércoles 26 de febrero de 2014 12:18, Andrey Kozhevnikov <coderusinbox at gmail.com> escribió:
start app in terminal and show output please
On 26.02.2014 17:15, antonio.cano.gomez at ovi.com<mailto:antonio.cano.gomez at ovi.com> wrote:
Hi Thomas,
I did both modification but the code does not work yet.
Here is the new code:
QGuiApplication *app = SailfishApp::application(argc, argv);
QQuickView *view = SailfishApp::createView();
Bloomfilters * bloomfilters = new Bloomfilters();
view->rootContext()->setContextProperty("bloomfiltersdata", bloomfilters);
view->setSource(SailfishApp::pathTo("qml/bloomfilter.qml"));
view->showFullScreen();
return app->exec();
El Miércoles 26 de febrero de 2014 12:01, Thomas Perl <th.perl at gmail.com><mailto:th.perl at gmail.com> escribió:
On 2014-02-26 11:48, antonio.cano.gomez at ovi.com<mailto:antonio.cano.gomez at ovi.com> wrote:
> I tried this:
>
> QGuiApplication *app = SailfishApp::application(argc, argv);
> QQuickView *view = SailfishApp::createView();
> Bloomfilters * bloomfilters = new Bloomfilters();
> view->setSource(SailfishApp::pathTo("qml/bloomfilter.qml"));
> view->showFullScreen();
> view->rootContext()->setContextProperty("Bloomfilters", bloomfilters);
> return app->exec();
>
> But it is not working yet.
Two things:
1. Call setContextProperty() right before before setSource(), so it's
already available when the QML content is loaded.
2. Use lowercase for context property names ("bloomfilters" instead of
"Bloomfilters"). In some places, QML interprets IDs starting with an
upper case letter as a type name, and that won't work then, therefore
stick to lowercase.
HTH :)
Thomas
_______________________________________________
SailfishOS.org Devel mailing list
_______________________________________________
SailfishOS.org Devel mailing list
_______________________________________________ SailfishOS.org Devel mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.sailfishos.org/pipermail/devel/attachments/20140227/3be87c9e/attachment.html>
More information about the Devel
mailing list