]> git.lyx.org Git - features.git/commitdiff
use QWaitCondition instead of QEventLoop for waiting on GUI thread-call finished...
authorPeter Kümmel <syntheticpp@gmx.net>
Thu, 21 Oct 2010 21:29:08 +0000 (21:29 +0000)
committerPeter Kümmel <syntheticpp@gmx.net>
Thu, 21 Oct 2010 21:29:08 +0000 (21:29 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35763 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/InGuiThread.cpp
src/frontends/qt4/InGuiThread.h

index b9332997f196951047039d0cd2d97ac1fd7e1921..ff53f9d0e9619be2564ea3b2f890b314e44df351 100644 (file)
@@ -15,6 +15,8 @@
 #include <QThread>
 #include <QEventLoop>
 #include <QApplication>
+#include <QMutexLocker>
+
 
 namespace lyx {
 namespace frontend {
@@ -32,13 +34,11 @@ void IntoGuiThreadMover::callInGuiThread()
                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();
+               connect(this, SIGNAL(triggerFunctionCall()), 
+                       this, SLOT(doFunctionCall()), Qt::QueuedConnection);
+               QMutexLocker lock(&sync_mutex_);
+               Q_EMIT triggerFunctionCall();
+               condition_.wait(&sync_mutex_);
        }
 }
 
@@ -46,7 +46,7 @@ void IntoGuiThreadMover::callInGuiThread()
 void IntoGuiThreadMover::doFunctionCall()
 {
        synchronousFunctionCall();
-       Q_EMIT called();
+       condition_.wakeOne();
 }
 
 
index 6d3b778a04eafb924bad289925c3d9620f225d94..73a9d4ccd67bd235d3943eaa1df1d571122a61b5 100644 (file)
@@ -12,7 +12,9 @@
 #ifndef INGUITHREAD_H
 #define INGUITHREAD_H
 
+#include <QMutex>
 #include <QObject>
+#include <QWaitCondition>
 
 #include "support/bind.h"
 #include "support/functional.h"
@@ -32,14 +34,16 @@ protected:
        void callInGuiThread();
 
 Q_SIGNALS:
-       void triggerCall();
-       void called();
+       void triggerFunctionCall();
 
 private Q_SLOTS:
        void doFunctionCall();
 
 private:
        virtual void synchronousFunctionCall() = 0;
+
+       QWaitCondition condition_;
+       QMutex sync_mutex_;
 };