]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/InGuiThread.cpp
Fix the tab ordering of GuiDocument components.
[lyx.git] / src / frontends / qt4 / InGuiThread.cpp
index b9332997f196951047039d0cd2d97ac1fd7e1921..20be94cffe22caf766cc29915fc4f92fdc42b9fe 100644 (file)
 
 #include "InGuiThread.h"
 
+#include "frontends/Application.h"
+
 #include <QThread>
 #include <QEventLoop>
 #include <QApplication>
+#include <QMutexLocker>
+
 
 namespace lyx {
 namespace frontend {
@@ -27,18 +31,16 @@ IntoGuiThreadMover::IntoGuiThreadMover()
 
 void IntoGuiThreadMover::callInGuiThread()
 {
-       QThread* gui_thread = QApplication::instance()->thread();
-       if (QThread::currentThread() == gui_thread) {
+       if (!theApp() || !QApplication::instance() ||
+               QThread::currentThread() == QApplication::instance()->thread()) {
                synchronousFunctionCall();
        } else {
-               moveToThread(gui_thread);
-               connect(this, SIGNAL(triggerCall()), this, SLOT(doFunctionCall()),
-                       Qt::QueuedConnection);
-               // TODO try with condition, it's maybe cheaper
-               QEventLoop loop;
-               connect(this, SIGNAL(called()), &loop, SLOT(quit()));
-               Q_EMIT triggerCall();
-               loop.exec();
+               moveToThread(QApplication::instance()->thread());
+               connect(this, SIGNAL(triggerFunctionCall()), 
+                       this, SLOT(doFunctionCall()), Qt::QueuedConnection);
+               QMutexLocker lock(&sync_mutex_);
+               Q_EMIT triggerFunctionCall();
+               condition_.wait(&sync_mutex_);
        }
 }
 
@@ -46,7 +48,7 @@ void IntoGuiThreadMover::callInGuiThread()
 void IntoGuiThreadMover::doFunctionCall()
 {
        synchronousFunctionCall();
-       Q_EMIT called();
+       condition_.wakeOne();
 }