diff -r edb4d909cd48 libs/imwrapper/include/imwrapper/IMWrapperFactory.h
--- a/libs/imwrapper/include/imwrapper/IMWrapperFactory.h	Tue Aug 31 12:33:52 2010 +0200
+++ b/libs/imwrapper/include/imwrapper/IMWrapperFactory.h	Thu Sep 02 22:00:44 2010 +0200
@@ -23,6 +23,7 @@
 #include <imwrapper/IMAccount.h>
 
 #include <util/Interface.h>
+#include <util/Trackable.h>
 
 class IMChat;
 class IMConnect;
@@ -38,9 +39,11 @@
  * @author Philippe Bernery
  * @author Tanguy Krotoff
  */
-class IMWrapperFactory : Interface {
+class IMWrapperFactory : Interface, public Trackable {
 public:
 
+	Event<void()> terminatedEvent;
+
 	virtual ~IMWrapperFactory() {
 	}
 
diff -r edb4d909cd48 libs/imwrapper/src/purple/PurpleIMFactory.cpp
--- a/libs/imwrapper/src/purple/PurpleIMFactory.cpp	Tue Aug 31 12:33:52 2010 +0200
+++ b/libs/imwrapper/src/purple/PurpleIMFactory.cpp	Thu Sep 02 22:00:44 2010 +0200
@@ -356,6 +356,7 @@
 	// Don't stop gMainLoop here: this is called when the user logoff, but we
 	// want to keep the loop running for the whole time the application is
 	// running.
+	PurpleIMFactory::getFactory().terminatedEvent();
 }
 
 void PurpleIMFactory::terminate() {
diff -r edb4d909cd48 wengophone/src/presentation/qt/QtWengoPhone.cpp
--- a/wengophone/src/presentation/qt/QtWengoPhone.cpp	Tue Aug 31 12:33:52 2010 +0200
+++ b/wengophone/src/presentation/qt/QtWengoPhone.cpp	Thu Sep 02 22:00:44 2010 +0200
@@ -71,6 +71,7 @@
 #include <model/profile/UserProfile.h>
 
 #include <imwrapper/EnumPresenceState.h>
+#include <imwrapper/IMWrapperFactory.h>
 
 #include <qtutil/CloseEventFilter.h>
 #include <qtutil/Widget.h>
@@ -111,6 +112,7 @@
 	_chatWindow = NULL;
 	_activeTabBeforeCall = NULL;
 	_qtWebDirectory = NULL;
+	_want_to_exit = false;
 
 	NetworkProxyDiscovery::getInstance().proxyNeedsAuthenticationEvent +=
 		boost::bind(&QtWengoPhone::proxyNeedsAuthenticationEventHandler, this, _1, _2);
@@ -141,7 +143,15 @@
 	//TODO delete created objects
 }
 
+void QtWengoPhone::terminatedEventHandler() {
+	if(_want_to_exit)
+		QCoreApplication::exit(EXIT_SUCCESS);
+}
+
 void QtWengoPhone::initUi() {
+
+	IMWrapperFactory::getFactory().terminatedEvent += boost::bind(&QtWengoPhone::terminatedEventHandler,this);
+
 	// Init parts of the UI which do not rely on Control layer
 	QApplication::setQuitOnLastWindowClosed(false);
 
@@ -689,6 +699,8 @@
 	////
 
 	_cWengoPhone.terminate();
+	
+	_want_to_exit = true;
 }
 
 void QtWengoPhone::phoneComboBoxClicked() {
@@ -698,7 +710,7 @@
 }
 
 void QtWengoPhone::exitEvent() {
-	QCoreApplication::exit(EXIT_SUCCESS);
+	//QCoreApplication::exit(EXIT_SUCCESS);
 }
 
 void QtWengoPhone::showHistory() {
diff -r edb4d909cd48 wengophone/src/presentation/qt/QtWengoPhone.h
--- a/wengophone/src/presentation/qt/QtWengoPhone.h	Tue Aug 31 12:33:52 2010 +0200
+++ b/wengophone/src/presentation/qt/QtWengoPhone.h	Thu Sep 02 22:00:44 2010 +0200
@@ -99,6 +99,8 @@
 
 	void connectionStatusEventHandler(int totalSteps, int currentStep, const std::string & infoMsg);
 
+	void terminatedEventHandler();
+
 	QWidget * getWidget() const;
 
 	void setQtDialpad(QtDialpad * qtDialpad);
@@ -264,6 +266,8 @@
 	std::auto_ptr<QtIMAccountMonitor> _qtIMAccountMonitor;
 
 	QtWebDirectory * _qtWebDirectory;
+
+	bool _want_to_exit;
 };
 
 #endif	//OWQTWENGOPHONE_H
