PDA

View Full Version : properly exiting console application.



pdallair
18th September 2013, 04:05
Already this is pretty stupid. I haven't done C++ in while so I'm expecting a huge face palm moment here. I can't believe I'm making a post. Anw...

So I have this insane complexe, multi layered, client server application that goes something like this :



#include <iostream>

int main()
{
std::cout << "I AM A BONANA!" << std::endl;
return 0;
}


no includes, no nothing. Did you get the sarcasm there?

1. click RUN
2. I giggle
2. I see this message "Press <RETURN> to close this window..." and I'm thinking "Good at least I don't have to _getch() at the end of every console application"
3. Pressed <RETURN>
4. Console closes.
5. QT Environment's application output says : "Cannot obtain a handle to the inferior: The parameter is incorrect."
6. Like any good programer who doesn't know what to do I just find the nearest X to close the tab
7. Pop up window says "Application is still running. Force it to quit?" with a "Force Quit" button and a "Keep Running" button.
7.1. ????????????? WHY YOU NO CLOSED!?

So a added a break-point and launched the debugger. Guess what. I didn't get the application output message or the pop up window!

So I tried :



#include <iostream>
#include <cstdlib>

int main()
{
std::cout << "I AM A BONANA!" << std::endl;
std::exit(0);
}


aaaaaand it's still the same... :(

PLease help. I promissss I'll be your bestest friend!

anda_skoa
18th September 2013, 08:39
There is nothing wrong with your program, either version should exit right after printing the output.

Maybe you accidentally ran the program in the debugger and the debugger had not exited yet?

Cheers,
_

pdallair
18th September 2013, 14:08
I'm pretty sure I'm not using the debugger since I am using ctrl+R to run. I tried it by explicitly clicking the button and it doesn't work either. When I restarted my computer it worked 1 time and then it started doing the same thing. I'll try reinstalling qt tonight and see what happens.

anda_skoa
19th September 2013, 08:11
It is definitely not your program that is at fault.
It has ended otherwise you wouldn't see "Press <RETURN> to close this window..."

Now, whatever creates that window might not have exited. I wouldn't worry about that too much though.

Cheers,
_

pdallair
20th September 2013, 04:20
I went through the trouble of uninstalling, getting the latest version online (again) and reinstalling. Still no change. I tried cleaning before running, deleting the .pro.user file, the folder with the makefile... well basically anything except the code.

I read online that people have had similar problem, they can compile there code with different compilers and run it normally. I found that, under Projects side tab -> run, if I uncheck "Run in terminal" I don't get the error. It's kind of like when I run with the terminal, without the debugger. QTCreator does not realize that when the process is over or something like that.

Kinda makes sens considering the error message I get : "Cannot obtain a handle to the inferior: The parameter is incorrect."

Somewhere, when launching the code with the terminal and expected handler isn't returned or something. I'm just guessing. Anw... could this be a bug?

ChrisW67
20th September 2013, 05:20
7. Pop up window says "Application is still running. Force it to quit?" with a "Force Quit" button and a "Keep Running" button.
7.1. ????????????? WHY YOU NO CLOSED!?

Your application has terminated. The stub program that Qt Creator has run along with your program in order to connect its output with the Windows console window and wait for a key press is still running... it is waiting for you to "Press <RETURN> to close this window...". The process is called qtcreator_stub_process.exe (or the like) and is prominently visible in the console window title bar and task manager.

On my Windows XP box with an ancient Creator the stub process closes cleanly when you press Return. It may be a quirk of your OS version or Creator version that causes it to hang rather than close. In any case, it should not have any negative effect on your application which is long since terminated.

If your program does not require user console input then running without the console window is a viable option: output is visible in the "Application Output" pane in Creator.