PDA

View Full Version : Quitting a QT app



Aztral
10th August 2009, 19:32
I have a class, call it server, which inherits from QTcpServer.

My main looks like this:


int main(int argc, char** argv)
{
QCoreApplication app(argc, argv);
new server();

return app.exec()
}

My question is, since server inherits from QTcpServer, how can I get app.exec() to return thus properly calling the destructor for server(). Right now I'm not sure how I can get into the server() destructor and also exit the main QT event loop so that the program will quit.

I can properly delete the server() class with deleteLater() or a few other ways, but doing so doesn't terminate the program, I think because I'm still in the main event loop.

Thanks a lot.

Ginsengelf
11th August 2009, 06:53
Hi, why don't you just create your server object on the stack?

server myServerObject;

Ginsengelf

Aztral
20th August 2009, 20:11
Sorry I got busy with a different problem and forgot to get back here!

Anyways, when I do that I get a rather large error:

*** glibc detected *** ./exename: free(): invalid pointer: 0xbf88ed6c ***

As I understand it this means I'm trying to delete something I didn't new. I simply cannot find where this might be happening. I have commented out every delete in my code and still the error occurs.

It has to be happening in my deleteLater() call that I call when I want the program to exit, but I'm not sure why that would be happening either.

profoX
21st August 2009, 09:46
Like Ginsengelf said, try creating it on the stack, and don't call delete or deleteLater on the server object in that case.

Aztral
21st August 2009, 19:09
Then how do I get out of the main loop? Right now I can only exit the program via Control-C. Doesn't main have to return for objects on the stack to be removed (since it's being put on the stack in main)? I'm never reaching that return statement because I'm in a QCoreApplication.exec() loop that I'm never exiting. I guess my question is how do I get out of that loop nicely.