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. Creating a "terminal"
QtWS25 Last Chance

Creating a "terminal"

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 5.4k Views
  • 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.
  • Z Offline
    Z Offline
    Zeolitic
    wrote on last edited by Zeolitic
    #1

    I'm trying to mimic a "terminal" for and IDE app I am creating. For example, I would like the output of my program to be displayed on the main Qt window. I also would like to be able to get user input from this same window.

    In essence I am looking for something very similar to the "Application Output" pane of the QtCreator.

    Any ideas on how this could be accomplished would me much appreciated :)

    JonBJ 1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi and welcome to the forums
      How many of the features do you need?
      a QPlainTextEdit can be used to show text lines and also accept user input but
      its not super "terminal" alike. So do you need to run "command" or in what
      way terminal like?

      https://github.com/jacob3141/qtterminalwidget

      1 Reply Last reply
      5
      • Z Zeolitic

        I'm trying to mimic a "terminal" for and IDE app I am creating. For example, I would like the output of my program to be displayed on the main Qt window. I also would like to be able to get user input from this same window.

        In essence I am looking for something very similar to the "Application Output" pane of the QtCreator.

        Any ideas on how this could be accomplished would me much appreciated :)

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

        @Zeolitic
        This gets asked several times. Depends what you want from it:

        • A full terminal emulator/widget? If you don't want to write it yourself, or if you want to see how others do it to inspire you, there are several from Google qt terminal emulator.

        • Is the "output of my program" stuff you write to stdout? Does input have to come from stdin?

        • If you don't care about above, a QTextEdit can accept output from your program and accept input from the user.

        I don't know if "the "Application Output" pane of the QtCreator." is available in itself.

        1 Reply Last reply
        5
        • Z Offline
          Z Offline
          Zeolitic
          wrote on last edited by
          #4

          @mrjj @JonB

          Thanks for your quick replies!

          I am looking just to output to the "terminal" and receive user input from the "terminal".

          The "output of my program" is currently things that are being written to stdout, however I find this mess and would like to write to something inside the app. I don't care if it is received from stdin or written directly to stdout, I just care that I can send and receive input from this terminal.

          Sounds like I have a good idea of where to start!

          Any further ideas or examples you have are much appreciated.

          1 Reply Last reply
          1
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by mrjj
            #5

            Hi
            So its more like a Debug view that actual a terminal ?
            To get your output from stdout you can redirect it.
            Like shown here
            https://stackoverflow.com/questions/10308425/redirect-stdcout-to-a-qtextedit
            Besides a QPlainTextEdit, you can use a LineEdit that is a single line edit
            so if you place it under the PlainTextEdit, it can be a one liner input "prompt" and you can hook to its returnPressed signal to know when to react.

            All that said:
            You do know qDebug() ?

            Small demo project with the code from link
            https://www.dropbox.com/s/1i71xzx7c6xwdtw/SemiConsole.zip?dl=0

            
            MainWindow::MainWindow(QWidget *parent)
                : QMainWindow(parent)
                , ui(new Ui::MainWindow)
            {
                ui->setupUi(this);
            
                redirect = new QDebugStream(std::cout, ui ->textEdit);
                std::cout << "Send this to the Text Edit!" << std::endl;
            
            }
            
            MainWindow::~MainWindow()
            {
                delete redirect;
                delete ui;
            
            }
            
            
            void MainWindow::on_lineEdit_returnPressed()
            {
                std::cout << "COMMAND !!!" << std::endl;
            }
            
            

            alt text

            Note that sample uses TextEdit and not PlainTextEdit. Not that it matters much overall.

            1 Reply Last reply
            2
            • Z Offline
              Z Offline
              Zeolitic
              wrote on last edited by
              #6

              I'm making a my own custom coding language and and IDE to go along with it. So on my mainwindow currently I have a text edit where the user can write code and then compile it. The issues right now is that when the user prints anything, it appears in the console that my program was run in (because I am just using cout for the moment). However, I would like the output to be displayed in the same area the code is written.

              I think what you've described above is perfect and is more than enough to get me started :)

              mrjjM 1 Reply Last reply
              0
              • Z Zeolitic

                I'm making a my own custom coding language and and IDE to go along with it. So on my mainwindow currently I have a text edit where the user can write code and then compile it. The issues right now is that when the user prints anything, it appears in the console that my program was run in (because I am just using cout for the moment). However, I would like the output to be displayed in the same area the code is written.

                I think what you've described above is perfect and is more than enough to get me started :)

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

                @Zeolitic
                Hi. Super.
                later you might be interested in

                • Highligthing
                  https://doc.qt.io/qt-5/qtwidgets-richtext-syntaxhighlighter-example.html
                • line numbers
                  https://doc.qt.io/qt-5/qtwidgets-widgets-codeeditor-example.html

                if you not already seen it. :)

                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