PDA

View Full Version : How to use C++ includes?



jochen_r
9th January 2006, 14:28
Hi,

I have used Qt Designer to create a simple application, inside the form1.ui.h File I have my slot functions. In order to understand better when which part is called I wanted to print text output to stdout via cout << "we are here"; I have place the #include<iostream> inside the form1.ui.h file. Anyway the compiler complains that "cout" is not defined.

Am I trying something really stupid? Where do I have to place the include?

Regards,
Jochen

yop
9th January 2006, 14:46
Try std::cout

jochen_r
9th January 2006, 14:50
Ok, found that I have to enter the include in "Includes (in Implementation)" of Qt Designer, now I can compile. But I don't see an output...

I expect to see some output after I click on file open, I have implemented:

void Form1::fileOpen()
{
cout << "my output";
}

Since it uses the standard signals/slots created by default I can't see where the error is.

wysota
9th January 2006, 14:51
Flush the output buffer:


#include <iostream>

void Form1::fileOpen(){
std::cout << "my output" << std::endl;
}

And remember that you have to run the application from a terminal.

BTW. It might be easier to use qDebug() instead of those cout statements.

jochen_r
9th January 2006, 15:34
That works perfectly! Thanks as well for the hint with qdebug. Will have a look into this as well.

Regards,
Jochen