macOS: fix QFileOpenEvent routing for .qet/.elmt/.titleblock double-click

Root cause (see issue #218 discussion):
- QETApp::eventFiltrer (Q_OS_DARWIN) was correct in intent but never
  actually installed as an event filter anywhere, and its name didn't
  match the QObject::eventFilter virtual signature, so even if it had
  been installed it would never have been invoked as an override.
  Confirmed dead code.
- main.cpp instead routed Finder's QFileOpenEvent through
  MacOSXOpenEvent -> SingleApplication::sendMessage(), which is the
  secondary-to-primary IPC channel. Called from within the primary
  instance itself, sendMessage() fails silently and the file path is
  dropped, which is exactly what double-click does (Finder doesn't spawn
  a secondary process, the running instance receives the FileOpen event
  directly).
- openFiles() takes a QETArguments, not a QStringList. The dead code's
  openFiles(QStringList() << filename) only worked via an untested
  implicit QStringList -> QList<QString> -> QETArguments conversion
  chain.

Fix:
- Rename eventFiltrer -> eventFilter (qetapp.h/.cpp) so it's a proper
  override of QObject::eventFilter, and make it public so main.cpp can
  install it on QApplication.
- Build the QETArguments explicitly instead of relying on implicit
  conversion.
- main.cpp: drop MacOSXOpenEvent entirely (include + instantiation),
  install qetapp as the Q_OS_MACOS event filter on app right after
  QETApp qetapp; is constructed and before app.exec(). No race window:
  the event loop hasn't started, so no QFileOpenEvent can be delivered
  before the filter is installed.

QETArguments::handleFileArgument() already sorts files by extension
(.elmt, titleblock, else project) and openFiles() already fans out to
openProjectFiles()/openElementFiles()/openTitleBlockTemplateFiles()
accordingly, so this single fix covers .qet, .elmt and .titleblock
double-click/drag-to-dock on macOS, not just .qet.

SingleApplication's sendMessage/receivedMessage flow (used for CLI args
on all platforms) is untouched; this only touches the Q_OS_MACOS block,
so there is no behavior change on Windows/Linux.

Follow-up (not included here): the macOS Info.plist (misc/Info.plist)
has an empty CFBundleShortVersionString, which may affect macOS's
willingness to retain file associations across app updates.
This commit is contained in:
scorpio810
2026-06-21 09:58:16 +00:00
committed by Laurent Trinques
parent 1410e70d13
commit 8d76354647
3 changed files with 14 additions and 10 deletions
+7 -5
View File
@@ -21,7 +21,6 @@
#include "qetapp.h" #include "qetapp.h"
#include "qetproject.h" #include "qetproject.h"
#include "singleapplication.h" #include "singleapplication.h"
#include "utils/macosxopenevent.h"
#include "utils/qetsettings.h" #include "utils/qetsettings.h"
#include <QApplication> #include <QApplication>
@@ -217,10 +216,6 @@ QGuiApplication::setHighDpiScaleFactorRoundingPolicy(QetSettings::hdpiScaleFacto
SingleApplication app(argc, argv, true); SingleApplication app(argc, argv, true);
#ifdef Q_OS_MACOS #ifdef Q_OS_MACOS
//Handle the opening of QET when user double click on a .qet .elmt .tbt file
//or drop these same files to the QET icon of the dock
MacOSXOpenEvent open_event;
app.installEventFilter(&open_event);
app.setStyle(QStyleFactory::create("Fusion")); app.setStyle(QStyleFactory::create("Fusion"));
#endif #endif
@@ -238,6 +233,13 @@ QGuiApplication::setHighDpiScaleFactorRoundingPolicy(QetSettings::hdpiScaleFacto
QETApp qetapp; QETApp qetapp;
QETApp::instance()->installEventFilter(&qetapp); QETApp::instance()->installEventFilter(&qetapp);
#ifdef Q_OS_MACOS
//Handle the opening of QET when user double click on a .qet .elmt .tbt file
//or drop these same files to the QET icon of the dock.
//Installed here (after QETApp is fully constructed, before app.exec())
//so there is no race: no QFileOpenEvent can be delivered before this point.
app.installEventFilter(&qetapp);
#endif
QObject::connect(&app, &SingleApplication::receivedMessage, QObject::connect(&app, &SingleApplication::receivedMessage,
&qetapp, &QETApp::receiveMessage); &qetapp, &QETApp::receiveMessage);
+5 -2
View File
@@ -2625,14 +2625,17 @@ void QETApp::fetchWindowStats(
#ifdef Q_OS_DARWIN #ifdef Q_OS_DARWIN
/** /**
Gere les evenements, en particulier l'evenement FileOpen sous MacOs. Gere les evenements, en particulier l'evenement FileOpen sous MacOs.
Installe comme event filter sur QApplication dans main(), une fois
QETApp construite (voir main.cpp).
@param object Objet cible de l'evenement
@param e Evenement a gerer @param e Evenement a gerer
*/ */
bool QETApp::eventFiltrer(QObject *object, QEvent *e) { bool QETApp::eventFilter(QObject *object, QEvent *e) {
// gere l'ouverture de fichiers (sous MacOs) // gere l'ouverture de fichiers (sous MacOs)
if (e -> type() == QEvent::FileOpen) { if (e -> type() == QEvent::FileOpen) {
// nom du fichier a ouvrir // nom du fichier a ouvrir
QString filename = static_cast<QFileOpenEvent *>(e) -> file(); QString filename = static_cast<QFileOpenEvent *>(e) -> file();
openFiles(QStringList() << filename); openFiles(QETArguments(QStringList() << filename));
return(true); return(true);
} else { } else {
return QObject::eventFilter(object, e); return QObject::eventFilter(object, e);
+2 -3
View File
@@ -178,10 +178,9 @@ class QETApp : public QObject
static QTextOrientationSpinBoxWidget *createTextOrientationSpinBoxWidget(); static QTextOrientationSpinBoxWidget *createTextOrientationSpinBoxWidget();
static TitleBlockTemplate *defaultTitleBlockTemplate(); static TitleBlockTemplate *defaultTitleBlockTemplate();
protected:
#ifdef Q_OS_DARWIN #ifdef Q_OS_DARWIN
bool eventFiltrer(QObject *object, QEvent *); public:
bool eventFilter(QObject *object, QEvent *) override;
#endif #endif
// attributes // attributes