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. QTextStrem stdin dont work?
Forum Updated to NodeBB v4.3 + New Features

QTextStrem stdin dont work?

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 646 Views 3 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.
  • P Offline
    P Offline
    PeterS
    wrote on last edited by
    #1

    The question is probably quite trivial,
    but I can't find a solution.
    It doesn't seem to work for other users.
    I can't enter my name.

    Can you help me please

    
    #include <QtCore/QCoreApplication>
    #include <QTextStream>
    #include <QString>
    
    int main(int argc, char *argv[])
    {
        QCoreApplication app(argc, argv);
        QTextStream qout (stdout);
        QTextStream qin (stdin);
        qin.flush();//Does it make sense? to clear memory directly? Should actually be ller.
        qout <<     "Please enter your name: ";
        QString inpu =qin.readLine();
        Qt::endl;
        qout <<" Welcome  " << inpu <<Qt::endl;
    
        return app.exec();
    }
    
    1 Reply Last reply
    0
    • posktomtenP Offline
      posktomtenP Offline
      posktomten
      wrote on last edited by
      #2

      @PeterS Hello!
      Try this. And keep in mind that it is not possible to write input values in Qt Creator.

      //    QCoreApplication app(argc, argv);
          QTextStream qout(stdout);
          QTextStream qin(stdin);
      //    qin.flush();//Does it make sense? to clear memory directly? Should actually be ller.
          qout << "Please enter your name: ";
          qout.flush(); // clears the keyboard buffer
          qin.skipWhiteSpace(); // Remove white characters that interrupt
          QString inpu = qin.readLine();
      //    Qt::endl;
      //    qout <<" Welcome  " << inpu <<Qt::endl;
          qout << " Welcome  " << inpu;
      //    return app.ex
      

      posktomten

      P 1 Reply Last reply
      0
      • posktomtenP posktomten

        @PeterS Hello!
        Try this. And keep in mind that it is not possible to write input values in Qt Creator.

        //    QCoreApplication app(argc, argv);
            QTextStream qout(stdout);
            QTextStream qin(stdin);
        //    qin.flush();//Does it make sense? to clear memory directly? Should actually be ller.
            qout << "Please enter your name: ";
            qout.flush(); // clears the keyboard buffer
            qin.skipWhiteSpace(); // Remove white characters that interrupt
            QString inpu = qin.readLine();
        //    Qt::endl;
        //    qout <<" Welcome  " << inpu <<Qt::endl;
            qout << " Welcome  " << inpu;
        //    return app.ex
        
        P Offline
        P Offline
        PeterS
        wrote on last edited by
        #3

        @posktomten
        Thank you.

        I don't think on the fact thats is not possible to make inputs in QtCreator. Now it works fine.

        JonBJ 1 Reply Last reply
        0
        • P PeterS has marked this topic as solved on
        • P PeterS

          @posktomten
          Thank you.

          I don't think on the fact thats is not possible to make inputs in QtCreator. Now it works fine.

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

          @PeterS said in QTextStrem stdin dont work?:

          I don't think on the fact thats is not possible to make inputs in QtCreator.

          What does this mean? Where have you be running your application, seeing its output, and trying to input? You certainly have not said so previously. Qt Creator? Are you simply looking at the Application Output there, which as it says simply displays output? Have you run your application outside of Creator in a terminal? If that works, you will need to tell Creator you want it to open a terminal for input/output when you run your program from there.

          P 1 Reply Last reply
          0
          • JonBJ JonB

            @PeterS said in QTextStrem stdin dont work?:

            I don't think on the fact thats is not possible to make inputs in QtCreator.

            What does this mean? Where have you be running your application, seeing its output, and trying to input? You certainly have not said so previously. Qt Creator? Are you simply looking at the Application Output there, which as it says simply displays output? Have you run your application outside of Creator in a terminal? If that works, you will need to tell Creator you want it to open a terminal for input/output when you run your program from there.

            P Offline
            P Offline
            PeterS
            wrote on last edited by
            #5

            @JonB Yes , you are right. I has only looking in the Application Output, Inside a terminal it runs fine. Thanks you.

            JonBJ 1 Reply Last reply
            0
            • P PeterS

              @JonB Yes , you are right. I has only looking in the Application Output, Inside a terminal it runs fine. Thanks you.

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

              @PeterS OK, hopefully you have found in Creator where you can set so this application always gets a terminal for it to run in.

              SGaistS 1 Reply Last reply
              0
              • JonBJ JonB

                @PeterS OK, hopefully you have found in Creator where you can set so this application always gets a terminal for it to run in.

                SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Hi,

                Out of curiosity, why are you calling app.exec(); since the rest of the logic will be done by the time you reach that line ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                posktomtenP 1 Reply Last reply
                1
                • SGaistS SGaist

                  Hi,

                  Out of curiosity, why are you calling app.exec(); since the rest of the logic will be done by the time you reach that line ?

                  posktomtenP Offline
                  posktomtenP Offline
                  posktomten
                  wrote on last edited by
                  #8

                  @SGaist I commented it out.

                  posktomten

                  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