Fixed an issue with deferred method execution in unit test context.

This commit is contained in:
Matthias Koefferlein 2020-08-30 13:06:50 +02:00
parent eccbb9884c
commit a5d675304c
4 changed files with 13 additions and 4 deletions

View File

@ -776,7 +776,10 @@ ApplicationBase::init_app ()
// establish the configuration // establish the configuration
dispatcher ()->config_setup (); dispatcher ()->config_setup ();
// Some info output // deferred method processing for those plugins which need this
process_events ();
// some info output
if (tl::verbosity () >= 20) { if (tl::verbosity () >= 20) {
tl::info << "KLayout path:"; tl::info << "KLayout path:";
@ -1504,6 +1507,9 @@ GuiApplication::process_events_impl (QEventLoop::ProcessEventsFlags flags, bool
mp_mw->enter_busy_mode (true); mp_mw->enter_busy_mode (true);
try { try {
QApplication::processEvents (flags); QApplication::processEvents (flags);
// Qt seems not to send posted UserEvents in some cases (e.g. in the unit test application with GLib?
// Glib not doing this without a main window visible?). Hence we do this explicitly here.
QApplication::sendPostedEvents ();
} catch (...) { } catch (...) {
// ignore exceptions // ignore exceptions
} }

View File

@ -32,6 +32,8 @@ namespace tl
DeferredMethodSchedulerQt::DeferredMethodSchedulerQt () DeferredMethodSchedulerQt::DeferredMethodSchedulerQt ()
: QObject (qApp), DeferredMethodScheduler () : QObject (qApp), DeferredMethodScheduler ()
{ {
m_event_type = QEvent::registerEventType ();
connect (&m_timer, SIGNAL (timeout ()), this, SLOT (timer ())); connect (&m_timer, SIGNAL (timeout ()), this, SLOT (timer ()));
m_timer.setInterval (0); // immediately m_timer.setInterval (0); // immediately
@ -51,13 +53,13 @@ DeferredMethodSchedulerQt::~DeferredMethodSchedulerQt ()
void void
DeferredMethodSchedulerQt::queue_event () DeferredMethodSchedulerQt::queue_event ()
{ {
qApp->postEvent (this, new QEvent (QEvent::User)); qApp->postEvent (this, new QEvent (QEvent::Type (m_event_type)));
} }
bool bool
DeferredMethodSchedulerQt::event (QEvent *event) DeferredMethodSchedulerQt::event (QEvent *event)
{ {
if (event->type () == QEvent::User) { if (event->type () == m_event_type) {
timer (); timer ();
return true; return true;
} else { } else {

View File

@ -65,6 +65,7 @@ private slots:
private: private:
QTimer m_timer, m_fallback_timer; QTimer m_timer, m_fallback_timer;
int m_event_type;
virtual bool event (QEvent *event); virtual bool event (QEvent *event);
}; };

View File

@ -396,7 +396,7 @@ class IMG_TestClass < TestBase
end end
def test_4 def test_5
tmp = File::join($ut_testtmp, "tmp.lyimg") tmp = File::join($ut_testtmp, "tmp.lyimg")