PDA

View Full Version : QCoreApplication



Morea
4th June 2007, 19:32
How do you write a console application?

With GUI application I usually write a main.cpp with the code

QApplication app(argc, argv);
SimpleGUI *ai = new SimpleGUI;
ai->show();
return app.exec();

and then I only have to concentrate on the SimpleGUI class. But what do I do with a console application?

Is it just me, or shouldn't there be more short simple examples in the Qt documentation?

marcel
4th June 2007, 19:38
But you just offered the answer.
With QCoreApplication, which is not part of QtGui, but part of the QtCore module.

You can use any Qt class that you can think of and is not part of QtGui, such as the stream classes, device I/O classes, timers, the xml support, the networking module, etc.

Regards

Morea
4th June 2007, 19:43
So

QCoreApplication app(argc, argv);
SimpleGUI *ai = new SimpleGUI;
ai->dostuff();
return app.exec();

But if doStuff is not returning control back to the app.exec() command? What then?

marcel
4th June 2007, 19:47
But I thought you wanted a console application.
What is the point of showing a GUI in a console app? Or you want to have both a GUI and a console on the screen, as part of your app?

Morea
4th June 2007, 19:51
Oh, sorry, it shouldn't be SimpleGUI, it should be something "SimpleClass". No GUI att all.

marcel
4th June 2007, 19:58
Oh, then it is OK.
But don't forget that in console mode you must( sometimes ) make good use of the arguments passed to your app.

It will work.
I assume ai->doStuff() is a wrapper for more complicated stuff.

A Qt console app is not much different than a standard C++ console app.

Regards