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. sth...@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.go...@ovi.com To: devel@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 coderusin...@gmail.com escribió: start app in terminal and show output please On 26.02.2014 17:15, antonio.cano.go...@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.p...@gmail.com escribió: On 2014-02-26 11:48, antonio.cano.go...@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 ___ SailfishOS.org Devel mailing list
Re: [SailfishDevel] QML C++ Integration not working in Sailfish
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-boun...@lists.sailfishos.org [devel-boun...@lists.sailfishos.org] on behalf of antonio.cano.go...@ovi.com [antonio.cano.go...@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. sth...@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.go...@ovi.com To: devel@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 coderusin...@gmail.com escribió: start app in terminal and show output please On 26.02.2014 17:15, antonio.cano.go...@ovi.commailto:antonio.cano.go...@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.p...@gmail.commailto:th.p...@gmail.com escribió: On 2014-02-26 11:48, antonio.cano.go...@ovi.commailto:antonio.cano.go...@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 ___ SailfishOS.org Devel mailing list
Re: [SailfishDevel] QML C++ Integration not working in Sailfish
Hi, On 25.02.2014 15:06, antonio.cano.go...@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 QScopedPointerQGuiApplication app(SailfishApp::application(argc, argv)); QScopedPointerQQuickView view(SailfishApp::createView()); // Register Bloomfilter Class qmlRegisterTypeBloomfilter, 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 ___ SailfishOS.org Devel mailing list
Re: [SailfishDevel] QML C++ Integration not working in Sailfish
Yes, it helped thanks. My problem now is different. I have some private attributes in my C++ object. When I call the first tiem I can modify the attributes, but in the second call the attributes dessapear. Is there a way to solve this problem? (The attributes a new C++ Object not declared as QObject) El Jueves 27 de febrero de 2014 12:32, Stefan Brand stefan.br...@seiichiro0185.org escribió: Hi, On 25.02.2014 15:06, antonio.cano.go...@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 QScopedPointerQGuiApplication app(SailfishApp::application(argc, argv)); QScopedPointerQQuickView view(SailfishApp::createView()); // Register Bloomfilter Class qmlRegisterTypeBloomfilter, 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 ___ SailfishOS.org Devel mailing list ___ SailfishOS.org Devel mailing list
Re: [SailfishDevel] QML C++ Integration not working in Sailfish
Antonio Can you provide a code example, and the exact error(s) that you get. Chris Zitat von antonio.cano.go...@ovi.com: Yes, it helped thanks. My problem now is different. I have some private attributes in my C++ object. When I call the first tiem I can modify the attributes, but in the second call the attributes dessapear. Is there a way to solve this problem? (The attributes a new C++ Object not declared as QObject) El Jueves 27 de febrero de 2014 12:32, Stefan Brand stefan.br...@seiichiro0185.org escribió: Hi, On 25.02.2014 15:06, antonio.cano.go...@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 QScopedPointerQGuiApplication app(SailfishApp::application(argc, argv)); QScopedPointerQQuickView view(SailfishApp::createView()); // Register Bloomfilter Class qmlRegisterTypeBloomfilter, 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 ___ SailfishOS.org Devel mailing list ___ SailfishOS.org Devel mailing list
Re: [SailfishDevel] QML C++ Integration not working in Sailfish
Hi J-P, It is not working as I try to call the method generateFilterInvokable2() in the function: function createBloomFilter() { getAppState().filterCharged = true; Bloomfilters.generateFilterInvokable2() console.log(Called) } And as result Called is never printed. So I guess that it crashes. El Miércoles 26 de febrero de 2014 0:30, Sylvain B. sth...@hotmail.com escribió: No, I am able to invoke c++ methods from QML while having exposed them the exact same way. The only difference would be that my constructor is a simple Bloomfilters(). So same question than J-P: what exactly isn't working? Date: Tue, 25 Feb 2014 16:31:13 +0100 From: mikel...@gmail.com To: antonio.cano.go...@ovi.com; devel@lists.sailfishos.org Subject: Re: [SailfishDevel] QML C++ Integration not working in Sailfish I think you need to add a qRegisterMetatype() to be able to invoke methods from qml. On Tue, Feb 25, 2014 at 3:06 PM, antonio.cano.go...@ovi.com wrote: Hi, I am trying to do a simple Sailfish aplication that uses a c++ library. I try to connect my qml code with the C++ code. First I create QObject extended library: #ifndef BLOOMFILTERS_H #define BLOOMFILTERS_H #include QObject #include svn/bloom-read-only/bloom_filter.hpp class Bloomfilters : public QObject { Q_OBJECT public: Q_INVOKABLE void generateFilterInvokable2() const ; Q_INVOKABLE void generateFilterInvokable(const QString cadenaK, const QString cadenaM) const ; explicit Bloomfilters(QObject *parent = 0); void generateFilter() ; Q_INVOKABLE void insertElement(const QString cadena) ; Q_INVOKABLE bool checkElement(const QString cadena) ; signals: public slots: private: bloom_parameters _parameters ; bloom_filter _filter; bool _filter_charged; QString _k; }; #endif // BLOOMFILTERS_H 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? Best Regards! ___ SailfishOS.org Devel mailing list -- Luciano Montanaro Anyone who is capable of getting themselves made President should on no account be allowed to do the job. -- Douglas Adams ___ SailfishOS.org Devel mailing list ___ SailfishOS.org Devel mailing list ___ SailfishOS.org Devel mailing list
Re: [SailfishDevel] QML C++ Integration not working in Sailfish
On 2014-02-26 11:48, antonio.cano.go...@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
Re: [SailfishDevel] QML C++ Integration not working in Sailfish
Hi, Try creating Bloomfilters class instance before declaring view, and store app and view either to qscopedpointer or qsharedpointer. /Mikko 2014-02-26 13:15 GMT+02:00 antonio.cano.go...@ovi.com: 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.p...@gmail.com escribió: On 2014-02-26 11:48, antonio.cano.go...@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
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 coderusin...@gmail.com escribió: start app in terminal and show output please On 26.02.2014 17:15, antonio.cano.go...@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.p...@gmail.com escribió: On 2014-02-26 11:48, antonio.cano.go...@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
Re: [SailfishDevel] QML C++ Integration not working in Sailfish
Yes, add a sYou declared bloomfiltersdata and you are trying to use bloomfilterdata... Date: Wed, 26 Feb 2014 04:02:22 -0800 From: antonio.cano.go...@ovi.com To: devel@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 coderusin...@gmail.com escribió: start app in terminal and show output please On 26.02.2014 17:15, antonio.cano.go...@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.p...@gmail.com escribió: On 2014-02-26 11:48, antonio.cano.go...@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 ___ SailfishOS.org Devel mailing list
Re: [SailfishDevel] QML C++ Integration not working in Sailfish
Hi Antonio This works for me: //Start BloomfiltersDemo.cpp #ifdef QT_QML_DEBUG #include QtQuick #endif #include sailfishapp.h #include bloomfilters.h int main(int argc, char *argv[]) { QGuiApplication *app = SailfishApp::application(argc, argv); QQuickView *view = SailfishApp::createView(); Bloomfilters * bloomfilters = new Bloomfilters(); view-rootContext()-setContextProperty(bloomfiltersdata, bloomfilters); view-setSource(SailfishApp::pathTo(qml/BloomFiltersDemo.qml)); view-showFullScreen(); return app-exec(); } //End BloomfiltersDemo.cpp //start bloomfilters.h #ifndef BLOOMFILTERS_H #define BLOOMFILTERS_H #include QObject #include QDebug //#include svn/bloom-read-only/bloom_filter.hpp class Bloomfilters : public QObject { Q_OBJECT public: Q_INVOKABLE void generateFilterInvokable2() const ; explicit Bloomfilters(QObject *parent = 0); void generateFilter() ; private: QString _k; }; #endif // BLOOMFILTERS_H //end bloomfilters.h //start bloomfilters.cpp #include bloomfilters.h Bloomfilters::Bloomfilters(QObject *parent) : QObject(parent) { } void Bloomfilters::generateFilterInvokable2() const { qDebug() Blooming Magic; } //end bloomfilters.cpp //start FirstPage.qml import QtQuick 2.0 import Sailfish.Silica 1.0 Page { id: page Component.onCompleted: { bloomfiltersdata.generateFilterInvokable2() } } //end FirstPage.qm HtH Chris Zitat von antonio.cano.go...@ovi.com: 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 coderusin...@gmail.com escribió: start app in terminal and show output please On 26.02.2014 17:15, antonio.cano.go...@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.p...@gmail.com escribió: On 2014-02-26 11:48, antonio.cano.go...@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
Re: [SailfishDevel] QML C++ Integration not working in Sailfish
I think you need to add a qRegisterMetatype() to be able to invoke methods from qml. On Tue, Feb 25, 2014 at 3:06 PM, antonio.cano.go...@ovi.com wrote: Hi, I am trying to do a simple Sailfish aplication that uses a c++ library. I try to connect my qml code with the C++ code. First I create QObject extended library: #ifndef BLOOMFILTERS_H #define BLOOMFILTERS_H #include QObject #include svn/bloom-read-only/bloom_filter.hpp class Bloomfilters : public QObject { Q_OBJECT public: Q_INVOKABLE void generateFilterInvokable2() const ; Q_INVOKABLE void generateFilterInvokable(const QString cadenaK, const QString cadenaM) const ; explicit Bloomfilters(QObject *parent = 0); void generateFilter() ; Q_INVOKABLE void insertElement(const QString cadena) ; Q_INVOKABLE bool checkElement(const QString cadena) ; signals: public slots: private: bloom_parameters _parameters ; bloom_filter _filter; bool _filter_charged; QString _k; }; #endif // BLOOMFILTERS_H 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? Best Regards! ___ SailfishOS.org Devel mailing list -- Luciano Montanaro Anyone who is capable of getting themselves made President should on no account be allowed to do the job. -- Douglas Adams ___ SailfishOS.org Devel mailing list
Re: [SailfishDevel] QML C++ Integration not working in Sailfish
On Tue, 2014-02-25 at 06:06 -0800, antonio.cano.go...@ovi.com wrote: Hi, I am trying to do a simple Sailfish aplication that uses a c++ library. I try to connect my qml code with the C++ code. First I create QObject extended library: #ifndef BLOOMFILTERS_H #define BLOOMFILTERS_H #include QObject #include svn/bloom-read-only/bloom_filter.hpp class Bloomfilters : public QObject { Q_OBJECT public: Q_INVOKABLE void generateFilterInvokable2() const ; Q_INVOKABLE void generateFilterInvokable(const QString cadenaK, const QString cadenaM) const ; explicit Bloomfilters(QObject *parent = 0); void generateFilter() ; Q_INVOKABLE void insertElement(const QString cadena) ; Q_INVOKABLE bool checkElement(const QString cadena) ; signals: public slots: private: bloom_parameters _parameters ; bloom_filter _filter; bool _filter_charged; QString _k; }; #endif // BLOOMFILTERS_H 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? Hi, What does this is not working mean? In what way is it not working? -- J-P Nurmi ___ SailfishOS.org Devel mailing list
Re: [SailfishDevel] QML C++ Integration not working in Sailfish
Hi, you should set the context property after loading the QML source. Then it ought to be available from QML. Martin Am Tue Feb 25 2014 15:06:39 GMT+0100 (CET) schrieb antonio.cano.go...@ovi.com: Hi, I am trying to do a simple Sailfish aplication that uses a c++ library. I try to connect my qml code with the C++ code. First I create QObject extended library: #ifndef BLOOMFILTERS_H #define BLOOMFILTERS_H #include QObject #include svn/bloom-read-only/bloom_filter.hpp class Bloomfilters : public QObject { Q_OBJECT public: Q_INVOKABLE void generateFilterInvokable2() const ; Q_INVOKABLE void generateFilterInvokable(const QString cadenaK, const QString cadenaM) const ; explicit Bloomfilters(QObject *parent = 0); void generateFilter() ; Q_INVOKABLE void insertElement(const QString cadena) ; Q_INVOKABLE bool checkElement(const QString cadena) ; signals: public slots: private: bloom_parameters _parameters ; bloom_filter _filter; bool _filter_charged; QString _k; }; #endif // BLOOMFILTERS_H 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? Best Regards -- Gesendet von meinem Jolla ___ SailfishOS.org Devel mailing list
Re: [SailfishDevel] QML C++ Integration not working in Sailfish
??? contextProperty should be set BEFORE loading QML source. On 25.02.2014 21:33, martin.gri...@gmail.com wrote: Hi, you should set the context property after loading the QML source. Then it ought to be available from QML. Martin Am Tue Feb 25 2014 15:06:39 GMT+0100 (CET) schrieb antonio.cano.go...@ovi.com: Hi, I am trying to do a simple Sailfish aplication that uses a c++ library. I try to connect my qml code with the C++ code. First I create QObject extended library: #ifndef BLOOMFILTERS_H #define BLOOMFILTERS_H #include QObject #include svn/bloom-read-only/bloom_filter.hpp class Bloomfilters : public QObject { Q_OBJECT public: Q_INVOKABLE void generateFilterInvokable2() const ; Q_INVOKABLE void generateFilterInvokable(const QString cadenaK, const QString cadenaM) const ; explicit Bloomfilters(QObject *parent = 0); void generateFilter() ; Q_INVOKABLE void insertElement(const QString cadena) ; Q_INVOKABLE bool checkElement(const QString cadena) ; signals: public slots: private: bloom_parameters _parameters ; bloom_filter _filter; bool _filter_charged; QString _k; }; #endif // BLOOMFILTERS_H 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? Best Regards ___ SailfishOS.org Devel mailing list
Re: [SailfishDevel] QML C++ Integration not working in Sailfish
Hi Antonio Here is a simplified example from one of my projects, showing a number of ways to expose C++ to QML. I tend to use qmlRegister when exposing C++ objects with methods, and SetContextProperty when I want to expose simple stuff like global constants only. I do things that way because it works for me ... Chris #ifdef QT_QML_DEBUG #include QtQuick #endif #include QGuiApplication #include QQuickView #include QQmlContext #include sailfishapp.h //#include landedtorch.h //harmattan #include gsttorch.h //sailfish #include satinfosource.h #include operatingsystem.h #include windowingsystem.h #include telepathyhelper.h #include landedtheme.h #include jsonstorage.h //HELPER Functions getting system information which will be exported to QML bool isSimulator() { bool simulator; #if defined(QT_SIMULATOR) simulator = true; #else // real device or emulator simulator = false; #endif return simulator; } int getOperatingSystem() { //C++ representation of the OperatingSystem enumg const OperatingSystem Os; int OSId; #if defined(Q_OS_SYMBIAN) OSId = Os.Symbian; #elif defined(Q_OS_MAC64) OSId = Os.Mac64; #elif defined(Q_OS_UNIX) OSId = Os.Unix; #elif defined(Q_OS_WIN32) OSId = Os.Win32; #elif defined(Q_OS_WIN64) OSId = Os.Win64; #elif defined(Q_OS_WINCE) OSId = Os.WinCE; #elif defined(Q_OS_SIMULATOR) OSId = Os.Simulator; #else // other OS OSId = Os.Other; #endif return OSId; } //END HELPER Functions static QObject *theme_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine) { Q_UNUSED(engine) Q_UNUSED(scriptEngine) LandedTheme *landedTheme = new LandedTheme(); return landedTheme; } static QObject *jsonStorage_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine) { Q_UNUSED(engine) Q_UNUSED(scriptEngine) JSONStorage *jsonStorage = new JSONStorage(); return jsonStorage; } int main(int argc, char *argv[]) { bool simulator = isSimulator(); //expose an enum of operating systems types to QML qmlRegisterUncreatableTypeOperatingSystem(OperatingSystem, 1, 0, OperatingSystem, ); int OperatingSystemId = getOperatingSystem(); qmlRegisterTypeGstTorch(GstTorch,1,0,GstTorch); qmlRegisterTypeTelepathyHelper(TelepathyHelper,1,0,TelepathyHelper); qmlRegisterTypeSatInfoSource(SatInfoSource,1,0,SatInfoSource); qmlRegisterSingletonTypeLandedTheme(LandedTheme, 1, 0, LandedTheme, theme_singletontype_provider); qmlRegisterSingletonTypeJSONStorage(JSONStorage,1,0,JSONStorage, jsonStorage_singletontype_provider); QScopedPointerQGuiApplication app(SailfishApp::application(argc, argv)); QScopedPointerQQuickView view(SailfishApp::createView()); view-rootContext()-setContextProperty(OperatingSystemId, OperatingSystemId); view-rootContext()-setContextProperty(simulator, simulator); view-setSource(SailfishApp::pathTo(qml/landed26_QT5.qml)); view-show(); view-showFullScreen(); return app-exec(); } Zitat von Andrey Kozhevnikov coderusin...@gmail.com: ??? contextProperty should be set BEFORE loading QML source. On 25.02.2014 21:33, martin.gri...@gmail.com wrote: Hi, you should set the context property after loading the QML source. Then it ought to be available from QML. Martin Am Tue Feb 25 2014 15:06:39 GMT+0100 (CET) schrieb antonio.cano.go...@ovi.com: Hi, I am trying to do a simple Sailfish aplication that uses a c++ library. I try to connect my qml code with the C++ code. First I create QObject extended library: #ifndef BLOOMFILTERS_H #define BLOOMFILTERS_H #include QObject #include svn/bloom-read-only/bloom_filter.hpp class Bloomfilters : public QObject { Q_OBJECT public: Q_INVOKABLE void generateFilterInvokable2() const ; Q_INVOKABLE void generateFilterInvokable(const QString cadenaK, const QString cadenaM) const ; explicit Bloomfilters(QObject *parent = 0); void generateFilter() ; Q_INVOKABLE void insertElement(const QString cadena) ; Q_INVOKABLE bool checkElement(const QString cadena) ; signals: public slots: private: bloom_parameters _parameters ; bloom_filter _filter; bool _filter_charged; QString _k; }; #endif // BLOOMFILTERS_H 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? Best Regards ___
Re: [SailfishDevel] QML C++ Integration not working in Sailfish
No, I am able to invoke c++ methods from QML while having exposed them the exact same way. The only difference would be that my constructor is a simple Bloomfilters(). So same question than J-P: what exactly isn't working? Date: Tue, 25 Feb 2014 16:31:13 +0100 From: mikel...@gmail.com To: antonio.cano.go...@ovi.com; devel@lists.sailfishos.org Subject: Re: [SailfishDevel] QML C++ Integration not working in Sailfish I think you need to add a qRegisterMetatype() to be able to invoke methods from qml. On Tue, Feb 25, 2014 at 3:06 PM, antonio.cano.go...@ovi.com wrote: Hi, I am trying to do a simple Sailfish aplication that uses a c++ library. I try to connect my qml code with the C++ code. First I create QObject extended library: #ifndef BLOOMFILTERS_H #define BLOOMFILTERS_H #include QObject #include svn/bloom-read-only/bloom_filter.hpp class Bloomfilters : public QObject { Q_OBJECT public: Q_INVOKABLE void generateFilterInvokable2() const ; Q_INVOKABLE void generateFilterInvokable(const QString cadenaK, const QString cadenaM) const ; explicit Bloomfilters(QObject *parent = 0); void generateFilter() ; Q_INVOKABLE void insertElement(const QString cadena) ; Q_INVOKABLE bool checkElement(const QString cadena) ; signals: public slots: private: bloom_parameters _parameters ; bloom_filter _filter; bool _filter_charged; QString _k; }; #endif // BLOOMFILTERS_H 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? Best Regards! ___ SailfishOS.org Devel mailing list -- Luciano Montanaro Anyone who is capable of getting themselves made President should on no account be allowed to do the job. -- Douglas Adams ___ SailfishOS.org Devel mailing list ___ SailfishOS.org Devel mailing list
Re: [SailfishDevel] QML C++ Integration not working in Sailfish
2014-02-25 16:39 GMT+01:00, Andrey Kozhevnikov coderusin...@gmail.com: ??? contextProperty should be set BEFORE loading QML source. You're right, sorry! I must have confused something. I shouldn't answer mails while on train. :) Martin On 25.02.2014 21:33, martin.gri...@gmail.com wrote: Hi, you should set the context property after loading the QML source. Then it ought to be available from QML. Martin Am Tue Feb 25 2014 15:06:39 GMT+0100 (CET) schrieb antonio.cano.go...@ovi.com: Hi, I am trying to do a simple Sailfish aplication that uses a c++ library. I try to connect my qml code with the C++ code. First I create QObject extended library: #ifndef BLOOMFILTERS_H #define BLOOMFILTERS_H #include QObject #include svn/bloom-read-only/bloom_filter.hpp class Bloomfilters : public QObject { Q_OBJECT public: Q_INVOKABLE void generateFilterInvokable2() const ; Q_INVOKABLE void generateFilterInvokable(const QString cadenaK, const QString cadenaM) const ; explicit Bloomfilters(QObject *parent = 0); void generateFilter() ; Q_INVOKABLE void insertElement(const QString cadena) ; Q_INVOKABLE bool checkElement(const QString cadena) ; signals: public slots: private: bloom_parameters _parameters ; bloom_filter _filter; bool _filter_charged; QString _k; }; #endif // BLOOMFILTERS_H 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? Best Regards ___ SailfishOS.org Devel mailing list ___ SailfishOS.org Devel mailing list