[SailfishDevel] Porting LocalStorage to Qt5: Blog updated
christopher.lamb at thurweb.ch
christopher.lamb at thurweb.ch
Mon Aug 5 12:51:10 UTC 2013
Hi Erlend
As promised, I have just updated my Sailfish Blog with my experiences
in updating LocalStorage from Qt4 Style to the new Qt5 style supported
by the Sailfish Alpha 2.
http://flyingsheeponsailfish.blogspot.ch/2013/08/alpha-2-migrating-localstorage-from-qt4.html
mfg
Chris
Zitat von "Erlend Böe" <erlendboe at yahoo.com>:
> Hoi Chris
>
> I will use the localstorage for my settings, so a blog entry would
> very much be appreciated :-)
>
> My main DB is however opened in C++, to do this I use the QSqlDatabase class.
> it then fails with out of memory on open(). In Alpha 1 it worked perfectly.
> QSqlDatabase db = QSqlDatabase:addDatabase("QSQLITE");
> db.setDatabaseName(pathToDB);
> bool opened = db.open();
>
>
> I checked the VM memory, and its was 1 GB, so it should be enough.
> This evening I will try to increase it, but I cannot understand why
> just opening the DB should use so much memory. Does anybody know how
> I can debug this, or if there are some SQLITE specific options that
> I must set?
>
> Opening the db in the sqlite3 command line client works in the
> simulator, so I'm confident that the DB is not corrupted.
>
> Greetings from Zürich
> Erlend
>
> On 05.08.2013, at 10:23, christopher.lamb at thurweb.ch wrote:
>
>> Sali Erlend
>>
>> Sorry, pressed send too soon on my last ...
>>
>> How exactly are you trying to access Sqlite? via QtQuick
>> LocalStorage API, or by some other means?
>>
>> The error message you quote sounds as though the Emulator is having
>> problems opening a 1.7 GB Database due to memory problems. I think
>> the memory allocated to the Emulator VM is fairly low, so you might
>> try increasing it.
>>
>> In the meantime I have just managed to migrate LocalStorage DB to
>> Qt5. I had to make a few changes to do so, and tore quite a bit of
>> hair out until I hit the correct solution. I can provide examples
>> if it helps (and will update my blog during the day)
>>
>> Chris
>>
>> p.s Hoi sounds Swiss (or Swiss aware ..)
>>
>>
>> ----- Weitergeleitete Nachricht von christopher.lamb at thurweb.ch -----
>> Datum: Mon, 05 Aug 2013 10:16:04 +0200
>> Von: christopher.lamb at thurweb.ch
>> Betreff: Re:sqlite "out of memory" error
>> An: "Erlend Boe" <erlendboe at yahoo.com>
>> Cc: devel at lists.sailfishos.org
>>
>> Zitat von "Erlend Boe" <erlendboe at yahoo.com>:
>>
>>> Hoi Chris
>>>
>>> after using the patch, it is also working for me.
>>>
>>> However, I have some other problems:
>>> * opening my sqlite DB (1.7 GB) fails with QSqlError(-1, "Error
>>> opening database", "out of memory")
>>> * debugging fails with "connection to remote server failed:
>>> tcp:localhost:10000: Bad file descriptor. (although the
>>> application Output shows "Listening on port 10000")
>>>
>>> opening the db worked fine in the previous release.
>>> Does anybody know what would cause this problem, or how I can debug it?
>>>
>>>
>>> I'm using a mac with osx 10.8.4, and virtualbox 4.2.16.
>>> I can log on to the simulator with: ssh -i
>>> ~/SailfishOS/vmshare/ssh/private_keys/1/root root at localhost -p 2223
>>>
>>> Regards
>>> Erlend
>>>
>>>
>>>
>>> On 04.08.2013, at 18:56, christopher.lamb at thurweb.ch wrote:
>>>
>>>> Hi All
>>>>
>>>> Just a quick note to say that
>>>>
>>>> Q_DECL_EXPORT int main(int argc, char *argv[])
>>>> {
>>>> QScopedPointer<QGuiApplication>
>>>> app(Sailfish::createApplication(argc, argv));
>>>> QScopedPointer<QQuickView> view(Sailfish::createView());
>>>> view->rootContext()->setContextProperty("cppproperty", "Hello world");
>>>> Sailfish::setView(view.data(), "main.qml");
>>>> Sailfish::showView(view.data());
>>>> return app->exec();
>>>> }
>>>>
>>>> works (so far) without error if Lucien's patch to
>>>> sailfishapplication.cpp is applied. This can be found here:
>>>> https://lists.sailfishos.org/pipermail/devel/attachments/20130802/2367c686/attachment.cpp
>>>>
>>>> Chris
>>>>
>>>> ----- Weitergeleitete Nachricht von christopher.lamb at thurweb.ch -----
>>>> Datum: Sun, 04 Aug 2013 18:36:06 +0200
>>>> Von: christopher.lamb at thurweb.ch
>>>> Betreff: Re: [SailfishDevel] Alpha 2: passing simple
>>>> properties from main.cpp to qml: A bug?
>>>> An: "Lucien XU" <sfietkonstantin at free.fr>
>>>> Cc: devel at lists.sailfishos.org
>>>>
>>>> Salut Lucien
>>>>
>>>> Maybe it is clearer with Code examples
>>>>
>>>> I was doing this, which gives me an error, but seems to work!
>>>>
>>>> Q_DECL_EXPORT int main(int argc, char *argv[])
>>>> {
>>>> QScopedPointer<QGuiApplication>
>>>> app(Sailfish::createApplication(argc, argv));
>>>> QScopedPointer<QQuickView> view(Sailfish::createView("main.qml"));
>>>> view->rootContext()->setContextProperty("cppproperty", "Hello world");
>>>> Sailfish::showView(view.data());
>>>> return app->exec();
>>>> }
>>>>
>>>> You suggest I could this:
>>>>
>>>> Q_DECL_EXPORT int main(int argc, char *argv[])
>>>> {
>>>> QScopedPointer<QGuiApplication>
>>>> app(Sailfish::createApplication(argc, argv));
>>>> QScopedPointer<QQuickView> view(Sailfish::createView());
>>>> view->rootContext()->setContextProperty("cppproperty", "Hello world");
>>>> Sailfish::setView(view.data(), "main.qml");
>>>> Sailfish::showView(view.data());
>>>> return app->exec();
>>>> }
>>>>
>>>> ..but will then run into your template error:
>>>> file:///usr/share/setContextPropertyDemo/main.qml: File not found
>>>>
>>>> Maybe the qmlRegister**Type is the best approach after all. The
>>>> downside is (unless I have missed something) that I will then
>>>> have to create a class for my property, whereas with the
>>>> setContextProperty I can use a string literal or a primitive type
>>>> like int.
>>>>
>>>> Merci
>>>>
>>>> Chris
>>>>
>>>>
>>>> Zitat von "Lucien XU" <sfietkonstantin at free.fr>:
>>>>
>>>>> Hello guys !
>>>>>
>>>>> It might be useful to use qmlRegister**Type (uncreatable,
>>>>> singleton etc.) to
>>>>> expose C++ components to QML. But if you really want to use
>>>>> rootContext()-
>>>>>> setContextProperty, you have to be cautious.
>>>>>
>>>>> Actually, if you pass the qml file to the view before registering C++
>>>>> components, the QML components won't be able to see the C++
>>>>> ones, so you have
>>>>> to call setContextProperty before calling setSource (or calling the
>>>>> createView("main.qml") method).
>>>>>
>>>>> You have to call the parameter-less method createView(), and then, call
>>>>> setView(QQuickView *, QString) to pass the source QML file.
>>>>>
>>>>> But beware, there is a bug in the template. See
>>>>> https://lists.sailfishos.org/pipermail/devel/2013-August/000529.html.
>>>>>
>>>>> Hopes it helps (because I'm not very clear in this mail)
>>>>> Cheers,
>>>>> Lucien
>>>>>
>>>>> Le dimanche 4 août 2013 17:05:01 christopher.lamb at thurweb.ch a écrit :
>>>>>> Hi Martin
>>>>>>
>>>>>> Curiouser and Curiouser!
>>>>>>
>>>>>> Just to be sure, I went back and tested your suggestion in a demo
>>>>>> project based on the default "Hello Sailors" new project template.
>>>>>>
>>>>>> Here I pass the c++ property cppproperty with the value "Hello World".
>>>>>> In the QML FirstPage this is concatenated to the "Hello Sailors" label
>>>>>> text.
>>>>>>
>>>>>> I still get this error:
>>>>>> file:///opt/sdk/setContextPropertyDemo/usr/share/setContextPropertyDemo/page
>>>>>> s/FirstPage.qml:34: ReferenceError: cppproperty is not defined
>>>>>>
>>>>>> Yet the app displays "Hello Sailors: Hello world".
>>>>>>
>>>>>> So a property can be passed as you suggested, it can be used. The
>>>>>> error must be wrong!
>>>>>>
>>>>>> Chris
>>>>>>
>>>>>> P.s you test the same by creating a default new Sailfish project, and
>>>>>> replacing the main.cpp and FirstPage.qml with the code below.
>>>>>>
>>>>>>
>>>>>> //start main.cpp
>>>>>> #include <QGuiApplication>
>>>>>> #include <QQuickView>
>>>>>> #include <QQmlContext>
>>>>>>
>>>>>> #include "sailfishapplication.h"
>>>>>>
>>>>>> Q_DECL_EXPORT int main(int argc, char *argv[])
>>>>>> {
>>>>>> QScopedPointer<QGuiApplication>
>>>>>> app(Sailfish::createApplication(argc, argv));
>>>>>> QScopedPointer<QQuickView> view(Sailfish::createView("main.qml"));
>>>>>> view->rootContext()->setContextProperty("cppproperty", "Hello world");
>>>>>> Sailfish::showView(view.data());
>>>>>>
>>>>>> return app->exec();
>>>>>> }
>>>>>> //end main.cpp
>>>>>>
>>>>>>
>>>>>> //start FirstPage.qml
>>>>>> import QtQuick 2.0
>>>>>> import Sailfish.Silica 1.0
>>>>>> import Sailfish.Silica.theme 1.0
>>>>>>
>>>>>>
>>>>>> Page {
>>>>>> id: page
>>>>>>
>>>>>> // To enable PullDownMenu, place our content in a SilicaFlickable
>>>>>> SilicaFlickable {
>>>>>> anchors.fill: parent
>>>>>>
>>>>>> // PullDownMenu and PushUpMenu must be declared in
>>>>>> SilicaFlickable, SilicaListView or SilicaGridView
>>>>>> PullDownMenu {
>>>>>> MenuItem {
>>>>>> text: "Show Page 2"
>>>>>> onClicked: pageStack.push(Qt.resolvedUrl("SecondPage.qml"))
>>>>>> }
>>>>>> }
>>>>>>
>>>>>> // Tell SilicaFlickable the height of its content.
>>>>>> contentHeight: childrenRect.height
>>>>>>
>>>>>> // Place our content in a Column. The PageHeader is always
>>>>>> placed at the top
>>>>>> // of the page, followed by our content.
>>>>>> Column {
>>>>>> width: page.width
>>>>>> spacing: Theme.paddingLarge
>>>>>> PageHeader {
>>>>>> title: "UI Template"
>>>>>> }
>>>>>> Label {
>>>>>> x: Theme.paddingLarge
>>>>>> text: "Hello Sailors: " + cppproperty
>>>>>> color: Theme.secondaryHighlightColor
>>>>>> font.pixelSize: Theme.fontSizeLarge
>>>>>> }
>>>>>> }
>>>>>> }
>>>>>> }
>>>>>> //end FirstPage.qml
>>>>>>
>>>>>> Zitat von "Martin Grimme" <martin.grimme at gmail.com>:
>>>>>>> Hi,
>>>>>>>
>>>>>>> you don't want to set the context property on the
>>>>>>> QmlApplicationViewer, which was dead Nokia code to target Symbian and
>>>>>>> Harmattan, anyway.
>>>>>>> QmlApplicationViewer was derived from QmlView, where it got the
>>>>>>> rootContext() method from.
>>>>>>>
>>>>>>> With Qt5, QmlView was renamed to QQuickView. And when using the
>>>>>>>
>>>>>>> functions from sailfishapplication.h, you get a QQuickView*, e.g.:
>>>>>>> QScopedPointer<QQuickView> view(Sailfish::createView("main.qml"));
>>>>>>> view->rootContext()->setContextProperty("platform", platformId);
>>>>>>>
>>>>>>> Martin
>>>>>>>
>>>>>>> 2013/8/4, christopher.lamb at thurweb.ch <christopher.lamb at thurweb.ch>:
>>>>>>>> Hi all
>>>>>>>>
>>>>>>>> What is the recommended way to pass simple c++ properties from the
>>>>>>>> main.cpp to the QML part of a project using the Qt 5 Alpha?
>>>>>>>>
>>>>>>>> In the good old days of the first Alpha, I used to do this Harmattan
>>>>>>>> style using
>>>>>>>>
>>>>>>>> QmlApplicationViewer viewer;
>>>>>>>> viewer.rootContext()->setContextProperty("platform", platformId);
>>>>>>>>
>>>>>>>> This would make the c++ property platformId available to my qml code
>>>>>>>> as the property platform.
>>>>>>>>
>>>>>>>> Now with Qt5 / Alpha 2 the QmlApplicationViewer is no longer created.
>>>>>>>>
>>>>>>>> The tutorial linked below suggests that the QmlApplicationViewer files
>>>>>>>> could be ported to Qt5, so I guess I could grab these files from an
>>>>>>>> old Harmattan project and do that.
>>>>>>>>
>>>>>>>> https://qt-project.org/doc/qt-5.0/qtdoc/portingqmlapp.html
>>>>>>>>
>>>>>>>> But somehow that feels like carting old baggage around.
>>>>>>>>
>>>>>>>> Is their a Sailfish native way of doing the same?
>>>>>>>>
>>>>>>>> Thanks
>>>>>>>>
>>>>>>>> Chris
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> _______________________________________________
>>>>>>>> SailfishOS.org Devel mailing list
>>>>>>
>>>>>> _______________________________________________
>>>>>> SailfishOS.org Devel mailing list
>>>>> _______________________________________________
>>>>> SailfishOS.org Devel mailing list
>>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> SailfishOS.org Devel mailing list
>>>>
>>>>
>>>> ----- Ende der weitergeleiteten Nachricht -----
>>>>
>>>> _______________________________________________
>>>> SailfishOS.org Devel mailing list
>>>
>>>
>>
>>
>>
>>
>> ----- Ende der weitergeleiteten Nachricht -----
>>
>>
>
>
More information about the Devel
mailing list