Active Topics

 


Reply
Thread Tools
Community Council | Posts: 4,920 | Thanked: 12,867 times | Joined on May 2012 @ Southerrn Finland
#101
Originally Posted by levone1 View Post
Oh - so if I change the file first, then install the patch, it should work... I'll check it out...
It depends on what the change is; patchmanager just applies patches with "standard" unix patch utility which can apply hunks if the changes done to the file are not touching the same lines and it can still detect the correct place to apply the hunk.

The way to learn is to read the file and see what changes the patch is making, just like @coderus said.
__________________
Dave999: Meateo balloons. What’s so special with em? Is it a ballon?
 

The Following 3 Users Say Thank You to juiceme For This Useful Post:
Markkyboy's Avatar
Posts: 433 | Thanked: 727 times | Joined on Oct 2012 @ Costa Blanca, España
#102
Hi all,

I've made myself a basic weather application, it uses the OpenWeatherMap.org API for data.

I would like to know how to enter my Weather API URL to my `weather.js` file using Dialog, but I'm unsure how to do it. I have played around with the example from Jolla, but I don't know quite what I'm doing......help!

The weather.js file uses XmlHttpRequest to fetch the data.

Code:
function requestWeatherData(cntr) {
    var xhr = new XMLHttpRequest;
    xhr.open("GET", `MY API KEY AND ID HERE`);
    xhr.onreadystatechange = function () {
        if (xhr.readyState === XMLHttpRequest.DONE) {
            cntr.weatherData = JSON.parse(xhr.responseText)
        }
    }
    xhr.send();
}
thanks,
__________________
..oO(Don't just sit there standing around, pick up a shovel and sweep up!)Oo..
 

The Following User Says Thank You to Markkyboy For This Useful Post:
Posts: 284 | Thanked: 661 times | Joined on Aug 2013 @ Finland
#103
is your API key embedded to url? Then you can just do this:

Code:
let url = 'https.//www.example.com?api_key=' + API_key;
the key might need to be converted to string, perhaps. Also need to check what name the API key has, it might not be api_key like in the url.

I would then use fetch api to get the response:

Code:
let response = await fetch(url);
let data = await response.json();

// parse data here
 

The Following 3 Users Say Thank You to Thoke For This Useful Post:
Posts: 479 | Thanked: 1,284 times | Joined on Jan 2012 @ Enschede, The Netherlands
#104
Originally Posted by Thoke View Post
I would then use fetch api to get the response:
Is the fetch API present in SFOS's ancient Qt version? The async await-construct isn't, I found out the hard way a few months ago. Native Promises are neither, by the way.
 

The Following 3 Users Say Thank You to Fuzzillogic For This Useful Post:
Posts: 284 | Thanked: 661 times | Joined on Aug 2013 @ Finland
#105
Ah, right. Didn't know that. I suggested fetch because it's so easy. Let me check how to do it with xmlhttprequest...
 

The Following User Says Thank You to Thoke For This Useful Post:
Posts: 284 | Thanked: 661 times | Joined on Aug 2013 @ Finland
#106
Found from here: https://openweathermap.org/forecast5#call

Code:
api.openweathermap.org/data/2.5/forecast?zip={zip code},{country code}&appid={your api key}
so you can contstruct your url as per my previous suggestion.

EDIT: I had to check, but XMLHttpRequest doesn't allow cross-site requests, so it wont work without modifications. With a short look, it seems there's CORS and JSONP to circumvent the restriction, but I don't know if they're supported on SFOS, and this is also something I have no experience implementing.

I would try it anyways, though. Maybe there's no restrictions when using it when you are not actually doing this js stuff with a browser attached.

Last edited by Thoke; 2020-08-24 at 18:12.
 

The Following 2 Users Say Thank You to Thoke For This Useful Post:
Posts: 301 | Thanked: 531 times | Joined on Aug 2010 @ The Netherlands
#107
Is there a way to force a ListModel to refresh, when the database records have been changed?

I have a page, where the ListModel is filled by a JS function getting a SELECT from a SQLite database. It is a list of letters, with a possible value, e.g. A="3", B="".
After some experiments with TextFields I chose for Buttons. Then a Dialog opens, where the value can be changed.

However, after the change, the Button does not show the new value of the letter. Can I force an update? Maybe by a signal from the PageStack that the current page has become visible again?

The Button is now configured like:
Code:
Button {
	height: Theme.itemSizeMedium
	preferredWidth: Theme.buttonWidthLarge
	anchors.horizontalCenter: parent.horizontalCenter
	text: letter + " = " + (lettervalue === "" ? "<?>" : lettervalue) + qsTr(". Click to change")
	onClicked: {
		generic.lettEdit  = letter
		pageStack.push(Qt.resolvedUrl("LetterPage.qml"),
					   {"lettervalue": lettervalue})
		listModelLett.updateLett();
	}
}
Attached Images
 
__________________
Palm Treo -> N900 -> N9 -> Jolla -> SailfishX -> XA2
Developer mode novice, and enjoying it

Last edited by rob_kouw; 2020-08-26 at 15:38.
 

The Following User Says Thank You to rob_kouw For This Useful Post:
coderus's Avatar
Posts: 6,436 | Thanked: 12,701 times | Joined on Nov 2011 @ Ängelholm, Sweden
#108
how do you work with model?
__________________
Telegram | Openrepos | GitHub | Revolut donations
 

The Following User Says Thank You to coderus For This Useful Post:
Posts: 301 | Thanked: 531 times | Joined on Aug 2010 @ The Netherlands
#109
Thanks for helping, coderus!

The simplified code looks like this.

Code:
import QtQuick 2.0
import Sailfish.Silica 1.0
import "../scripts/Database.js" as Database

Page {
    id: thisWayptPage

    ListModel {
        id: listModelLett

        function updateLett()
        {
            listModelLett.clear();
            var lettrs = Database.getLettersWP(generic.wpId);
            for (var i = 0; i < lettrs.length; ++i) {
                listModelLett.append(lettrs[i]);
            }
        }
    }

    Component.onCompleted: listModelLett.updateLett();

    SilicaFlickable {

        PageHeader { ... }

        Column {

            TextArea { ... }

            Repeater {
                model: listModelLett

                ListItem {

                    Button {
                        text: letter + qsTr(". Click to change")
                        onClicked: {
                            pageStack.push(Qt.resolvedUrl("LetterPage.qml"),
                                           {"letterid": letterid})
                        }
                    }
                 }
            }
        }
    }
}
I took the ListModel from the app BudgetBook. The database function just reads the records from the table, in order to fill the ListModel.

On clicking the button, the Dialog in "LetterPage.qml" provides the possibility to enter a value for the letter. Then onDone, the value is stored in the database. After the pop() I don't know how to update the ListModel from the updated database.

This morning I thought of a work-around, but a proper method would be nice.
__________________
Palm Treo -> N900 -> N9 -> Jolla -> SailfishX -> XA2
Developer mode novice, and enjoying it
 

The Following User Says Thank You to rob_kouw For This Useful Post:
Posts: 301 | Thanked: 531 times | Joined on Aug 2010 @ The Netherlands
#110
Hm. Work-around is not working.
__________________
Palm Treo -> N900 -> N9 -> Jolla -> SailfishX -> XA2
Developer mode novice, and enjoying it
 

The Following User Says Thank You to rob_kouw For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 15:09.