Hi again,
of the application when the main window object is not yet present (if I
comment this statement out, it will crash on e.g. loadGPX()). Is this a
"special" effect on Tiger (didn't try Leopard yet)? Maybe it is necessary to
delay the handling of the event until the main window has been fully
initialised.
Don't know yet... In some cases, after attaching with gdb, theMainWindow
is indeed a NULL-pointer in the event handler, which results in a crash
in the above statement :-( Smells like an obscure race condition.
ok, I could reproduce this after adding sleep(4) right before
splash->show() in main.cpp. So the file open event is posted while
there is no main window yet but only the splash screen.
A simple workaround is attached. Maybe someone with better Qt knowledge
has a better solution.
--
Michael
Thank you for not using Microsoft products
Index: src/CApplication.cpp
===================================================================
--- src/CApplication.cpp (revision 2967)
+++ src/CApplication.cpp (working copy)
@@ -20,6 +20,7 @@
#include "CApplication.h"
#include "CMainWindow.h"
+#include <QDebug>
#include <QFileOpenEvent>
// http://doc.qt.nokia.com/qq/qq18-macfeatures.html
@@ -27,9 +28,25 @@
{
switch (event->type()) {
case QEvent::FileOpen:
- theMainWindow->loadData(static_cast<QFileOpenEvent
*>(event)->file(), "");
+ if (theMainWindow) {
+ theMainWindow->loadData(static_cast<QFileOpenEvent
*>(event)->file(), "");
+ } else {
+ qWarning() << "main window is NULL, enqueueing event";
+ _filesToOpen.enqueue(static_cast<QFileOpenEvent
*>(event)->file());
+ startTimer(1000);
+ }
return true;
default:
return QApplication::event(event);
}
}
+
+void CApplication::timerEvent(QTimerEvent *event)
+{
+ if (theMainWindow) {
+ while (!_filesToOpen.empty()) {
+ theMainWindow->loadData(_filesToOpen.dequeue(), "");
+ }
+ killTimer(event->timerId());
+ }
+}
Index: src/CApplication.h
===================================================================
--- src/CApplication.h (revision 2967)
+++ src/CApplication.h (working copy)
@@ -22,6 +22,9 @@
#include <QApplication>
#include <QEvent>
+#include <QQueue>
+#include <QString>
+#include <QTimerEvent>
class CApplication : public QApplication
{
@@ -33,6 +36,10 @@
protected:
bool event(QEvent *);
+ void timerEvent(QTimerEvent *);
+
+private:
+ QQueue<QString> _filesToOpen;
};
#endif
------------------------------------------------------------------------------
Doing More with Less: The Next Generation Virtual Desktop
What are the key obstacles that have prevented many mid-market businesses
from deploying virtual desktops? How do next-generation virtual desktops
provide companies an easier-to-deploy, easier-to-manage and more affordable
virtual desktop model.http://www.accelacomm.com/jaw/sfnl/114/51426474/
_______________________________________________
Qlandkartegt-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qlandkartegt-users