PDA

View Full Version : error in QTextStream cout(stdout)



kaushik_acharya
7th April 2009, 12:32
Hi,
I am getting error in
QTextStream cout(stdout);

Though its getting complied but giving error while executing.

http://cartan.cas.suffolk.edu/oopdocbook/opensource/qtfirstapp.html

Can anyone help me how to correct it?

Regards and Thanks,
Kaushik

calhal
7th April 2009, 17:18
If you want someone to help you, provide more details. What's the error message? We can't just guess it.

kaushik_acharya
8th April 2009, 04:08
Hi,
First of all sorry for giving incomplete info about the error in my previous post.

I am getting this error:

"Unhandled exception at 0x7c918fea in qt_test.exe: 0xC0000005: Access violation writing location 0x00000010."

when it reaches the line:
QTextStream cout(stdout);

and it stops in a file called _file.c
in this line:
EnterCriticalSection( &(((_FILEX *)pf)->lock) );
inside the function
void __cdecl _lock_file

kaushik_acharya
9th April 2009, 10:47
Hi,
I had copied this code from the online book as it is. Has anyone tried running this code?

Regards,
Kaushik

ComaWhite
9th April 2009, 11:16
Works for me in Linux

rishiraj
9th April 2009, 11:23
Hi,
the code's working fine in Linux.Am using Qt 4.4.3 on Fedora.
Better to put the code here,then more people are likely to test it out and tell you if they get any errors or can make sense of the errors you got.

fac1.cpp


#include <QtGui>

int main (int argc, char* argv[])
{
QApplication app(argc, argv);
QTextStream cout(stdout);

// Declarations of variables
int answer = 0;

do {
// local variables to the loop:
int factArg = 0;
int fact(1);
factArg = QInputDialog::getInteger(0, "Factorial Calculator",
"Factorial of:", 1);
cout << "User entered: " << factArg << endl;
int i=2;
while (i <= factArg) {
fact = fact * i;
++i;
}
QString response = QString("The factorial of %1 is %2.\n%3")
.arg(factArg).arg(fact)
.arg("Do you want to compute another factorial?");
answer = QMessageBox::question(0, "Play again?", response,QMessageBox::Yes | QMessageBox::No);
}
while (answer == QMessageBox::Yes);
return EXIT_SUCCESS;
}


fac1.pro


TEMPLATE = app
SOURCES += fac1.cpp

rishiraj
9th April 2009, 11:47
http://lists.trolltech.com/qt-interest/2003-06/thread00855-0.html
...check out this thread.It's a bit similar to your query and might give you some idea.
HTH.

kaushik_acharya
9th April 2009, 13:24
@rishiraj,
This webpage tells about using the visual studio debugger. I am using that and that's how I pointed out the error.

The program is running if i use std::cout instead of QTextStream cout
Is this some problem with visual studio?

Regards,
Kaushik