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. Input in Terminal
Forum Updated to NodeBB v4.3 + New Features

Input in Terminal

Scheduled Pinned Locked Moved General and Desktop
4 Posts 4 Posters 1.9k 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.
  • Q Offline
    Q Offline
    qttroubles
    wrote on last edited by
    #1

    I just wrote a simple code to try to interact with the terminal for Qt.
    @
    #include <QtGui/QApplication>
    #include <iostream>
    #include <iomanip>
    #include "mainwindow.h"
    using namespace std;

    int main(int argc, char *argv[])
    {
    int a;
    cin >> a;
    if(a == 1){
    cout << "good";
    }
    }
    @
    It obviously works and the terminal pops up since I clicked the "run in terminal" option in projects. However, it is quite frustrating that I cannot interact with the terminal in anyway. Whenever I click enter it closes the terminal and I'm trying to find a way to input into the terminal that won't be as frustrating.

    [Edit: Added @ tags -- mlong]

    1 Reply Last reply
    0
    • A Offline
      A Offline
      AcerExtensa
      wrote on last edited by
      #2

      How should it be possible to "interact" with terminal if you didn't implement this?
      Your code says:

      1. read int from stdin
      2. if value equals 1 - print string "good" to the stdout
      3. exit without even returning exit code

      and why are you including <QtGui/QApplication> if you don't use Qt??? Simple including <QtGui/QApplication> doesn't makes your app Qt-App!

      You should start with tutorials for Qt.

      God is Real unless explicitly declared as Integer.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        terenty
        wrote on last edited by
        #3

        Terminal opens as soon as your program starts and closes as soon as it ends leaving no chance to see any output of your program. but for example in MSVC theres Ctrl+F5 combination that runs you program in console that doesnot close after you app finishes, and waits untill you press any key. Or you can add another additional "fake" input at the end of your app just to make it not exit immediately:
        @int main(int argc, char *argv[])
        { int a;
        cin >> a;
        if(a == 1){ cout << “good”;}

        // end of the program
        char p;
        cin>>p; // like pause before exit
        }@

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tobias.hunger
          wrote on last edited by
          #4

          Creator actually waits for the user to press return before closing the terminal window again...

          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