How to know when there is no internet for a listview

by Retired on ‎09-24-2013 10:46 AM (1,447 Views)

Symptoms

Sometimes we have a list view from XML over the web and we want to show an error message when there is no internet connection, here are 2 ways to know it without C++.

Diagnosis

We can do this in two ways, one of them with the function called onError and the other finding the number of elements on the list.

Solution

The first solution is with onError, that enables the label where we will notify the error (which is disabled).

DataSource {
			    id: dataSource
                            source: "url"
                           
			             query: "rss/channel/item"
		                    onDataLoaded: {
		                        groupDataModel.insertList(data);

		                    }

                    onError: {                        
label.enabled = true label.visible = true } }

 

The second solution is getting the number of items in the list. If it is 0 means there were no elements loaded, hence there is no internet.

 

onCreationCompleted:{

if(groupDataModel.size()==0)
{
    label.enabled=true;
    label.visible=true;
}
}