×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Mar 2009
    Location
    Chennai, India
    Posts
    49

    Which is the correct way to close a QNetworkSession?

    I am using Nokia Qt SDK 1.0.2 and I am using Mobility bearer API to open and close network connections.

    I have declared the following in my header file.

    Code:
        QNetworkSession *m_session;
    In the CPP file, I have two functions - one to open and one to close

    Code:
    bool MainWindow::OpenConnection()
    {
        QNetworkConfigurationManager manager;
        const bool selectIap = (manager.capabilities()& QNetworkConfigurationManager::CanStartAndStopInterfaces);
        QNetworkConfiguration defaultIap = manager.defaultConfiguration();
    
        if(!defaultIap.isValid() && (!selectIap && defaultIap.state() != QNetworkConfiguration::Active))
        {
            return false;
        }
        m_session = new QNetworkSession(defaultIap,this);
        if(m_session->state() == QNetworkSession::Connected) {
            return true;
        }
        m_session->open();
        if(m_session->waitForOpened() == false)
        {
            return false;
        }
        return m_session->isOpen();
    }

    Code:
    bool MainWindow::CloseConnection() {
            m_session->stop();
            m_session->close();
    //    m_session->deleteLater(); // I have tried all four options(stop,close,deletelater,delete) one by one. all of them gave the same exception
    //        delete m_session;
            return true;
    }
    I am calling the openconnection and then making a network request. In the finished SLOT, i call the close connection.

    The open connection works fine as expected. It opens the network connection. But the close connection is not working. When the program enters closeconnection, I get the following message in the Qt creator application output.

    exception on 3 [will close the socket handle - hack]
    Is this a bug or there is a correct way to close a network connection?

    Thanks
    Last edited by emaillenin; 2011-04-24 at 05:54. Reason: code formatting

  2. #2
    Registered User
    Join Date
    Mar 2009
    Location
    Chennai, India
    Posts
    49

    Re: Which is the correct way to close a QNetworkSession?

    I have asked 3 questions in this forum. But have received answers for none

  3. #3
    Registered User
    Join Date
    Jun 2007
    Location
    Mumbai, India
    Posts
    1,998

    Re: Which is the correct way to close a QNetworkSession?

    In Qt doc its stated that

    Note: After the request has finished, it is the responsibility of the user to delete the QNetworkReply object at an appropriate time. Do not directly delete it inside the slot connected to finished(). You can use the deleteLater() function.

    May be something similar applies to QNetworkSession too just try closing it later.

  4. #4
    Registered User
    Join Date
    Oct 2010
    Posts
    31

    Re: Which is the correct way to close a QNetworkSession?

    You only have to call close() method, don't call stop().

  5. #5
    Registered User
    Join Date
    Mar 2009
    Location
    Chennai, India
    Posts
    49

    Re: Which is the correct way to close a QNetworkSession?

    Quote Originally Posted by kamalakshan View Post
    In Qt doc its stated that

    Note: After the request has finished, it is the responsibility of the user to delete the QNetworkReply object at an appropriate time. Do not directly delete it inside the slot connected to finished(). You can use the deleteLater() function.

    May be something similar applies to QNetworkSession too just try closing it later.
    In the finished SLOT of QNetworkReply, I am calling the deleteLater function as per the documentation. This is not related with closing the network connection.
    There is no such similar method for closing the network connection in the QNetworkSession (http://doc.qt.nokia.com/qtmobility-1...rksession.html)

  6. #6
    Registered User
    Join Date
    Mar 2009
    Location
    Chennai, India
    Posts
    49

    Re: Which is the correct way to close a QNetworkSession?

    Quote Originally Posted by Pavel.Rusin View Post
    You only have to call close() method, don't call stop().
    Calling only close() in the CloseConnection function results in the same exception mentioned earlier.

  7. #7
    Registered User
    Join Date
    Mar 2009
    Location
    Chennai, India
    Posts
    49

    Re: Which is the correct way to close a QNetworkSession?

    Since Qt way is not working as expected, are there any native symbian method to open the network connection and close it after the get request by QNetworkAccessManager?

  8. #8
    Registered User
    Join Date
    Mar 2009
    Location
    Chennai, India
    Posts
    49

    Re: Which is the correct way to close a QNetworkSession?

    I have started trying out the native symbian way of doing it.

    Code:
    bool m2mnetwork::OpenConnection_s() {
    #if defined(Q_OS_SYMBIAN)
        TInt error;
        iSession.OpenL();
        error = isockServ.Connect(KESockDefaultMessageSlots);
        error = iConnection.Open(isockServ,KConnectionTypeDefault);
        // open the IAP communications database
        CCommsDatabase* commDB = CCommsDatabase::NewL(EDatabaseTypeIAP);
        CleanupStack::PushL(commDB);
    
        // initialize a view
        CCommsDbConnectionPrefTableView* commDBView =
                commDB->OpenConnectionPrefTableInRankOrderLC(ECommDbConnectionDirectionUnknown);
    
        // go to the first record
        User::LeaveIfError(commDBView->GotoFirstRecord());
    
        // Declare a prefTableView Object.
        CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref pref;
    
        // read the connection preferences
        commDBView->ReadConnectionPreferenceL(pref);
    
        TUint32 iapID = pref.iBearer.iIapId;
    
        // pop and destroy the IAP View
        CleanupStack::PopAndDestroy(commDBView);
    
        // pop and destroy the database object
        CleanupStack::PopAndDestroy(commDB);
    
        // Now we have the iap Id. Use it to connect for the connection.
        // setup preferences
        TCommDbConnPref connectPref;
        connectPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
        connectPref.SetDirection(ECommDbConnectionDirectionUnknown);
        connectPref.SetBearerSet(ECommDbBearerGPRS);
    
        //Sets the CommDb ID of the IAP to use for this connection
        connectPref.SetIapId(iapID);
    
        User::LeaveIfError(iConnection.Start(connectPref));
    #endif
        return true;
    }
    But, I get the following error when the program reaches the line iSession.OpenL();

    [Qt Message] CActiveScheduler::RunIfReady() returned error: -1
    My Pro file

    QT += core gui network xml sql
    CONFIG += mobility
    MOBILITY += messaging
    MOBILITY += bearer
    symbian {
    ICON = icon.svg
    TARGET.UID3 = 0xe5f21dcd
    # TARGET.CAPABILITY +=
    TARGET.EPOCSTACKSIZE = 0x14000
    TARGET.EPOCHEAPSIZE = 0x020000 0x800000
    TARGET.CAPABILITY = ReadUserData \
    WriteUserData \
    ReadDeviceData \
    WriteDeviceData \
    NetworkServices \
    LocalServices \
    UserEnvironment
    LIBS += -lws32\
    -lcone\
    -leikcore\
    -lavkon\
    -lcommdb\
    -lesock\
    -lefsrv\
    -lhttp
    }
    Any help about that particular error will be much appreciated..Thanks..

Similar Threads

  1. Which is the correct way to close a form?
    By symbi4n_programmer in forum Symbian
    Replies: 1
    Last Post: 2009-09-17, 17:41
  2. Replies: 3
    Last Post: 2009-06-12, 10:55
  3. Replies: 3
    Last Post: 2008-12-20, 18:00
  4. New UNI-09 Step 7 - What is the correct way to pass?
    By komuto1 in forum Symbian Signed Support, Application Packaging and Distribution and Security
    Replies: 4
    Last Post: 2008-01-22, 14:21
  5. Replies: 1
    Last Post: 2007-12-06, 10:23

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×