Menu

Main Menu
Talk Get Daily Search

Member's Online

    User Name
    Password

    Qt Networking & Connectivity

    Reply
    StewartHolmes | # 1 | 2010-04-08, 00:52 | Report

    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

    Edit | Forward | Quote | Quick Reply | Thanks

     
    uvatbc | # 2 | 2010-04-08, 01:08 | Report

    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.

    Edit | Forward | Quote | Quick Reply | Thanks

     
    krk969 | # 3 | 2010-04-08, 05:52 | Report

    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

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following 4 Users Say Thank You to krk969 For This Useful Post:
    danielwilms, mbo, nath, uvatbc

     
    StewartHolmes | # 4 | 2010-04-08, 12:12 | Report

    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.

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following 6 Users Say Thank You to StewartHolmes For This Useful Post:
    Helmuth, krk969, marxian, mr id, Sasler, uvatbc

     
    pigling | # 5 | 2010-10-04, 06:02 | Report

    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.

    Edit | Forward | Quote | Quick Reply | Thanks

     
    scottrNZ | # 6 | 2010-10-08, 08:20 | Report

    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.

    Edit | Forward | Quote | Quick Reply | Thanks

     
    laitiju | # 7 | 2010-10-08, 09:56 | Report

    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_INTERFACE, ICD_DBUS_API_PATH,
                                           
    ICD_DBUS_API_INTERFACE, dBusConnection);
                                           
        
    //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));
    } 

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following User Says Thank You to laitiju For This Useful Post:
    scottrNZ

     
    scottrNZ | # 8 | 2010-10-08, 10:51 | Report

    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.

    Edit | Forward | Quote | Quick Reply | Thanks

     
    pigling | # 9 | 2010-10-11, 08:36 | Report

    Divanov has built an article for this issue in wiki of Nokia forum:Connection state aware applications for Maemo 5 with Qt Mobility

    Edit | Forward | Quote | Quick Reply | Thanks

     
vBulletin® Version 3.8.8
Normal Logout