diff --git a/lcl/interfaces/qt/qtint.pp b/lcl/interfaces/qt/qtint.pp index 2c55b6e448..0bf852e13e 100644 --- a/lcl/interfaces/qt/qtint.pp +++ b/lcl/interfaces/qt/qtint.pp @@ -68,6 +68,8 @@ type // global hooks FAppEvenFilterHook: QObject_hookH; FAppFocusChangedHook: QApplication_hookH; + FAppSessionQuit: QApplication_hookH; + FAppSaveSessionRequest: QApplication_hookH; // default application font name (FamilyName for "default" font) FDefaultAppFontName: WideString; @@ -114,6 +116,8 @@ type function EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl; procedure FocusChanged(aold: QWidgetH; anew: QWidgetH); cdecl; procedure OnWakeMainThread(Sender: TObject); + procedure SlotCommitDataRequest(sessionManager: QSessionManagerH); cdecl; + procedure SlotSaveDataRequest(sessionManager: QSessionManagerH); cdecl; public function LCLPlatform: TLCLPlatform; override; function GetLCLCapability(ACapability: TLCLCapability): PtrUInt; override; diff --git a/lcl/interfaces/qt/qtobject.inc b/lcl/interfaces/qt/qtobject.inc index d0c75ea145..763c7f4f30 100644 --- a/lcl/interfaces/qt/qtobject.inc +++ b/lcl/interfaces/qt/qtobject.inc @@ -224,6 +224,18 @@ begin FAppFocusChangedHook := QApplication_hook_create(App); QApplication_hook_hook_focusChanged(FAppFocusChangedHook, @FocusChanged); + if not FIsLibraryInstance then + begin + FAppSessionQuit := QApplication_hook_create(App); + QApplication_hook_hook_commitDataRequest(FAppSessionQuit, @SlotCommitDataRequest); + FAppSaveSessionRequest := QApplication_hook_create(App); + QApplication_hook_hook_saveStateRequest(FAppSaveSessionRequest, @SlotSaveDataRequest); + end else + begin + FAppSessionQuit := nil; + FAppSaveSessionRequest := nil; + end; + ScreenDC := GetDC(0); try @@ -300,7 +312,19 @@ begin QApplication_hook_destroy(FAppFocusChangedHook); // do not quit application if we are library if not FIsLibraryInstance then + begin + if Assigned(FAppSessionQuit) then + begin + QApplication_hook_destroy(FAppSessionQuit); + FAppSessionQuit := nil; + end; + if Assigned(FAppSaveSessionRequest) then + begin + QApplication_hook_destroy(FAppSaveSessionRequest); + FAppSaveSessionRequest := nil; + end; QCoreApplication_quit; + end; end; procedure TQtWidgetSet.AppMinimize; @@ -915,6 +939,48 @@ begin QCoreApplication_postEvent(QCoreApplication_instance(), Event, 1 {high priority}); end; +procedure TQtWidgetSet.SlotCommitDataRequest(sessionManager: QSessionManagerH); + cdecl; +var + ACancel: Boolean; +begin + ACancel := False; + {$IFDEF QTDEBUGSESSIONMANAGER} + DebugLn('TQtWidgetSet.SlotCommitDataRequest allowInteraction ? ',dbgs(QSessionManager_allowsInteraction(sessionManager)), + ' errorInteraction ',dbgs(QSessionManager_allowsErrorInteraction(sessionManager)), + ' phase2 ',dbgs(QSessionManager_isPhase2(sessionManager))); + {$ENDIF} + // if session manager does not allow interaction, then we close app without any intf calls + if QSessionManager_allowsInteraction(sessionManager) then + begin + Application.IntfQueryEndSession(ACancel); + if ACancel then + begin + {$IFDEF QTDEBUGSESSIONMANAGER} + DebugLn('*** App shutdown cancelled ...***'); + {$ENDIF} + QSessionManager_cancel(sessionManager); + end else + begin + Application.IntfEndSession; + QApplication_hook_destroy(FAppSessionQuit); + FAppSessionQuit := nil; + {$IFDEF QTDEBUGSESSIONMANAGER} + DebugLn('*** App shutdown releasing sessionManager ...***'); + {$ENDIF} + QSessionManager_release(sessionManager); + end; + end; +end; + +procedure TQtWidgetSet.SlotSaveDataRequest(sessionManager: QSessionManagerH); + cdecl; +begin + {$IFDEF QTDEBUGSESSIONMANAGER} + DebugLn('TQtWidgetSet.SlotSaveDataRequest '); + {$ENDIF} +end; + function TQtWidgetSet.LCLPlatform: TLCLPlatform; begin Result:= lpQT;