A
A
alexey_abramov2015-08-04 20:32:18
Qt
alexey_abramov, 2015-08-04 20:32:18

How to implement a console command line in QT using standard streams?

Hello. I am making a server application for my little game. I could do it using the GUI and this question was not there, but I wanted to implement it using the command line. Those. a window into which we drive in console commands and get answers, but this application also works by itself with clients, of course.
The simple server is the server constructor in which we launch it. We created, connected everything using signal slots, and open a separate stream, which actually works with stdin and stdout.

gserver::gserver(int nPort) : NextBlockSize(0)
{
    //создание, соединение и прочее опустил
        logadd("server ready"); // моя функция добавления в журнал(сообщений
        thread.start();
        thread.run();
   

}

In a thread like the following is called
void ThreadIO::run()
{
    qtin = new  QTextStream(stdin);
    qtout = new  QTextStream(stdout);
    QString line;
    line = qtin->readLine();
// далее идет обработка и прочее.
}

Of course, this option - does not work normally, because. working in stdin, even in a separate thread, we are silencing the entire application. So, of course, no requests from clients, receiving any signals and slots, do not work here, and do not pass until something is entered.
Please tell me how to implement this kind of application. Those. so that stdin doesn't "jam" everything. Those. it is necessary as for example in gdb, and other other applications with the command line separately.
If there is some kind of implementation that does not use standard streams, or something else, please write it down, or tell me where to dig. I googled enough and didn't find anything similar. I tried to take out operations with stdin in a separate process - it turns out, unfortunately, the same thing.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question