qtmobility/tests/bearerex/bearerex.cpp
changeset 11 06b8e2af4411
parent 0 cfcbf08528c4
child 14 6fbed849b4f4
--- a/qtmobility/tests/bearerex/bearerex.cpp	Thu May 27 13:42:11 2010 +0300
+++ b/qtmobility/tests/bearerex/bearerex.cpp	Fri Jun 11 14:26:25 2010 +0300
@@ -1,6 +1,6 @@
 /****************************************************************************
 **
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
 **
@@ -299,8 +299,12 @@
 
 SessionTab::~SessionTab()
 {
+    // Need to be nulled, because modal dialogs may return after destruction of this object and
+    // use already released resources.
     delete m_NetworkSession;
+    m_NetworkSession = NULL;
     delete m_http;
+    m_http = NULL;
 }
 
 void SessionTab::on_createQHttpButton_clicked()
@@ -550,10 +554,16 @@
         msgBox.setText(QString("HTTP request finished successfully.\nReceived ")+QString::number(result.length())+QString(" bytes."));
     }
     msgBox.exec();
-    
-    sentRecDataLineEdit->setText(QString::number(m_NetworkSession->bytesWritten())+
-                                 QString(" / ")+
-                                 QString::number(m_NetworkSession->bytesReceived()));
+    // Check if the networksession still exists - it may have gone after returning from
+    // the modal dialog (in the case that app has been closed, and deleting QHttp will
+    // trigger the done() invokation).
+    if (m_NetworkSession) {
+        sentRecDataLineEdit->setText(QString::number(m_NetworkSession->bytesWritten())+
+                                     QString(" / ")+
+                                     QString::number(m_NetworkSession->bytesReceived()));
+    } else {
+        sentRecDataLineEdit->setText("Data amounts not available.");
+    }
 }
 
 // End of file