Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to clear output of a cmd on QT CLI app?
Forum Updated to NodeBB v4.3 + New Features

How to clear output of a cmd on QT CLI app?

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 4 Posters 2.7k 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.
  • K Offline
    K Offline
    Kien Bui
    wrote on last edited by
    #3

    I meant that:
    ./app
    It shows:

    log line 1
    log line 2
    ....
    ... log line n
    Result A
    Result B
    

    But I only want to it shows

    Result A
    Result B
    
    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #4

      OK, then you can configure your log output using logging categories.

      (Z(:^

      K 1 Reply Last reply
      0
      • sierdzioS sierdzio

        OK, then you can configure your log output using logging categories.

        K Offline
        K Offline
        Kien Bui
        wrote on last edited by
        #5

        @sierdzio Thanks for your suggestion but maybe they don't only log, it can be notify processing, it shows for users, but when finished, they should be deleted.

        sierdzioS 1 Reply Last reply
        0
        • K Kien Bui

          @sierdzio Thanks for your suggestion but maybe they don't only log, it can be notify processing, it shows for users, but when finished, they should be deleted.

          sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #6

          @Kien-Bui said in How to clear output of a cmd on QT CLI app?:

          but when finished, they should be deleted.

          I've told you: that's not possible. CLI does not work this way, CLI keeps the history visible. This is not something Qt-related, anyway.

          (Z(:^

          1 Reply Last reply
          4
          • hskoglundH Offline
            hskoglundH Offline
            hskoglund
            wrote on last edited by
            #7

            Just to add to @sierdzio's comment, one "solution" I saw long time ago was to print 10000 empty lines just before printing the result lines.

            1 Reply Last reply
            3
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #8

              One more thought: you can send your logs to stderr and output to stdout. Then in terminal you'll have control over this (but not the way you want): you can pipe stderr into a file, for example, and only show stdout.

              (Z(:^

              1 Reply Last reply
              0
              • K Offline
                K Offline
                Kien Bui
                wrote on last edited by
                #9

                Okie. I see. It is not problem relates Qt. It is only a problem of the terminal window.

                Maybe move the cursor up and then replace text or erase the content of that line.

                JonBJ 1 Reply Last reply
                0
                • K Kien Bui

                  Okie. I see. It is not problem relates Qt. It is only a problem of the terminal window.

                  Maybe move the cursor up and then replace text or erase the content of that line.

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

                  @Kien-Bui said in How to clear output of a cmd on QT CLI app?:

                  Maybe move the cursor up and then replace text or erase the content of that line.

                  Good luck!

                  K 1 Reply Last reply
                  0
                  • JonBJ JonB

                    @Kien-Bui said in How to clear output of a cmd on QT CLI app?:

                    Maybe move the cursor up and then replace text or erase the content of that line.

                    Good luck!

                    K Offline
                    K Offline
                    Kien Bui
                    wrote on last edited by
                    #11

                    @JonB said in How to clear output of a cmd on QT CLI app?:

                    @Kien-Bui said in How to clear output of a cmd on QT CLI app?:

                    Maybe move the cursor up and then replace text or erase the content of that line.

                    Good luck!

                    What happen if I do this?

                    JonBJ 1 Reply Last reply
                    0
                    • K Kien Bui

                      @JonB said in How to clear output of a cmd on QT CLI app?:

                      @Kien-Bui said in How to clear output of a cmd on QT CLI app?:

                      Maybe move the cursor up and then replace text or erase the content of that line.

                      Good luck!

                      What happen if I do this?

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

                      @Kien-Bui
                      You will have to figure out the raw character sequences to send to the console to address the cursor, delete lines etc. And how to send them correctly from code. It will require Windows-specific code, not cross-platform.

                      However, since you do not know just what output your "log lines" have produced, you will not know how many lines it will/might have occupied (even with @sierdzio's correct suggestion that you terminate them with \r and not \r\n).

                      Your code will presumably assume that every "line" of output has occupied no more than 1 "line" on the screen, and that will not be good enough if, say, it has spilled onto a second line.... [EDIT: If you know when you have finished outputting the log stuff and before you output stuff which you will want retained in the final console, you can probably simplify by either sending a "clear screen" code at that point or even simpler sending 100+ blank lines to scroll off, if that is acceptable.]

                      Tbh, why you are wanting to do all this with output to the terminal/console/Command Prompt window is quite beyond me. Do you really need the output to go to a console window? It might be a lot easier to approach if you have a "parent" Qt GUI application which QProcess spawns your CLI child process and captures all its output for display inside the GUI (e.g. QTextEdit), where you would be in control and able to do what you like with the output as & when required. But of course I don't know if that is what you want.

                      1 Reply Last reply
                      1

                      • Login

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