You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Saturday, November 19th 2011, 11:30am

Qt editor and console cooperation

Hello,

I would like to ask a question about Qt editor and console cooperation. I tried to use the console for debugging purposes (I know there more elegant ways for debugging) so I would be satisfied with simple input/output support. My question that arouse was why the order is not maintained in this piece of code:

Source code

1
2
3
4
5
	cin >> a;
	cout << "Now executing the program...";
	dialog->show();
	cout << "Program exits...";
	cin >> a;

I mean both messages appear in console before the dialog appears! Why is that? I would suggest that maybe the messages display faster than the dialog but since the program expects user input dialog is not showing until I have inserted both time the value of a.

Any ideas?
I use LInux by the way.

2

Saturday, November 19th 2011, 11:42am

OK I have made some modifications on the code (I figured out that app.exec enters interactive loop).

Source code

1
2
3
4
5
6
	cin >> a;
	cout << "Now executing the program...";
	dialog->show();
	app.exec();
	cin >> a;
	cout << "Program exits...";


But now I don't get why the first message appears AFTER the dialog have exited?

3

Saturday, November 19th 2011, 7:18pm

'writing' to a stream doesnt guarantee that it is flushed. add << std::endl to the end of the line to guarantee that the buffer is flushed.
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

4

Sunday, November 20th 2011, 9:12pm

Thanks that what it. I have forgot about it.