Important: Please read the Qt Code of Conduct -

Getting focus on activation window with QtSingleApplication in windows OS and a problem.

  • Hi,

    Try as I might, I have been unable to get the main window(set as the activation window with 'setActivationWindow()) associated with the QtSingleApplication to raise and appear in front of other overlapping windows. I am using Windows OS. It looks it is not easy to do that, from other posts I have seen. Could you suggest a way to do this.

    In addition, I am seeing a problem.

    I have the following code:

    QtSingleApplication theApp( ENF_STRING, argc, argv);

    if (theApp.sendMessage( "act" ) )
    QWidget *theWindow = theApp.activationWindow();

    return 0;


    When a second instance of the application runs, I noticed that the activation window is set to null, though it was set previously set with setActivationWindow. But, I can see that the 'sendMessage()' works, because if the window is iconized, and a second instance runs, the window de-minimizes and comes immediately into focus. But, 'theWindow' variable above is null, because the activationWindow is zero.

    What is going on?

  • Please enclose your code snippets with character '@' for easier reading.

  • Clarifying my code snippets for you:

    @QtSingleApplication theApp( ENF_STRING, argc, argv);

    @if (theApp.sendMessage( “act” ) )
    @{ QWidget *theWindow = theApp.activationWindow();

    @return 0;

  • Thanks for adding '@'. Actually, you should start your code section with a ´@' and close it with the character. The plural was not appropriate for you.

    The "example ": is quitting when it sees that there is another instance already running. I would assume that this is the main purpose as the name already suggests. If you really want to run it several times as indicated for the server example, you probably should not activate windows.
    However, I am not an expert in that area, so I am happy to read other comments on this.
    From my point it is somehow strange to use it as you try to do. I would consider the behaviour you encounter as design feature :-)

  • Hi quizzical,

    Am I right, you try to get the widget pointer of the other running application? That is not possible!
    You can set an activationWindow for the local application / process. and it only works inside this process.

    This sendMessage send a message to the first instance of the QtSingleApplication which resides in a different process. You will not get pointers of that process.

Log in to reply