Congratulations to our 2022 Qt Champions!

Input in Terminal

  • 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]

  • 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.

  • 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

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

Log in to reply