Active Topics

 


Reply
Thread Tools
Posts: 17 | Thanked: 42 times | Joined on Feb 2010
#1
Hi all,

I'm using QNetworkManager to make some requests over the internet. My problem is that I don't seem to have the tools to let me work out the connectivity of the device.

For example, if I have a QNetworkManager object called manager, and I call

manager->post(request, requestData);

If the user has connection to the internet, everything is fine. If not, then what will happen is that an error will be generated, which I can handle, and the connection window will popup, allowing the user to choose a connection.

What I'd like to do is to poll to see if the user is connected somehow. I can do this by retrying the request, because this would re-open the connection window (spamming the user with it while, for example, the device is establishing the connection the user previously selected).

Any ideas?

Stewart
 
Posts: 1,048 | Thanked: 979 times | Joined on Mar 2008 @ SF Bay Area
#2
Not sure if its really a solution, but you could use QTcpSocket to connect to a "known" hostname - like example.com and if it connects without errors, you have a valid network connection.

As to whether this way will also popup a window asking you to connect - not sure, haven't tried it.

Just hazarding a guess, but d-bus may have the info you need.
 
krk969's Avatar
Posts: 754 | Thanked: 630 times | Joined on Sep 2009 @ London
#3
QtMobility will bring some of the bearer management functionality.
Also whatever it is that you do, make sure that the user is aware a connection is being made transparently, so its not unexpected at times .

Also for now you could try
dbus-send --type=method_call --system --dest=com.nokia.icd /com/nokia/icd com.nokia.icd.connect string:IAP uint32:0

IAP is the internet access point name I guess.

some useful links are here, here and here
__________________
Developer of :
Buddy - budget/expense manager ( website )
Showtime - a telly channel listing viewer/reminder ( website )
Travelapp - london underground status/planner ( website )
Batlevel - desktop widget for battery level ( website )

“I hear and I forget. I see and I remember. I do and I understand.”
 

The Following 4 Users Say Thank You to krk969 For This Useful Post:
Posts: 17 | Thanked: 42 times | Joined on Feb 2010
#4
Thanks for the ideas guys,

I checked QTcpSocket, but this opens the connections window (as I suppose it should really).

krk969; rather than make a connection, what I want to achieve is to check whether there currently is a connection. Initially, I can just fire off a QNetworkRequest; if there is a connection, I'll get some data, if not, I can find out through the appropriate error. If there is no such connection, what I want to do is to silently poll to wait for a connection.

After some digging, what I've found is, until bearer management is implemented for Maemo/MeeGo, QNetworkInterface can be used. The N900 can be connected by either gprs or wlan. So what I do:

Code:
void retry()
{
    QNetworkInterface wlan = QNetworkInterface::interfaceFromName("wlan0");
    QNetworkInterface gprs = QNetworkInterface::interfaceFromName("gprs0");

    if( (wlan.isValid() && wlan.flags().testFlag(QNetworkInterface::IsUp)) || (gprs.isValid() && gprs.flags().testFlag(QNetworkInterface::IsUp)) )
    {
        qDebug() << "Connection found.";
    }
    else
    {
        qDebug() << "No connection found on retry, retrying again";
        QTimer::singleShot(500, this, SLOT(retry()));
    }
}
This works well; the only issue it does suffer from is that if the N900 is connected via usb in PC suite mode, wlan0 reports that it is connected even if not connected to a wifi network (I guess this is because I'm using mad developer tools with USB mode g_ether). In such a state, it's therefore not possible to really detect whether the wifi is really connected, but this can be handled by the error messages given by QNetworkReply.
 

The Following 6 Users Say Thank You to StewartHolmes For This Useful Post:
Posts: 27 | Thanked: 8 times | Joined on Jan 2009 @ Singapore
#5
This is a good way. However, if I fails to choose the connectivity from possible network list, how you handle this? The retry() will run unlimited.


Originally Posted by StewartHolmes View Post
Thanks for the ideas guys,

I checked QTcpSocket, but this opens the connections window (as I suppose it should really).

krk969; rather than make a connection, what I want to achieve is to check whether there currently is a connection. Initially, I can just fire off a QNetworkRequest; if there is a connection, I'll get some data, if not, I can find out through the appropriate error. If there is no such connection, what I want to do is to silently poll to wait for a connection.

After some digging, what I've found is, until bearer management is implemented for Maemo/MeeGo, QNetworkInterface can be used. The N900 can be connected by either gprs or wlan. So what I do:

Code:
void retry()
{
    QNetworkInterface wlan = QNetworkInterface::interfaceFromName("wlan0");
    QNetworkInterface gprs = QNetworkInterface::interfaceFromName("gprs0");

    if( (wlan.isValid() && wlan.flags().testFlag(QNetworkInterface::IsUp)) || (gprs.isValid() && gprs.flags().testFlag(QNetworkInterface::IsUp)) )
    {
        qDebug() << "Connection found.";
    }
    else
    {
        qDebug() << "No connection found on retry, retrying again";
        QTimer::singleShot(500, this, SLOT(retry()));
    }
}
This works well; the only issue it does suffer from is that if the N900 is connected via usb in PC suite mode, wlan0 reports that it is connected even if not connected to a wifi network (I guess this is because I'm using mad developer tools with USB mode g_ether). In such a state, it's therefore not possible to really detect whether the wifi is really connected, but this can be handled by the error messages given by QNetworkReply.
 
Posts: 34 | Thanked: 32 times | Joined on May 2010 @ Hamilton, New Zealand
#6
I have a similar problem,

I'm using a QNetworkAccessManager object to fire off GET requests, however I find that if the device does not have a network connection it automatically connects to my 3G provider. What I'd like is to have it pop up the standard internet connection selection window to allow the user to select the internet access point to use.

Any hints would be appreciated.

Cheers, Scott.
 
Posts: 16 | Thanked: 18 times | Joined on Sep 2010
#7
Originally Posted by scottrNZ View Post
I'm using a QNetworkAccessManager object to fire off GET requests, however I find that if the device does not have a network connection it automatically connects to my 3G provider. What I'd like is to have it pop up the standard internet connection selection window to allow the user to select the internet access point to use.
This depends on user settings. If the user has disabled the connect automatically, then the dialog is shown.

However you can request the connection dialog via D-Bus.

Qt code (I haven't tried this):
PHP Code:
#include <icd/dbus_api.h>

static QDBusConnection dBusConnection QDBusConnection::systemBus();

ICD::ICD(QObject *parent)
    : 
QObject(parent)
{
    
QDBusInterface *dBusInterface = new QDBusInterface(ICD_DBUS_API_INTERFACEICD_DBUS_API_PATH,
                                       
ICD_DBUS_API_INTERFACEdBusConnection);
                                       
    
//From dbus_api.h: Request the 'Select connection' dialog; 
    //Only connectiviy UIs should be using this function.
    
dBusInterface->call(ICD_DBUS_API_SELECT_REQ,
                        
QVariant((unsigned int)ICD_CONNECTION_FLAG_USER_EVENT));

 

The Following User Says Thank You to laitiju For This Useful Post:
Posts: 34 | Thanked: 32 times | Joined on May 2010 @ Hamilton, New Zealand
#8
Originally Posted by laitiju View Post
This depends on user settings. If the user has disabled the connect automatically, then the dialog is shown.
Many thanks for the useful information.

Interestingly, I had my Internet Connection options set to connect automatically but only to WLAN. When I set it to Always Ask, the expected behaviour occurred and the Select Connections dialog appeared.

However when set to connect automatically to WLAN, the device connected to my 3G provider, rather than the WLAN network it usually connects to. Very odd, I can only assume this is a bug.

Thanks again for the useful information though.

Cheers, Scott.
 
Posts: 27 | Thanked: 8 times | Joined on Jan 2009 @ Singapore
#9
Divanov has built an article for this issue in wiki of Nokia forum:Connection state aware applications for Maemo 5 with Qt Mobility
 
Reply


 
Forum Jump


All times are GMT. The time now is 06:22.