Results 1 to 5 of 5

Thread: simple console application does ot finish

  1. #1
    Join Date
    Nov 2010
    Location
    Budapest, Hungary
    Posts
    125
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default simple console application does ot finish

    Hi,

    I'm creating a console application. I've created it in the Qt Creator with New File or Project (...) and I've changed the main just like this:
    Qt Code:
    1. #include <QtCore/QCoreApplication>
    2. #include <iostream>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QCoreApplication a(argc, argv);
    7.  
    8.  
    9. std::cout << "hello" << std::endl;
    10.  
    11. return a.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

    The only problem around this is that when I run it it does not seem to finish. I have to terminate the program "roughly" by switching off the popping console window or running it from a command promt using Ctrl+C. In the Creator I get the message:
    F:\(mypath)\myproject-build-desktop\release\myproject.exe exited with code -1073741510


    I've found this thread:
    http://www.qtcentre.org/threads/3620...-order-of-code
    but it does not seem to work for me or I'm not using it nice.

    So at last the question is:
    How to finish a qt console application correctly?
    In the future it has to happen at specific eventy, most likely at a keyboard press, now how to achieve that? (I've seen that once somewhere, but I cannot find it anymore.)

    Szilvi
    Szilvi

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: simple console application does ot finish

    With exec() you start an event loop you have to quit using quit() for your application you can simply write
    Qt Code:
    1. return 0;
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Nov 2010
    Location
    Budapest, Hungary
    Posts
    125
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: simple console application does ot finish

    Yes, I see for this very simple application return 0 should work. The question is how to use these exec-quit properly? If the main ends with the line "return a.exec();" then where should the quit function be called? The default code that is generated by the creator is just this:

    Qt Code:
    1. #include <QtCore/QCoreApplication>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QCoreApplication a(argc, argv);
    6.  
    7. return a.exec();
    8. }
    To copy to clipboard, switch view to plain text mode 

    As I guess (because everybody says "use quit") this assumes the programmer will add the a.quit() somewhere - but where?
    Szilvi

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: simple console application does ot finish

    As soon as you create a widget and show it, Qt will handle it. Otherwise you have to quit the (empty) gui loop.

  5. #5
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: simple console application does ot finish

    This application will end after 5 seconds :
    Qt Code:
    1. #include <QtCore/QCoreApplication>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QCoreApplication a(argc, argv);
    6.  
    7. QTimer::singleShot(5000,&a,SLOT(quit()));
    8. return a.exec();
    9. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. about console application
    By jirach_gag in forum Qt Programming
    Replies: 2
    Last Post: 5th January 2012, 11:39
  2. Two threads in a console application
    By msr in forum Qt Programming
    Replies: 3
    Last Post: 30th September 2011, 16:16
  3. qtimer in console application
    By JeanC in forum Newbie
    Replies: 10
    Last Post: 31st March 2011, 15:30
  4. Replies: 2
    Last Post: 21st November 2010, 18:03
  5. Console application suspense
    By TheGrimace in forum Newbie
    Replies: 6
    Last Post: 1st October 2007, 14:52

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.