From 301db81bd434b3af775e54055bbc212744bea219 Mon Sep 17 00:00:00 2001 From: YiFang Xiao Date: Fri, 12 May 2023 08:12:46 +0800 Subject: [PATCH] opt: move auto release guard to the variable by this way, developer will have a more clear view about what will happen when released --- src/main.cc | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main.cc b/src/main.cc index 22d4229d..6c4da55d 100644 --- a/src/main.cc +++ b/src/main.cc @@ -206,15 +206,6 @@ void processCommandLine( QCoreApplication * app, GDOptions * result) } } -class LogFilePtrGuard -{ - QFile logFile; - Q_DISABLE_COPY( LogFilePtrGuard ) -public: - LogFilePtrGuard() { logFilePtr = &logFile; } - ~LogFilePtrGuard() { logFilePtr = 0; } -}; - int main( int argc, char ** argv ) { #ifdef Q_OS_UNIX @@ -304,7 +295,15 @@ int main( int argc, char ** argv ) QWebEngineUrlScheme::registerScheme(webUiScheme); } - LogFilePtrGuard logFilePtrGuard; + QFile file; + logFilePtr = &file; + auto guard = qScopeGuard( [ &file ]() { + logFilePtr = nullptr; + file.close(); + } ); + + Q_UNUSED( guard ) + if ( app.isRunning() ) {