]> 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 f26893f7ac749574d2c8cd4539dfa3344aedcdd1..20be94cffe22caf766cc29915fc4f92fdc42b9fe 100644 (file)
 
 #include "InGuiThread.h"
 
+#include "frontends/Application.h"
+
 #include <QThread>
 #include <QEventLoop>
 #include <QApplication>
+#include <QMutexLocker>
+
 
 namespace lyx {
 namespace frontend {
@@ -22,21 +26,21 @@ namespace frontend {
 
 IntoGuiThreadMover::IntoGuiThreadMover()
 {
-       moveToThread(QApplication::instance()->thread());
-       connect(this, SIGNAL(triggerCall()), this, SLOT(doFunctionCall()),
-               Qt::QueuedConnection);
 }
 
 
 void IntoGuiThreadMover::callInGuiThread()
 {
-       if (QThread::currentThread() == QApplication::instance()->thread()) {
+       if (!theApp() || !QApplication::instance() ||
+               QThread::currentThread() == QApplication::instance()->thread()) {
                synchronousFunctionCall();
        } else {
-               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_);
        }
 }
 
@@ -44,11 +48,11 @@ void IntoGuiThreadMover::callInGuiThread()
 void IntoGuiThreadMover::doFunctionCall()
 {
        synchronousFunctionCall();
-       Q_EMIT called();
+       condition_.wakeOne();
 }
 
 
 } // namespace frontend
 } // namespace lyx
 
-
+#include "moc_InGuiThread.cpp"