Mercurial > repos > IBBoard.WarFoundry.GUI.QtSharp
changeset 26:55d4f16c982b
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.
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 31 Jul 2010 16:03:14 +0000 |
parents | 4ec2083eb755 |
children | 7eaa8a1715e2 |
files | Main.cs MainWindow.cs qt-gui/MainWindowLayout.cs qt-gui/MainWindowLayout.ui |
diffstat | 4 files changed, 26 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- 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) {
--- 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");
--- 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;
--- 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 @@ <x>0</x> <y>0</y> <width>696</width> - <height>23</height> + <height>21</height> </rect> </property> <widget class="QMenu" name="menuFile"> @@ -206,22 +206,5 @@ </action> </widget> <resources/> - <connections> - <connection> - <sender>actionExit</sender> - <signal>triggered()</signal> - <receiver>MainWindowLayout</receiver> - <slot>close()</slot> - <hints> - <hint type="sourcelabel"> - <x>-1</x> - <y>-1</y> - </hint> - <hint type="destinationlabel"> - <x>399</x> - <y>299</y> - </hint> - </hints> - </connection> - </connections> + <connections/> </ui>