PDA

View Full Version : Odd Results in Application Output Pane on simple C++ app



t4w2
24th September 2013, 20:20
Running Qt Creator 2.7.0 Based on Qt 5.0.2 (32 bit).


1. Start Qt, File --> New File or Project --> Non-Qt Project --> Plain C++ Project --> Choose

Name: t1
Create in: E:\test\
Use as default project location: left unchecked

Hit Next.

2. Kit Selection

(checked) Desktop Qt 5.0.2 MinGw 32bit
(checked) E:\test\build-t1-Desktop_Qt_5_0_2_MinGW_32bit-Debug
(checked) E:\test\build-t1-Desktop_Qt_5_0_2_MinGW_32bit-Release

Hit Next.

3. Project Management

Add to version control: <None>

Hit Finish


4. Select "Projects" button --> Run tab --> Uncheck "Run in terminal"

5. Edit button. Update main.cpp to the following:


#include <iostream>

using namespace std;

int main()
{
int i;

for (i=1; i<52; i++)
{
cout << i << endl;
}
cout << endl;
return 0;
}

t1.pro file is left to default values:


TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt

SOURCES += main.cpp


6. Hit RUN (Ctrl+R)

Results (Application Output Pane):


Starting E:\test\build-t1-Desktop_Qt_5_0_2_MinGW_32bit-Debug\debug\t1...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
E:\test\build-t1-Desktop_Qt_5_0_2_MinGW_32bit-Debug\debug\t1 exited with code 0

Hit RUN again (Ctrl+r)

Results (Application Output Pane):


Starting E:\test\build-t1-Desktop_Qt_5_0_2_MinGW_32bit-Debug\debug\t1...
1
E:\test\build-t1-Desktop_Qt_5_0_2_MinGW_32bit-Debug\debug\t1 exited with code 0

Hit DEBUG (F5)

Results (Application Output Pane):


Debugging starts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

Debugging has finished

What the heck is going on here? Every time I run this with "RUN Ctrl+R" I get different results, but I get the expected (and reliable) results in DEBUG (F5)?

aamer4yu
25th September 2013, 10:09
Not sure what machine you are running it on.

Its showing proper result with printing till 51 on my machine.. Tried under release and debug builds both.

t4w2
25th September 2013, 14:42
Windows 7 64bit with Intel Xeon E5410.

As in step 2 above, though I compiled with "Desktop Qt 5.0.2 MinGw 32bit."

t4w2
25th September 2013, 20:47
If I change the code slightly, this appears to work. I'm not sure why, but there must be some kind of glitch with flushing cout on std::endl in Qt Application Panel.

#include <iostream>

using namespace std;

int main()
{
int i;

for (i=1; i<52; i++)
{
cout << i << "\n";
}
cout << endl;
return 0;
}