# HG changeset patch # User IBBoard # Date 1280592194 0 # Node ID 55d4f16c982bec05317e7eb898d73c42265aa878 # Parent 4ec2083eb7552e4d1b4f72d472f14fde168fc796 Fixes #250: QtSharp app doesn't always quit properly * Override Close event to dispose of file dialogs (open and save) * Remove unnecessary event handler hooked to close * Change app initialisation to match pattern used by Synapse * Create file dialogs without specifying "this" as parent - seems to be main fix, for some reason. diff -r 4ec2083eb755 -r 55d4f16c982b Main.cs --- a/Main.cs Sat Mar 06 15:23:40 2010 +0000 +++ b/Main.cs Sat Jul 31 16:03:14 2010 +0000 @@ -16,7 +16,6 @@ class MainClass { private static ILog logger = LogManager.GetLogger(typeof(MainClass)); - static MainWindow win; static QApplication app; public static void Main(string[] args) @@ -24,17 +23,19 @@ try { logger.InfoFormat("Starting application with args: {0}", args.ToString()); - app = new QApplication(args); - - SetUpWarFoundryEnvironment(); + app = new QApplication(args, true); + app.QuitOnLastWindowClosed = true; + logger.Debug("Starting exec"); + QApplication.Invoke(delegate + { + SetUpWarFoundryEnvironment(); - win = new MainWindow(); - win.Show(); - logger.Debug("Starting exec"); - int result = QApplication.Exec (); - logger.Info("Closing application"); - Environment.Exit(result); - logger.Info("Exited"); + MainWindow win = new MainWindow(); + win.Show(); + QApplication.SetActiveWindow(win); + }); + int result = QApplication.Exec(); + logger.InfoFormat("Closing application - exit code {0}", result); } catch(Exception ex) { diff -r 4ec2083eb755 -r 55d4f16c982b MainWindow.cs --- a/MainWindow.cs Sat Mar 06 15:23:40 2010 +0000 +++ b/MainWindow.cs Sat Jul 31 16:03:14 2010 +0000 @@ -47,11 +47,11 @@ } SetAppTitle(); - saveArmyDialog = new QFileDialog(this); + saveArmyDialog = new QFileDialog(); saveArmyDialog.acceptMode = QFileDialog.AcceptMode.AcceptSave; saveArmyDialog.fileMode = QFileDialog.FileMode.AnyFile; saveArmyDialog.SetDirectory(new QDir(Environment.GetFolderPath(Environment.SpecialFolder.Personal))); - openArmyDialog = new QFileDialog(this); + openArmyDialog = new QFileDialog(); openArmyDialog.acceptMode = QFileDialog.AcceptMode.AcceptOpen; openArmyDialog.fileMode = QFileDialog.FileMode.ExistingFile; openArmyDialog.SetNameFilter("*.army"); @@ -64,6 +64,13 @@ CommandStack.CommandStackUpdated+= HandleCommandStackCommandStackUpdated; } + protected override void CloseEvent(QCloseEvent arg1) + { + base.CloseEvent(arg1); + saveArmyDialog.Dispose(); + openArmyDialog.Dispose(); + } + private void SetUpActionIcons() { layout.actionCreateArmy.icon = new QIcon("icons/ui/filenew.png"); diff -r 4ec2083eb755 -r 55d4f16c982b qt-gui/MainWindowLayout.cs --- a/qt-gui/MainWindowLayout.cs Sat Mar 06 15:23:40 2010 +0000 +++ b/qt-gui/MainWindowLayout.cs Sat Jul 31 16:03:14 2010 +0000 @@ -1,8 +1,8 @@ /******************************************************************************** ** Form generated from reading ui file 'MainWindowLayout.ui' ** -** Created: Sat Feb 13 10:32:31 2010 -** by: Qt User Interface Compiler for C# version 4.5.3 +** Created: Sat Jul 31 16:07:24 2010 +** by: Qt User Interface Compiler for C# version 4.6.3 ** ** WARNING! All changes made in this file will be lost when recompiling ui file! ********************************************************************************/ @@ -103,7 +103,7 @@ MainWindowLayout.SetCentralWidget(mainContent); menubar = new QMenuBar(MainWindowLayout); menubar.ObjectName = "menubar"; - menubar.Geometry = new QRect(0, 0, 696, 23); + menubar.Geometry = new QRect(0, 0, 696, 21); menuFile = new QMenu(menubar); menuFile.ObjectName = "menuFile"; menuExportArmyAs = new QMenu(menuFile); @@ -141,7 +141,6 @@ menuHelp.AddAction(actionAbout); RetranslateUi(MainWindowLayout); - QObject.Connect(actionExit, Qt.SIGNAL("triggered()"), MainWindowLayout, Qt.SLOT("close()")); unitTabs.CurrentIndex = 0; diff -r 4ec2083eb755 -r 55d4f16c982b qt-gui/MainWindowLayout.ui --- a/qt-gui/MainWindowLayout.ui Sat Mar 06 15:23:40 2010 +0000 +++ b/qt-gui/MainWindowLayout.ui Sat Jul 31 16:03:14 2010 +0000 @@ -66,7 +66,7 @@ 0 0 696 - 23 + 21 @@ -206,22 +206,5 @@ - - - actionExit - triggered() - MainWindowLayout - close() - - - -1 - -1 - - - 399 - 299 - - - - +