Skip to content

Commit

Permalink
Handle sigint to terminate qgis app immediately
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Mar 5, 2019
1 parent 620db06 commit 534ff68
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/app/CMakeLists.txt
@@ -1,4 +1,5 @@
ADD_SUBDIRECTORY(../../external/libdxfrw dwg/libdxfrw)
SUBDIRS(${CMAKE_SOURCE_DIR}/external/qt-unix-signals)

SET(QGIS_APP_SRCS
${CMAKE_SOURCE_DIR}/external/nmea/gmath.c
Expand Down Expand Up @@ -729,6 +730,7 @@ INCLUDE_DIRECTORIES(SYSTEM
${QWT_INCLUDE_DIR}
${QT_QTUITOOLS_INCLUDE_DIR}
${QSCINTILLA_INCLUDE_DIR}
${CMAKE_SOURCE_DIR}/external/qt-unix-signals
)
INCLUDE_DIRECTORIES(
../analysis/processing
Expand Down Expand Up @@ -882,6 +884,7 @@ IF(WIN32)
ENDIF(WIN32)

TARGET_LINK_LIBRARIES(${QGIS_APP_NAME} qgis_native)
TARGET_LINK_LIBRARIES(${QGIS_APP_NAME} QTSignal)

IF (APPLE)
SET_TARGET_PROPERTIES(${QGIS_APP_NAME} PROPERTIES
Expand Down
18 changes: 18 additions & 0 deletions src/app/main.cpp
Expand Up @@ -38,6 +38,8 @@
#include <cstdlib>
#include <cstdarg>

#include "sigwatch.h"

#ifdef WIN32
// Open files in binary mode
#include <fcntl.h> /* _O_BINARY */
Expand Down Expand Up @@ -1521,6 +1523,22 @@ int main( int argc, char *argv[] )
qgis->menuBar()->setVisible( true );
#endif

UnixSignalWatcher sigwatch;
sigwatch.watchForSignal( SIGINT );

QObject::connect( &sigwatch, &UnixSignalWatcher::unixSignal, &myApp, [&myApp ]( int signal )
{
switch ( signal )
{
case SIGINT:
myApp.exit( 1 );
break;

default:
break;
}
} );

int retval = myApp.exec();
delete qgis;
return retval;
Expand Down

0 comments on commit 534ff68

Please sign in to comment.