wiRedPanda
Logic Circuit Simulator
Loading...
Searching...
No Matches
Application Class Reference

Custom QApplication that wraps event dispatch with exception handling. More...

#include <Application.h>

Inheritance diagram for Application:
[legend]

Public Member Functions

 Application (int &argc, char **argv)
 Constructs the application with command-line arguments.
bool notify (QObject *receiver, QEvent *event) override
 ~Application () override=default
 Destructor.

Static Public Member Functions

template<typename Body>
static void guardedSlot (const QObject *context, Body &&body) noexcept
 Wraps a slot body in try/catch and reports any exception synchronously, inside the slot's own stack frame.
static void handleException (const ExceptionInfo &info, const QObject *context)
 Centralised exception-reporting handler used by both Application::notify (defence-in-depth on Linux/Windows) and Application::guardedSlot (the macOS-correct catch-in-slot path).
static Applicationinstance ()
 Returns the application instance cast to Application*.
static bool isSentryDenyMessage (const QString &message)

Static Public Attributes

static bool interactiveMode = true
static bool migrationEnabled = true
static bool renderingEnabled = true

Detailed Description

Custom QApplication that wraps event dispatch with exception handling.

Overrides notify() to catch Pandaception and std::exception objects thrown during event processing and display appropriate error dialogs.

Definition at line 44 of file Application.h.

Constructor & Destructor Documentation

◆ Application()

Application::Application ( int & argc,
char ** argv )

Constructs the application with command-line arguments.

Parameters
argcArgument count (passed by reference as required by QApplication).
argvArgument vector.

Definition at line 79 of file Application.cpp.

Referenced by instance().

◆ ~Application()

Application::~Application ( )
overridedefault

Destructor.

Member Function Documentation

◆ guardedSlot()

template<typename Body>
void Application::guardedSlot ( const QObject * context,
Body && body )
inlinestaticnoexcept

Wraps a slot body in try/catch and reports any exception synchronously, inside the slot's own stack frame.

Per Qt 6.11 Exception Safety and QTBUG-15197, throwing across Qt's signal-slot dispatch is undefined behaviour; on macOS the unwinder reliably triggers std::terminate mid-stack and no upstream catch runs. guardedSlot keeps the catch frame inside the slot itself (below any Qt-internal frame) so the unwinder never crosses a structure that aborts. Reporting was originally deferred to the next event-loop iteration via a queued invokeMethod, but that hangs on macOS — the modal QMessageBox::exec() deep inside the queued dispatch never returns (see the catch block below and .claude/SENTRY_TRIAGE.md §A25). handleException is called directly instead, using a non-modal show() so it returns immediately even when interactive.

Template Parameters
BodyInvocable callable with no arguments returning anything.
Parameters
contextNon-owning pointer used as the receiver hint passed to handleException.
bodyThe slot body to invoke; any thrown std::exception is caught and reported before this function returns.

Definition at line 129 of file Application.h.

References handleException().

Referenced by ICController::addICFromFile(), ExportController::exportArduinoDialog(), ExportController::exportImageDialog(), ExportController::exportPdfDialog(), ExportController::exportSystemVerilogDialog(), WorkspaceManager::newTab(), WorkspaceManager::openFile(), WorkspaceManager::reloadFile(), WorkspaceManager::saveFile(), WorkspaceManager::saveFileAs(), and ICController::showRemoveICHint().

◆ handleException()

void Application::handleException ( const ExceptionInfo & info,
const QObject * context )
static

Centralised exception-reporting handler used by both Application::notify (defence-in-depth on Linux/Windows) and Application::guardedSlot (the macOS-correct catch-in-slot path).

Shows a QMessageBox::critical when interactiveMode is true, and forwards the event to Sentry as a handled:1 warning when sentry is compiled in. Safe to call from a deferred QMetaObject::invokeMethod callback (the exception has finished unwinding by then).

Definition at line 127 of file Application.cpp.

References ExceptionInfo::englishMessage, ExceptionInfo::file, interactiveMode, ExceptionInfo::line, and ExceptionInfo::what.

Referenced by guardedSlot(), and notify().

◆ instance()

Application * Application::instance ( )
static

Returns the application instance cast to Application*.

Returns
Pointer to the Application instance, or nullptr if not available.

Definition at line 91 of file Application.cpp.

References Application().

Referenced by LanguageManager::loadTranslation(), ThemeAttributes::setTheme(), ThemeManager::setTheme(), and LanguageManager::~LanguageManager().

◆ isSentryDenyMessage()

bool Application::isSentryDenyMessage ( const QString & message)
static

Returns true if message matches any deny pattern that should be dropped before being sent to Sentry. Always compiled (independent of HAVE_SENTRY) so the deny-list policy is unit-testable.

Definition at line 69 of file Application.cpp.

◆ notify()

bool Application::notify ( QObject * receiver,
QEvent * event )
override
Reimplemented from base class. Dispatches event to receiver, catching and reporting exceptions.

Definition at line 96 of file Application.cpp.

References handleException().

Member Data Documentation

◆ interactiveMode

bool Application::interactiveMode = true
inlinestatic

When false, suppresses informational dialogs (e.g. version-mismatch warnings). Stays false in BOTH MCP modes: an automated session can't dismiss a QMessageBox. Visual concerns are governed by renderingEnabled instead.

Definition at line 73 of file Application.h.

Referenced by UpdateController::checkForUpdates(), handleException(), WorkSpace::load(), WorkspaceManager::loadAutosaveFiles(), main(), WorkSpace::save(), MainWindow::show(), and Simulation::update().

◆ migrationEnabled

bool Application::migrationEnabled = true
inlinestatic

When true, old-format files are automatically backed up and re-saved in the current format on load. Independent of interactiveMode so tests can enable migration without triggering any QMessageBox dialogs.

Definition at line 85 of file Application.h.

Referenced by WorkSpace::load().

◆ renderingEnabled

bool Application::renderingEnabled = true
inlinestatic

When false, skips wire-geometry construction (Connection::updatePath) as a throughput optimization for contexts that never paint or export: unit tests and fuzz harnesses. Must stay true whenever anything can be rendered — including headless –mcp, whose export_image paints the scene off-screen.

Definition at line 80 of file Application.h.

Referenced by Connection::updatePath().


The documentation for this class was generated from the following files: