move graphic operation to the same thread
diff --git a/chatdialog.cpp b/chatdialog.cpp
index 5527f96..4a3e59f 100644
--- a/chatdialog.cpp
+++ b/chatdialog.cpp
@@ -35,7 +35,8 @@
 {
   // have to register this, otherwise
   // the signal-slot system won't recognize this type
-  qRegisterMetaType<SyncDemo::ChatMessage>("SyncDemo::ChatMessage");
+  qRegisterMetaType<std::vector<Sync::MissingDataInfo> >("std::vector<Sync::MissingDataInfo>");
+  qRegisterMetaType<size_t>("size_t");
   setupUi(this);
   m_session = time(NULL);
 
@@ -56,12 +57,13 @@
     std::string syncPrefix = BROADCAST_PREFIX_FOR_SYNC_DEMO;
     syncPrefix += "/";
     syncPrefix += m_user.getChatroom().toStdString();
-    m_sock = new Sync::SyncAppSocket(syncPrefix, bind(&ChatDialog::processTreeUpdate, this, _1, _2), bind(&ChatDialog::processRemove, this, _1));
+    m_sock = new Sync::SyncAppSocket(syncPrefix, bind(&ChatDialog::processTreeUpdateWrapper, this, _1, _2), bind(&ChatDialog::processRemove, this, _1));
   }
 
   connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
   connect(setButton, SIGNAL(pressed()), this, SLOT(buttonPressed()));
-  connect(this, SIGNAL(msgReceived(const SyncDemo::ChatMessage)), this, SLOT(appendMessage(const SyncDemo::ChatMessage)));
+  connect(this, SIGNAL(dataReceived(QString, const char *, size_t)), this, SLOT(processData(QString, const char *, size_t)));
+  connect(this, SIGNAL(treeUpdated(const std::vector<Sync::MissingDataInfo>)), this, SLOT(processTreeUpdate(const std::vector<Sync::MissingDataInfo>)));
   //testDraw();
 }
 
@@ -105,7 +107,13 @@
 }
 
 void
-ChatDialog::processTreeUpdate(const std::vector<Sync::MissingDataInfo> &v, Sync::SyncAppSocket *)
+ChatDialog::processTreeUpdateWrapper(const std::vector<Sync::MissingDataInfo> v, Sync::SyncAppSocket *sock)
+{
+  emit treeUpdated(v);
+}
+
+void
+ChatDialog::processTreeUpdate(const std::vector<Sync::MissingDataInfo> v)
 {
   if (v.empty())
   {
@@ -127,7 +135,7 @@
     {
       for (Sync::SeqNo seq = v[i].low; seq <= v[i].high; ++seq)
       {
-        m_sock->fetchRaw(v[i].prefix, seq, bind(&ChatDialog::processData, this, _1, _2, _3), 2);
+        m_sock->fetchRaw(v[i].prefix, seq, bind(&ChatDialog::processDataWrapper, this, _1, _2, _3), 2);
       }
     }
   }
@@ -145,7 +153,13 @@
 }
 
 void
-ChatDialog::processData(std::string name, const char *buf, size_t len)
+ChatDialog::processDataWrapper(std::string name, const char *buf, size_t len)
+{
+  emit dataReceived(name.c_str(), buf, len);
+}
+
+void
+ChatDialog::processData(QString name, const char *buf, size_t len)
 {
   SyncDemo::ChatMessage msg;
   if (!msg.ParseFromArray(buf, len)) 
@@ -159,10 +173,10 @@
   // so if we call appendMsg directly
   // Qt crash as "QObject: Cannot create children for a parent that is in a different thread"
   // the "cannonical" way to is use signal-slot
-  emit msgReceived(msg);
+  appendMessage(msg);
   
   // update the tree view
-  std::string prefix = name.substr(0, name.find_last_of('/'));
+  std::string prefix = name.toStdString().substr(0, name.toStdString().find_last_of('/'));
   m_scene->msgReceived(prefix.c_str(), msg.from().c_str());
 }
 
@@ -184,6 +198,7 @@
 bool
 ChatDialog::readSettings()
 {
+#ifndef __DEBUG
   QSettings s(ORGANIZATION, APPLICATION);
   QString nick = s.value("nick", "").toString();
   QString chatroom = s.value("chatroom", "").toString();
@@ -198,15 +213,21 @@
     m_user.setPrefix(prefix);
     return true;
   }
+#else
+  QTimer::singleShot(500, this, SLOT(buttonPressed()));
+  return false;
+#endif
 }
 
 void 
 ChatDialog::writeSettings()
 {
+#ifndef __DEBUG
   QSettings s(ORGANIZATION, APPLICATION);
   s.setValue("nick", m_user.getNick());
   s.setValue("chatroom", m_user.getChatroom());
   s.setValue("prefix", m_user.getPrefix());
+#endif
 }
 
 void
@@ -281,7 +302,7 @@
     std::string syncPrefix = BROADCAST_PREFIX_FOR_SYNC_DEMO;
     syncPrefix += "/";
     syncPrefix += m_user.getChatroom().toStdString();
-    m_sock = new Sync::SyncAppSocket(syncPrefix, bind(&ChatDialog::processTreeUpdate, this, _1, _2), bind(&ChatDialog::processRemove, this, _1));
+    m_sock = new Sync::SyncAppSocket(syncPrefix, bind(&ChatDialog::processTreeUpdateWrapper, this, _1, _2), bind(&ChatDialog::processRemove, this, _1));
 
     fitView();
     
diff --git a/chatdialog.h b/chatdialog.h
index df3de48..452fc2e 100644
--- a/chatdialog.h
+++ b/chatdialog.h
@@ -19,12 +19,14 @@
 public:
 	ChatDialog(QWidget *parent = 0);
   ~ChatDialog();
-  void processTreeUpdate(const std::vector<Sync::MissingDataInfo> &, Sync::SyncAppSocket *);
-  void processData(std::string, const char *buf, size_t len);
   void processRemove(const std::string);
+  void appendMessage(const SyncDemo::ChatMessage msg);
+  void processTreeUpdateWrapper(const std::vector<Sync::MissingDataInfo>, Sync::SyncAppSocket *);
+  void processDataWrapper(std::string, const char *buf, size_t len);
 
 public slots:
-  void appendMessage(const SyncDemo::ChatMessage msg);
+  void processTreeUpdate(const std::vector<Sync::MissingDataInfo>);
+  void processData(QString name, const char *buf, size_t len);
 
 private:
   void formChatMessage(const QString &text, SyncDemo::ChatMessage &msg);
@@ -42,7 +44,8 @@
   void settingUpdated(QString, QString, QString);
 
 signals:
-  void msgReceived(const SyncDemo::ChatMessage msg);
+  void dataReceived(QString name, const char *buf, size_t len);
+  void treeUpdated(const std::vector<Sync::MissingDataInfo>);
 
 private:
   User m_user; 
diff --git a/sync-demo.pro b/sync-demo.pro
index 2eae1a3..24fcdd1 100644
--- a/sync-demo.pro
+++ b/sync-demo.pro
@@ -1,5 +1,6 @@
 TEMPLATE = app
 TARGET = sync-demo
+DEFINES += __DEBUG
 HEADERS = chatdialog.h \
           digesttreescene.h \
           settingdialog.h \