PDA

View Full Version : Program compiles but does not run - please help!



Gaara
9th October 2010, 14:21
My program compiles with the following message (when I press Run):

"Running build steps for project example1-11...
Starting: C:/Qt/2009.03/qt/bin/qmake.exe C:/Users/Gaara/Documents/example1-11/example1-11.pro -spec win32-g++ -r
Exited with code 0.
Starting: C:/Qt/2009.03/mingw/bin/mingw32-make.exe -w
mingw32-make: Entering directory `C:/Users/Gaara/Documents/example1-11'
C:/Qt/2009.03/mingw/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `C:/Users/Gaara/Documents/example1-11'
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\..\..\Qt\2009.03\qt\include\QtCore" -I"..\..\..\..\Qt\2009.03\qt\include\QtGui" -I"..\..\..\..\Qt\2009.03\qt\include" -I"..\..\..\..\Qt\2009.03\qt\include\ActiveQt" -I"debug" -I"..\..\..\..\Qt\2009.03\qt\mkspecs\win32-g++" -o debug\main.o main.cpp
g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows -o debug\example1-11.exe debug/main.o -L"c:\Qt\2009.03\qt\lib" -lmingw32 -lqtmaind -lQtGuid4 -lQtCored4
mingw32-make[1]: Leaving directory `C:/Users/Gaara/Documents/example1-11'
mingw32-make: Leaving directory `C:/Users/Gaara/Documents/example1-11'
Exited with code 0."

but the actual program does not run, please let me know if you require more information, you help with be greatly appreciated - thanks.

Lykurg
9th October 2010, 14:26
It seems to run and successfully returns with no error (=0). So how does your main function look like? Do you start the event loop?

Zlatomir
9th October 2010, 15:47
This usually happens when you create a console application on windows and forget about the CONFIG += console in project file, so make sure it's not this case, and give us more information on what application you make.

Gaara
9th October 2010, 19:35
The program code looks as follows:




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

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

int main() {
QString str, newstr;
QTextStream strbuf(&str); /*strbuf is initialized with the address of str.*/

int lucky = 7;
float pi = 3.14;
double e = 2.71;

cout << "An in-memory stream" << endl;
strbuf << "luckynumber: " << lucky << endl
<< "pi: " << pi << endl
<< "e: " << e << endl;

cout << str;

QFile data("mydata");
data.open(QIODevice::WriteOnly);
QTextStream out(&data);
out << str ;
data.close();

cout << "Read data from the file - watch for errors." << endl;
if(data.open(QIODevice::ReadOnly)) { /*Make sure the file exists before
attempting to read.*/
QTextStream in(&data);
int lucky2;
in >> newstr >> lucky2;
if (lucky != lucky2)
cerr << "ERROR! wrong " << newstr << lucky2 << endl;
else
cout << newstr << " OK" << endl;

float pi2;
in >> newstr >> pi2;
if (pi2 != pi)
cerr << "ERROR! Wrong " << newstr << pi2 << endl;
else
cout << newstr << " OK" << endl;

double e2;
in >> newstr >> e2;
if (e2 != e)
cerr << "ERROR: Wrong " << newstr << e2 << endl;
else
cout << newstr << " OK" << endl;
data.close();
}

cout << "Read from file line-by-line" << endl;
if(data.open(QIODevice::ReadOnly)) {
QTextStream in(&data);
while (not in.atEnd()) {
newstr = in.readLine();
cout << newstr << endl;
}
data.close();
}
return 0;
}


Thank you for the responses.

Lykurg
9th October 2010, 20:17
As said: it runs perfect. what do you expect to "see"? have a look at the console output. (and instead of using cout you can use e.g. qWarning() )

Zlatomir
9th October 2010, 23:42
I see you are using windows, on this OS you need the following line:

CONFIG += console
in your project file (the .pro file) whenever you are creating console application
After you add that line in your .pro file, rebuild your application and it should open the console as expected.

Gaara
11th October 2010, 13:16
sorted, thanks allot.

I added: CONFIG += console
as advised and
In Projects mode, chose the Run Settings tab and checked the "Run in Terminal".