Runs the main application for this instance and returns the
        success value.
        
        :return     <int>

def exec_(self):
        """
        Runs the main application for this instance and returns the
        success value.
        
        :return     <int>
        """
        # create the tray icon
        if self.autoCreateTrayIcon() and not self.trayIcon():
            try:
                window = self.topLevelWindows()[0]
            except IndexError:
                pass
            else:
                # create the menu
                menu = QtGui.QMenu(window)
                
                if self.applicationName():
                    act = menu.addAction('Quit {0}'.format(self.applicationName()))
                else:
                    act = menu.addAction('Quit')
                
                act.triggered.connect(self.quit)
                
                # create the tray icon
                icon = QtGui.QSystemTrayIcon()
                icon.setIcon(self.windowIcon())
                icon.setObjectName('trayIcon')
                icon.setContextMenu(menu)
                icon.setToolTip(self.applicationName())
                icon.show()
                
                self._trayIcon = icon
        
        result = super(XApplication, self).exec_()
        
        # save the settings before exiting
        self.saveSettings()
        return result