Results 1 to 5 of 5

Thread: Quitting a QT app

  1. #1

    Default Quitting a QT app

    I have a class, call it server, which inherits from QTcpServer.

    My main looks like this:

    Qt Code:
    1. int main(int argc, char** argv)
    2. {
    3. QCoreApplication app(argc, argv);
    4. new server();
    5.  
    6. return app.exec()
    7. }
    To copy to clipboard, switch view to plain text mode 

    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.

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    520
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 77 Times in 75 Posts

    Default Re: Quitting a QT app

    Hi, why don't you just create your server object on the stack?
    Qt Code:
    1. server myServerObject;
    To copy to clipboard, switch view to plain text mode 

    Ginsengelf

  3. #3

    Default Re: Quitting a QT app

    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.

  4. #4
    Join Date
    Mar 2008
    Posts
    27
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    1
    Thanked 3 Times in 3 Posts

    Default Re: Quitting a QT app

    Like Ginsengelf said, try creating it on the stack, and don't call delete or deleteLater on the server object in that case.

  5. #5

    Default Re: Quitting a QT app

    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.

Similar Threads

  1. Quitting before the QApplication::exec()
    By jsmax in forum Qt Programming
    Replies: 2
    Last Post: 17th April 2008, 20:19

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.