Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Child process needs to stay in front of parent
Forum Updated to NodeBB v4.3 + New Features

Child process needs to stay in front of parent

Scheduled Pinned Locked Moved Solved QML and Qt Quick
10 Posts 5 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bmarzolf
    wrote on last edited by
    #1

    I have a parent application that acts as a process handler of sorts. When it starts a child process, I need that child process to stay in the foreground. Normally, if the user doesn't interact with the screen, the child process starts and it's window fills the screen, and everything is fine, and the user can interact as expected.

    The problem is, if the user touches the screen in that brief moment before the child process has fully started, Windows assumes they are trying to interact with the parent process's window and keeps it in the foreground, and the child process ends up starting with it's window behind the parent. This gives the appearance that nothing happened and the system is stuck on the splash screen.

    This is an embedded system, so it's all locked down, no keyboard shortcuts work. You can't just Alt+tab to get the child process back. Is there a way I can tell the QProcess to keep itself in the foreground? I know that the child process can have windows flags set to keep it in the foreground, but this will make QAs job much more difficult - so unless I can pass windows flags as an argument some how, that's a no go.

    jsulmJ J.HilkJ JonBJ 3 Replies Last reply
    0
    • B bmarzolf

      I have a parent application that acts as a process handler of sorts. When it starts a child process, I need that child process to stay in the foreground. Normally, if the user doesn't interact with the screen, the child process starts and it's window fills the screen, and everything is fine, and the user can interact as expected.

      The problem is, if the user touches the screen in that brief moment before the child process has fully started, Windows assumes they are trying to interact with the parent process's window and keeps it in the foreground, and the child process ends up starting with it's window behind the parent. This gives the appearance that nothing happened and the system is stuck on the splash screen.

      This is an embedded system, so it's all locked down, no keyboard shortcuts work. You can't just Alt+tab to get the child process back. Is there a way I can tell the QProcess to keep itself in the foreground? I know that the child process can have windows flags set to keep it in the foreground, but this will make QAs job much more difficult - so unless I can pass windows flags as an argument some how, that's a no go.

      jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @bmarzolf You can call

      setWindowFlags(Qt::WindowStaysOnTopHint)
      

      in your child app, so it will stay on top all the time.
      See https://doc.qt.io/qt-5/qt.html#WindowType-enum

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • B Offline
        B Offline
        bmarzolf
        wrote on last edited by
        #3

        Yes I know, but as I stated, this is not allowed because it prevents QA from running their tests. I would need to be able to pass that flag to the child as an option, so that it can be set if desired, but not set during QA.

        mrjjM 1 Reply Last reply
        0
        • B bmarzolf

          Yes I know, but as I stated, this is not allowed because it prevents QA from running their tests. I would need to be able to pass that flag to the child as an option, so that it can be set if desired, but not set during QA.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @bmarzolf
          Hi
          Could you not just add a parameter to the call to start the other process so it knows
          if to use WindowStaysOnTopHint or not?
          That assumes you have the code for the child process else it's not an option ofc.

          B 1 Reply Last reply
          1
          • B bmarzolf

            I have a parent application that acts as a process handler of sorts. When it starts a child process, I need that child process to stay in the foreground. Normally, if the user doesn't interact with the screen, the child process starts and it's window fills the screen, and everything is fine, and the user can interact as expected.

            The problem is, if the user touches the screen in that brief moment before the child process has fully started, Windows assumes they are trying to interact with the parent process's window and keeps it in the foreground, and the child process ends up starting with it's window behind the parent. This gives the appearance that nothing happened and the system is stuck on the splash screen.

            This is an embedded system, so it's all locked down, no keyboard shortcuts work. You can't just Alt+tab to get the child process back. Is there a way I can tell the QProcess to keep itself in the foreground? I know that the child process can have windows flags set to keep it in the foreground, but this will make QAs job much more difficult - so unless I can pass windows flags as an argument some how, that's a no go.

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            @bmarzolf you could simply call rise() after show(). That should rise the child process to the end of the draw list.

            You can delay it with a QQueudConection call or a timer, that way it should be at the end, after the mouseEvents


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            B 1 Reply Last reply
            1
            • mrjjM mrjj

              @bmarzolf
              Hi
              Could you not just add a parameter to the call to start the other process so it knows
              if to use WindowStaysOnTopHint or not?
              That assumes you have the code for the child process else it's not an option ofc.

              B Offline
              B Offline
              bmarzolf
              wrote on last edited by
              #6

              @mrjj I'm not sure if the windows flags can be placed inside an if statement, I'd have to investigate that.

              1 Reply Last reply
              0
              • J.HilkJ J.Hilk

                @bmarzolf you could simply call rise() after show(). That should rise the child process to the end of the draw list.

                You can delay it with a QQueudConection call or a timer, that way it should be at the end, after the mouseEvents

                B Offline
                B Offline
                bmarzolf
                wrote on last edited by
                #7

                @J-Hilk There is no rise() function for QProcess, and one uses start() not show() to start the process.

                J.HilkJ 1 Reply Last reply
                0
                • B bmarzolf

                  @J-Hilk There is no rise() function for QProcess, and one uses start() not show() to start the process.

                  J.HilkJ Offline
                  J.HilkJ Offline
                  J.Hilk
                  Moderators
                  wrote on last edited by
                  #8

                  @bmarzolf oh, I thought you meant something like a QDialog, not an actual external program that you start with QProcess!


                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

                  1 Reply Last reply
                  0
                  • B bmarzolf

                    I have a parent application that acts as a process handler of sorts. When it starts a child process, I need that child process to stay in the foreground. Normally, if the user doesn't interact with the screen, the child process starts and it's window fills the screen, and everything is fine, and the user can interact as expected.

                    The problem is, if the user touches the screen in that brief moment before the child process has fully started, Windows assumes they are trying to interact with the parent process's window and keeps it in the foreground, and the child process ends up starting with it's window behind the parent. This gives the appearance that nothing happened and the system is stuck on the splash screen.

                    This is an embedded system, so it's all locked down, no keyboard shortcuts work. You can't just Alt+tab to get the child process back. Is there a way I can tell the QProcess to keep itself in the foreground? I know that the child process can have windows flags set to keep it in the foreground, but this will make QAs job much more difficult - so unless I can pass windows flags as an argument some how, that's a no go.

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #9

                    @bmarzolf
                    Sorry, humour me, it may be obvious to others but not to me....

                    "Your" program is the "parent" here, the one that is kicking off the QProcess, right? The potential child processes are GUI programs, right? And you are in charge of the parent/Qt application here, right? And (contrary to some suggestions) you can't send parameters to the child processes, because they are not your source code, right?

                    Then when the user touches, it is the parent which comes up front, and you wanted but can't get the child to stay on top as it would have done, right?

                    So your app probably cannot bring the child back up front if I recall correctly that Windows doesn't let a process bring another one up-front? Is there a Windows call instead for "push myself to back" which you could use with a delay after starting the child process? Or could you minimize your parent before spawning child and restore yourself on child finish? Or, is there a call to block/ignore touch events so Windows won't bring you up-front which you could make prior to launching the child?

                    B 1 Reply Last reply
                    0
                    • JonBJ JonB

                      @bmarzolf
                      Sorry, humour me, it may be obvious to others but not to me....

                      "Your" program is the "parent" here, the one that is kicking off the QProcess, right? The potential child processes are GUI programs, right? And you are in charge of the parent/Qt application here, right? And (contrary to some suggestions) you can't send parameters to the child processes, because they are not your source code, right?

                      Then when the user touches, it is the parent which comes up front, and you wanted but can't get the child to stay on top as it would have done, right?

                      So your app probably cannot bring the child back up front if I recall correctly that Windows doesn't let a process bring another one up-front? Is there a Windows call instead for "push myself to back" which you could use with a delay after starting the child process? Or could you minimize your parent before spawning child and restore yourself on child finish? Or, is there a call to block/ignore touch events so Windows won't bring you up-front which you could make prior to launching the child?

                      B Offline
                      B Offline
                      bmarzolf
                      wrote on last edited by
                      #10

                      @JonB This is correct.
                      In theory there is a windows api for this. I started down that rabbit hole and quickly backed out of it because it's a lot of work to track down the correct process.

                      I may have found a solution, but I'm not happy with it:

                      powershell -ExecutionPolicy bypass -Command "add-type -AssemblyName Microsoft.VisualBasic; [Microsoft.VisualBasic.Interaction]::AppActivate(process->processId)"
                      

                      Call that from a QProcess::start(), depending on how finicky your system is you may need to break it into the "powershell" command and a QStringList of arguments, but that does pull the child process to the front.

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved