0

I noticed something with qDebug() QTextStrean and generally stdin, stdout wanna ask, how it works actually, see this:

THIS WORKS!

method showmenu() using QTextStream

showMenu(){
            QTextStream m_out(stdout);
            QTextStream m_in(stdin);

            m_out() << "Hey";
}

THIS DOESN'T WORK!

.h

//declaration 

public:
   QTextStream m_out;
   QTextStream m_in;

.cpp

//method showMenu() 

showMenu(){
             m_out(stdout);
             m_in(stdin);

             m_out() << "Hey";
}

I noticed, it has problem with overloading, because also qDebug() uses stdout... am I correct?

It throws this error:

1>D:..\App_console.cpp(20,15): error : no match for call to '(QTextStream) (_IO_FILE*&)'

I have included cstdio

What could it be?

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • In the first case you call a constructor. In the second case you try to call `operator()` that doesn't exist. – ilotXXI Oct 18 '16 at 11:33

1 Answers1

2

Pre C++11, You will need to do that in your Constructor Initialization List. In the Constructor Definition of your class, say MyStreamer, you can initialize it like this:

class MyStreamer{
....
public:
   QTextStream m_out;
   QTextStream m_in;
};

In your .cpp file:

MyStreamer::MyStreamer(...) : m_out(stdout), m_in(stdin) {
    ....
}

In C++11 and beyond, you could simply use uniform initialization:

class MyStreamer{
....
public:
   QTextStream m_out{stdout};
   QTextStream m_in{stdin};
};
WhiZTiM
  • 21,207
  • 4
  • 43
  • 68