Qt Creator: application output in a separate window, instead of the output pane?

  • When using Qt Creator, I'd like to be able to have my application's output appear in a separate window form the main Qt Creator window, instead of the "Application Output" pane that is always anchored to the bottom of the main window. This will help me better utilize all of my available screen real estate. Is there any way to do this?

    In case there are platform specific solutions, I'm running OS X. However if there's a cross-platform solution that would be great too.

  • Lifetime Qt Champion


    What about the "Run in Terminal" option in the Project panel under Run ?

  • @SGaist It's a bit inconvenient because it causes a new terminal window to open every time. I'd prefer to have just one window that all of my app's output goes to so I can place it in a specific spot.

    I see that, behind the scenes, Qt Creator is calling a bash script that executes some AppleScript to get the terminal window to open. I may try tinkering with it to see if I can get it to behave how I want, but it'd be much more convenient if Qt Creator allowed breaking off the Application Output (and the issues section now that I think about it) into its own floating window so that I can make full use of the vertical real estate of my screen.

  • There is a task for this in Jira: https://bugreports.qt.io/browse/QTCREATORBUG-9488

    If you want this feature, please REGISTER THERE AND VOTE FOR IT!

  • @Guy-Gizmo hi
    you can use qInstallMessageHandler to do whatever you need with the application output

  • Wasn't expecting this thread to get resurrected! I'm glad to see there's a feature I can vote for to have this ability added to Qt Creator.

    I've dealt with this in the meantime by enabling "run in terminal" in all of my project's run settings and then setting my terminal in Preferences > Environment > System > Terminal to a custom script that uses whichever terminal window is the closest to the lower right corner of my desktop. (That's where I want my program output to go.) This lets me effectively have it be in a separate window from Qt Creator that I can position wherever I like.

    I'm running macOS so my solution only works for that, but in case anyone wants it, here's the script I'm using to do the above in iTerm2:

    #! /bin/bash
    # ugly escaping: for apple script \ and " need to be escaped, whereas %q takes care of all bash escaping
    declare -a args
    mydir=$(printf '%q' "$mydir")
    args[0]="bribriSaveDir=\`pwd\`; cd ${mydir//\"/\\\"}; "
    # args[0]="cd ${mydir//\"/\\\"};"
    for a in "$@" ; do
        x=$(printf '%q ' "$a")
    args+=('; cd ${bribriSaveDir}')
    osascript <<EOF
    tell application "System Events" to set terminalRunning to exists process "iTerm2"
    if not terminalRunning then
        tell application "iTerm"
            repeat while the (count of the windows) = 0
                delay 0.1
            end repeat
        end tell
    end if
    set exec to "$mArgs"
    tell application "iTerm"
        set theWindows to {}
        repeat with i from 1 to the count of the windows
            if (is hotkey window of window i) = false and (is at shell prompt of current session of window i) = true then
                copy window i to the end of theWindows
            end if
        end repeat
        if (count of theWindows) = 0 then
            set newWindow to create window with default profile
            tell current session of newWindow to write text exec with newline
            set currentWin to window 1
            set currentDistance to 0
            repeat with i from 1 to the count of theWindows
                set theWindow to item i of theWindows
                set bb to bounds of theWindow
                set x to (item 3 of bb)
                set y to (item 4 of bb)
                set dist to x * x + y * y
                if dist > currentDistance then
                    set currentWin to theWindow
                    set currentDistance to dist
                end if
            end repeat
            tell current session of currentWin to write text exec with newline
        end if
    end tell

    The criteria for which window it selects can be adjusted by changing the interior of the repeat with i from 1 to the count of theWindows loop. Whichever window currentWin gets assigned to will be the one that Qt Creator runs the app in.

    I also got annoyed with the way that you have to press enter in the terminal window after the program I'm running in Qt Creator exits, since that doesn't really make sense to do if you're reusing the same terminal window over and over again. So I downloaded the source to Qt Creator and made a small modification to the qtcreator_process_stub tool it includes (which is the little executable that communicates with Qt Creator and manages running your app in a terminal window) so that it doesn't do that any longer, and it prints the return code of my program since I find it's useful to know precisely when it's terminated and how. Each time I update Qt Creator I just copy my version of qtcreator_process_stub into its application bundle to get the behavior I want. So far there hasn't been any changes to qtcreator_process_stub in several versions so it's been fine to just keep copying in my version of it.

    Here's a diff of the changes I made to it, at least for the unix / macOS side of things. I imagine it'd be easy to do something similar on Windows:

    --- a/src/libs/utils/process_stub_unix.c
    +++ b/src/libs/utils/process_stub_unix.c
    @@ -70,8 +70,8 @@ static volatile int chldPid;
     static void __attribute__((noreturn)) doExit(int code)
         tcsetpgrp(0, getpid());
    -    puts(sleepMsg);
    -    fgets(sleepMsg, 2, stdin); /* Minimal size to make it wait */
    +    //puts(sleepMsg);
    +    //fgets(sleepMsg, 2, stdin); /* Minimal size to make it wait */
    @@ -163,9 +163,11 @@ static void sigchldHandler(int sig)
                 sendMsg("exit %d\n", WEXITSTATUS(chldStatus));
    +            printf("\nExited with status %d\n", chldStatus >> 8);
             } else {
                 sendMsg("crash %d\n", WTERMSIG(chldStatus));
    +            printf("\nExited with status %d\n", chldStatus >> 8);
    @@ -180,7 +182,8 @@ int main(int argc, char *argv[])
         char **env = 0;
         struct sockaddr_un sau;
         struct sigaction act;
    +       printf("\n");
         memset(&act, 0, sizeof(act));
         if (argc < ArgEnv) {

    I figured I'd post all that stuff just in case someone else finds it useful. I definitely appreciate that Qt Creator is open source so I can make little modifications to it like this.