simple console application does ot finish
Hi,
I'm creating a console application. I've created it in the Qt Creator with New File or Project (...) and I've changed the main just like this:
Code:
#include <QtCore/QCoreApplication>
#include <iostream>
int main(int argc, char *argv[])
{
std::cout << "hello" << std::endl;
return a.exec();
}
The only problem around this is that when I run it it does not seem to finish. I have to terminate the program "roughly" by switching off the popping console window or running it from a command promt using Ctrl+C. In the Creator I get the message:
F:\(mypath)\myproject-build-desktop\release\myproject.exe exited with code -1073741510
I've found this thread:
http://www.qtcentre.org/threads/3620...-order-of-code
but it does not seem to work for me or I'm not using it nice.
So at last the question is:
How to finish a qt console application correctly?
In the future it has to happen at specific eventy, most likely at a keyboard press, now how to achieve that? (I've seen that once somewhere, but I cannot find it anymore.)
Szilvi
Re: simple console application does ot finish
With exec() you start an event loop you have to quit using quit() ;) for your application you can simply write
Re: simple console application does ot finish
Yes, I see for this very simple application return 0 should work. The question is how to use these exec-quit properly? If the main ends with the line "return a.exec();" then where should the quit function be called? The default code that is generated by the creator is just this:
Code:
#include <QtCore/QCoreApplication>
int main(int argc, char *argv[])
{
return a.exec();
}
As I guess (because everybody says "use quit") this assumes the programmer will add the a.quit() somewhere - but where?
Re: simple console application does ot finish
As soon as you create a widget and show it, Qt will handle it. Otherwise you have to quit the (empty) gui loop.
Re: simple console application does ot finish
This application will end after 5 seconds :
Code:
#include <QtCore/QCoreApplication>
int main(int argc, char *argv[])
{
QTimer::singleShot(5000,
&a,
SLOT(quit
()));
return a.exec();
}