PDA

View Full Version : Terminating a console app



cejohnsonsr
30th August 2010, 01:48
I have a small console app that will do some post install file & text proccessing. I need it to be self terminating & I need it to NOT show a console while running. I tried a.quit() & a.exit() to terminate, but neither one worked. I'm not sure how to supress the console window. The app will run on Win.

Any help is appreciated.

Thanx,

Ed



#include <QTextStream>
#include <QString>
#include <QFile>

QTextStream cout(stdout, QIODevice::WriteOnly);
QTextStream cerr(stderr, QIODevice::WriteOnly);

int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString str1, str2;
QFile file("fixPath.txt");
if(file.open(QIODevice::ReadOnly))
{
QTextStream in(&file);
while (not in.atEnd())
{
str1 = in.readLine();
cout << str1 << endl;
}
file.close();
}

return a.exec();
}

ChrisW67
30th August 2010, 04:19
Suppressing the console window: Does
CONFIG -= console in your Pro file do it for you? Of course, you have to have somewhere for your cout and cerr streams to go.

If you don't enter the event loop, i.e. don't call QCoreApplication::exec(), then the program just runs straight through to completion.

tbscope
30th August 2010, 05:46
I tried a.quit() & a.exit()

This is a common problem. You need to let the program enter the event loop.
To quit, you can use a timer with a singleshot for about 100ms and call the slot quit().

cejohnsonsr
30th August 2010, 21:21
Thank you for the answers. I'm learning & relearning a little at a time.

Ed