PDA

View Full Version : Writing to the console



MCFormax
18th April 2012, 05:06
I have experience programming C++ mainly in plain C++ and VisualC++ environments. Some time ago I switched to Mac (MacBook Pro with OS X Lion) and I started learning Qt4.
I have been able to write simple programs using the Qt4 GUI interface, compiling them within the Mac "Terminal" using the Bash shell. To execute the program, within Terminal I change to the Directory where the compiled application is and I type the command "open MyApplication.app" where "MyApplication.app" is the name of the program I have created. So far no problems.

Then I decided to do a non-GUI application writing some text to the console creating the file "MyConsole.cpp" as follows:

#include <iostream>

int main()
{
std::cout << "console application\n";
}

I complied the application (in Terminal) using the normal "qmake -project", "qmake", "make" as I do with my GUI applications.

Then I do an "ls" command and all the files I expect to see are listed, "Makefile", "MyConsole.cpp", "MyConsole.o", "Qt4Console.app" and "Qt4Console.pro" where "Qt4Console" is the directory where "MyConsole.cpp" resides. In summary nothing different from what I see when I do GUIs.

Now here is the problem I have:
When I enter the command (in Terminal) "open Qt4Console.app", nothing happens. Terminal responds printing in the screen the current directory.
I have tried variations of the code that print to the screen but I see nothing.
Any Ideas about solving this? Please keep in mind that my knowledge of Terminal Bash is very limited and I am afraid I am missing some configuration, switch, flag, etc. to capture text in the console
Thank you

p3c0
18th April 2012, 07:55
verify that CONFIG += console is added to your .pro file

MCFormax
18th April 2012, 23:53
When I start the compilation process the first thing I do is run "qmake -project" which produces the "*.pro" file. This file does not have the statement CONFIG += console", so I added it manually (without the quotation marks). Then I did "qmake" and finally "make". Then all the files seem to be in place but opening the *.app" file does nothing but printing to the console the current directory. I wonder if manually adding the CONFIG += console breaks the natural flow of the compilation process. Is there any way to get this statement automatically in the "*.pro" file?

Thank you for your help.

p3c0
19th April 2012, 11:10
Do you want to create a console application?
CONFIG += console is automatically included when you create a "Qt Console Application"