PDA

View Full Version : Application stops working unexpectedly



baluk
19th November 2010, 09:14
Hi,

in my app I am reading a file name by opening a QFileDialog and save the filename to a string variable. And then I check for the variable in question of filename returned. I am doing this with an If statement and showing message box if the variable is empty. But when I get to the If statement my program showing a message that "example.exe has stopped working unexpectedly". here is my code



void MainWindow::getFilename()
{
QMessageBox msgbox;
msgbox.setText("Please select the file");
filepath = QFileDialog::getOpenFileName(this, tr("Open File"),"/home",tr("Text files(*.txt)"));
if(filepath.isEmpty())
msgbox.exec();
}



I would be grateful for any solution.

Thank You,
Baluk

high_flyer
19th November 2010, 09:37
run the application in a debugger, and see exactly where it crashes, you will probably also see why (NULL pointer or similar)

baluk
19th November 2010, 10:17
oke. I run the app in debug mode and I receive a message that

The inferior stopped because it received a signal from operating system, SignalName : SIGSEGV SiganMeaning:Sigmentation fault.
I have removed the above function from my app and I still get this error when I try to close the app by clicking on the "Close" menu item on the top of the window. Can you tell me why is it because if it is a common error.

high_flyer
19th November 2010, 10:42
No - run the app in the debugger - this means you run it from within the debugger - not by double clicking on the exe.
The code you posted should not crash, the problem is somewhere else in your app.

baluk
19th November 2010, 11:56
oke. But I run the program from the Qt creator not by clicking the exe file. Unfortunately I have no idea where to look for when debugger shows me some output when I get the error message.

FelixB
19th November 2010, 11:59
can you post more code?

baluk
19th November 2010, 12:27
My app has 200 lines of code. I don't know from which portion the error is. But my program exited with code -1073741819.

wysota
19th November 2010, 12:40
oke. I run the app in debug mode and I receive a message that
.
I have removed the above function from my app and I still get this error when I try to close the app by clicking on the "Close" menu item on the top of the window. Can you tell me why is it because if it is a common error.
When you get this, Creator should show you where the crash occured. There should be a backtrace available so that you can see where it crashes. And forseeing your next question - no, we will not teach you here what backtrace is. If you are a programmer you should either already know that or be able to find it out yourself.

baluk
19th November 2010, 12:56
Yes I see the backtrace when I run in the debug mode. The applications crashes at QObjectPrivate::deleteChilderen() function in the qobject.cpp file at line 1978. Can you tell me what it means.

high_flyer
19th November 2010, 13:00
Go back in the trace to the first line you can see which is from your code.

baluk
19th November 2010, 13:14
From my code I get the error next after the destructor statement
delete ui; . When I press F10 from the statement, I get the segmentation fault message.

high_flyer
19th November 2010, 13:36
you probably forgot to do ui = new <YourUIWidget>;

wysota
19th November 2010, 13:53
Post the whole backtrace.

baluk
19th November 2010, 14:09
Here I am attaching the image showing the debugger output. I can't see the option to copy the output. And I see the message
Lowest section in C:\Windows\system32\normaliz.dll is .text at 00401000 in the console after stopping the debugger.

wysota
20th November 2010, 00:31
So the crash happens when you are closing the application? Does the program work correctly until then?

baluk
20th November 2010, 11:51
yes exactly. the crash happens only when closing the app. Until then every thing works fine. Before It was running fine but when I added the above function my app started crashing. So I then removed the function but still the crash happens when closing the application.

wysota
20th November 2010, 15:06
My guess is that you have a double delete somewhere. You are deleting some object explicitly and then MainWindow destructor deletes it again.