Hiding and relaunching the same instance of QApplication



  • Hi there,

    I have a QApplication in which I have a custom QDialog. The dialog offers the users a set of options and then launches a process via QProcess. While the process launched still runs, the app if closed has to still run. To achieve this, I re-implemented the 'closeEvent' of QWidget and accept() or ignore() 'ed the event based on whether a process is launched or not.

    In the closeEvent() function, I am hiding my QDialog. With this, for the user the application is closed (it will however run in the task manager). I expect the user to relaunch the application by running the program again. At this point I need to figure out that another instance is already running and that instance to should come to the foreground.

    Can anyone help me with how I can achieve this?

    Regards,
    Bharath



  • qtsingleapplication from "qtsolutions":https://qt.gitorious.org/qt-solutions could help you



  • I read about the qtsingleapplication. I would like to know if there's any other way.



  • Can you tell, what kind of solution do you need, and why qtsingleapplication is not suitable?



  • I don't have a reason why not to use QtSingleApplication, but I used the above technique of hiding the app by overriding the closeEvent of the dialog. And when the 2nd instance of the process is launched, it uses a QSharedMemory to notify the already running instance to bring itself to foreground. The already running instance keeps monitoring changes to QSharedMemory (a QObject timer that expires for every 5 seconds is used). If it detects a change in the shared memory, it brings itself to foreground.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.