PDA

View Full Version : Problem with LocalStorage



witusx93
16th April 2015, 18:52
Hello,
I started using Qt and I have a project in which I have to use LocalStorage. I dont know how exactly it works.
I checked this page: [http://doc.qt.io/qt-5/qtquick-localstorage-qmlmodule.html ](link url)
but I still dont know how to use it in bigger project.
For example how to write my own function that returns a row and use it in other file.qml

wysota
20th April 2015, 07:33
What exactly is the problem?

witusx93
20th April 2015, 17:13
@Wysota
I am gonna write in polish, couse it will be easier to describe problem.
Chodzi o to, że muszę muszę pracować z tym LocalStorage. Chciałbym zrobic w jednym pliku qml funkcje, a w innym wywolywac je wywolywac, np DodajDoBazy(argumenty), a w innym np onClicked: DodajDoBazy(). I nie weim jak w innym pliku odnosic sie do tych funkcji. Czy mozna zrobic to w jakis lepszy sposob? Nie wiem tez za bardzo jak uzyc localStorage w liscie? Np ze lista ma godziny 00:00 do 23:00 i w niektore godziny jest jakies zdarzenie, a w inne nie, zrobilem przycisk filtruj, zeby wyswietlalo TYLKO godziny w ktorych cos jest i nie weim za bardzo jak to zrobic na liscie, czy jest jakas opcja visible czy co.

EDIT:
OK. I want to create functions in a .qml file and use these functions in other file, e.g. AddToDB() nad in other file onClicked: AddToDB() (Now how to call this function??) Is there any other way to do this?
Second thing is that I dont really know how to use LocalStorage in ListModel. Eg. I have hours 00:00 - 23:00 and things to do on some of them. I created the button and I want it to filter ONLY the hours with things to do.

wysota
20th April 2015, 17:32
@Wysota
I am gonna write in polish, couse it will be easier to describe problem.

It is an English-spoken site. If everyone used their native language just because there is one other person who understands it we would have to integrate Google Translate into the site. I understand it is easier for you to ask in Polish but please try translating your question to English.

witusx93
20th April 2015, 18:10
Ok, edited my post

wysota
20th April 2015, 19:06
@Wysota
I am gonna write in polish, couse it will be easier to describe problem.
Chodzi o to, że muszę muszę pracować z tym LocalStorage. Chciałbym zrobic w jednym pliku qml funkcje, a w innym wywolywac je wywolywac, np DodajDoBazy(argumenty), a w innym np onClicked: DodajDoBazy(). I nie weim jak w innym pliku odnosic sie do tych funkcji. Czy mozna zrobic to w jakis lepszy sposob? Nie wiem tez za bardzo jak uzyc localStorage w liscie? Np ze lista ma godziny 00:00 do 23:00 i w niektore godziny jest jakies zdarzenie, a w inne nie, zrobilem przycisk filtruj, zeby wyswietlalo TYLKO godziny w ktorych cos jest i nie weim za bardzo jak to zrobic na liscie, czy jest jakas opcja visible czy co.

EDIT:
OK. I want to create functions in a .qml file and use these functions in other file, e.g. AddToDB() nad in other file onClicked: AddToDB() (Now how to call this function??) Is there any other way to do this?
Second thing is that I dont really know how to use LocalStorage in ListModel. Eg. I have hours 00:00 - 23:00 and things to do on some of them. I created the button and I want it to filter ONLY the hours with things to do.

You can create a library of functions (with ".pragma library") and then import the script file whenever you want and simply call those functions from whereever you need. Regarding the list model, I have no idea how you would want to use LocalStorage there. ListModel is a crude container for simple item data, if you really have to, you can of course insert data to the model when you need it but that is it. It is much better to implement your model in C++ (e.g. using QtSql module) and then export the objects you need (the model itself and maybe a filter proxy model) to QML.