Index: pjproject/trunk/pjsip-apps/src/vidgui/vidgui.cpp
===================================================================
--- pjproject/trunk/pjsip-apps/src/vidgui/vidgui.cpp	(revision 3725)
+++ pjproject/trunk/pjsip-apps/src/vidgui/vidgui.cpp	(revision 3726)
@@ -51,5 +51,5 @@
 
     initLayout();
-    onCallReleased();
+    emit signalCallReleased();
 }
 
@@ -102,11 +102,18 @@
     connect(quitButton_, SIGNAL(clicked()), this, SLOT(quit()));
     //connect(this, SIGNAL(close()), this, SLOT(quit()));
+
+    // UI updates must be done in the UI thread!
+    connect(this, SIGNAL(signalNewCall(int, bool)),
+	    this, SLOT(onNewCall(int, bool)));
+    connect(this, SIGNAL(signalCallReleased()),
+	    this, SLOT(onCallReleased()));
+    connect(this, SIGNAL(signalInitVideoWindow()),
+	    this, SLOT(initVideoWindow()));
+    connect(this, SIGNAL(signalShowStatus(const QString&)),
+	    this, SLOT(doShowStatus(const QString&)));
 }
 
 void MainWin::quit()
 {
-    //if (preview_on)
-        //preview();
-
     delete video_prev_;
     video_prev_ = NULL;
@@ -120,7 +127,14 @@
 void MainWin::showStatus(const char *msg)
 {
+    PJ_LOG(3,(THIS_FILE, "%s", msg));
+
+    QString msg_ = QString::fromUtf8(msg);
+    emit signalShowStatus(msg_);
+}
+
+void MainWin::doShowStatus(const QString& msg)
+{
     //statusBar_->showMessage(msg);
     statusBar_->setText(msg);
-    PJ_LOG(3,(THIS_FILE, "%s", msg));
 }
 
@@ -135,5 +149,5 @@
 }
 
-void MainWin::onNewCall(pjsua_call_id cid, bool incoming)
+void MainWin::onNewCall(int cid, bool incoming)
 {
     pjsua_call_info ci;
@@ -206,5 +220,6 @@
 	//X11 Display
 	//status = pjsua_vid_win_set_show(wid, PJ_TRUE);
-	video_prev_->show();
+	//This is handled by VidWin now
+	//video_prev_->show();
 	showStatus("Preview started");
 
@@ -224,5 +239,7 @@
 	pj_status_t status;
 	QString dst = url_->text();
-	const char *uri = dst.toAscii().data();
+	char uri[256];
+
+	pj_ansi_strncpy(uri, dst.toAscii().data(), sizeof(uri));
 	pj_str_t uri2 = pj_str((char*)uri);
 
@@ -243,9 +260,9 @@
     //pjsua_call_hangup(currentCall_, PJSIP_SC_BUSY_HERE, NULL, NULL);
     pjsua_call_hangup_all();
-    onCallReleased();
-}
-
-
-void MainWin::init_video_window()
+    emit signalCallReleased();
+}
+
+
+void MainWin::initVideoWindow()
 {
     pjsua_call_info ci;
@@ -311,5 +328,5 @@
 
     if (currentCall_ == -1 && ci.state < PJSIP_INV_STATE_DISCONNECTED) {
-	onNewCall(call_id, false);
+	emit signalNewCall(call_id, false);
     }
 
@@ -320,5 +337,5 @@
 	         ci.last_status_text.ptr);
 	showStatus(status);
-	onCallReleased();
+	emit signalCallReleased();
     } else {
 	snprintf(status, sizeof(status), "Call is %s", pjsip_inv_state_name(ci.state));
@@ -338,5 +355,5 @@
     }
 
-    onNewCall(call_id, true);
+    emit signalNewCall(call_id, true);
 
     pjsua_call_info ci;
@@ -366,5 +383,5 @@
 	    }
 	} else if (ci.media[i].type == PJMEDIA_TYPE_VIDEO) {
-	    init_video_window();
+	    emit signalInitVideoWindow();
 	}
     }
Index: pjproject/trunk/pjsip-apps/src/vidgui/vidgui.h
===================================================================
--- pjproject/trunk/pjsip-apps/src/vidgui/vidgui.h	(revision 3725)
+++ pjproject/trunk/pjsip-apps/src/vidgui/vidgui.h	(revision 3726)
@@ -48,7 +48,6 @@
     bool initStack();
     void showError(const char *title, pj_status_t status);
-    void showStatus(const char *);
+    void showStatus(const char *msg);
 
-public:
     void on_reg_state(pjsua_acc_id acc_id);
     void on_call_state(pjsua_call_id call_id, pjsip_event *e);
@@ -56,4 +55,10 @@
     void on_call_media_state(pjsua_call_id call_id);
 
+signals:
+    void signalNewCall(int, bool);
+    void signalCallReleased();
+    void signalInitVideoWindow();
+    void signalShowStatus(const QString&);
+    
 public slots:
     void preview();
@@ -62,4 +67,9 @@
     void quit();
 
+    void onNewCall(int cid, bool incoming);
+    void onCallReleased();
+    void initVideoWindow();
+    void doShowStatus(const QString& msg);
+
 private:
     static MainWin *theInstance_;
@@ -67,7 +77,4 @@
     pjsua_call_id currentCall_;
     bool preview_on;
-
-    void onNewCall(pjsua_call_id cid, bool incoming);
-    void onCallReleased();
 
 private:
@@ -86,5 +93,4 @@
 
     void initLayout();
-    void init_video_window();
 };
 
Index: pjproject/trunk/pjsip-apps/src/vidgui/vidwin.cpp
===================================================================
--- pjproject/trunk/pjsip-apps/src/vidgui/vidwin.cpp	(revision 3725)
+++ pjproject/trunk/pjsip-apps/src/vidgui/vidwin.cpp	(revision 3726)
@@ -47,8 +47,6 @@
 VidWin::~VidWin()
 {
+    show(false);
     detach();
-    pj_bzero(&hwnd, sizeof(hwnd));
-    size_hint = QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
-    destroy(true, false);
 }
 
@@ -56,20 +54,12 @@
 {
     switch(e->type()) {
+
     case QEvent::Resize:
-	{
-	    // revert to default size hint, make it resizable
-	    setFixedSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
-	    // resize now
-	    set_size();
-	}
-	break;
-    case QEvent::ParentAboutToChange:
+	set_size();
+	break;
+
+    case QEvent::ParentChange:
 	get_size();
-	setFixedSize(size_hint);
-	break;
-    case QEvent::ParentChange:
-	{
-	    get_size();
-	    /*
+	if (0) {
 	    QRect qr = rect();
 	    if (qr.width() > size_hint.width())
@@ -77,9 +67,19 @@
 	    if (qr.height() > size_hint.height())
 		size_hint.setWidth(qr.height());
-	    */
-	    setFixedSize(size_hint);
-	    attach();
 	}
-	break;
+	setFixedSize(size_hint);
+	attach();
+	break;
+
+    case QEvent::Show:
+	show(true);
+	// revert to default size hint, make it resizable
+	setFixedSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
+	break;
+
+    case QEvent::Hide:
+	show(false);
+	break;
+
     default:
 	break;
@@ -103,7 +103,6 @@
     orig_parent = GetParent(w);
 
+    SetWindowLong(w, GWL_STYLE, WS_CHILD);
     SetParent(w, new_parent);
-    SetWindowLong(w, GWL_STYLE, WS_CHILD);
-    ShowWindow(w, SW_SHOWNOACTIVATE);
     TRACE_("%p new parent handle = %p", w, new_parent);
 }
@@ -114,5 +113,4 @@
 
     HWND w = (HWND)hwnd.info.win.hwnd;
-    ShowWindow(w, SW_HIDE);
     SetParent(w, (HWND)orig_parent);
     TRACE_("%p revert parent handle to %p", w, orig_parent);
@@ -145,5 +143,6 @@
     if (!hwnd.info.win.hwnd) return;
 
-    ShowWindow(hwnd.info.win.hwnd, visible ? SW_SHOW : SW_HIDE);
+    HWND w = (HWND)hwnd.info.win.hwnd;
+    ShowWindow(w, visible ? SW_SHOW : SW_HIDE);
 }
 
Index: pjproject/trunk/pjsip-apps/src/vidgui/vidwin.h
===================================================================
--- pjproject/trunk/pjsip-apps/src/vidgui/vidwin.h	(revision 3725)
+++ pjproject/trunk/pjsip-apps/src/vidgui/vidwin.h	(revision 3726)
@@ -33,5 +33,4 @@
     virtual ~VidWin();
     QSize sizeHint() const { return size_hint; }
-    void show(bool visible=true);
 
 protected:
@@ -47,4 +46,5 @@
     void set_size();
     void get_size();
+    void show(bool visible=true);
 };
 
