]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/InGuiThread.cpp
enable EXPORT_in_THREAD to prevent gui calls in non gui-threads
[lyx.git] / src / frontends / qt4 / InGuiThread.cpp
1 /**
2  * \file InGuiThread.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Peter Kümmel
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "InGuiThread.h"
14
15 #include <QThread>
16 #include <QEventLoop>
17 #include <QApplication>
18
19 namespace lyx {
20 namespace frontend {
21
22
23 IntoGuiThreadMover::IntoGuiThreadMover()
24 {
25         moveToThread(QApplication::instance()->thread());
26         connect(this, SIGNAL(triggerCall()), this, SLOT(doFunctionCall()),
27                 Qt::QueuedConnection);
28 }
29
30
31 void IntoGuiThreadMover::callInGuiThread()
32 {
33         if (QThread::currentThread() == QApplication::instance()->thread()) {
34                 synchronousFunctionCall();
35         } else {
36                 QEventLoop loop;
37                 connect(this, SIGNAL(called()), &loop, SLOT(quit()));
38                 Q_EMIT triggerCall();
39                 loop.exec();
40         }
41 }
42
43
44 void IntoGuiThreadMover::doFunctionCall()
45 {
46         synchronousFunctionCall();
47         Q_EMIT called();
48 }
49
50
51 } // namespace frontend
52 } // namespace lyx
53
54 #include "moc_InGuiThread.cpp"