Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/andreicherniaev/qcoreapplication_quit_example

simpe example How to exit after QCoreApplication::exec()
https://github.com/andreicherniaev/qcoreapplication_quit_example

example qt sigint

Last synced: about 1 month ago
JSON representation

simpe example How to exit after QCoreApplication::exec()

Awesome Lists containing this project

README

        

# QCoreApplication_quit_example
This is simple example How to exit after QCoreApplication::exec()

Run app and after 3 second QCoreApplication_quit_example will close automatically with message "good bye".

To exit from you infinite cycle QCoreApplication::exec()
try this

QTimer::singleShot(1000, this, &rial::closeApp); //if you need process some code in closeApp()
or this

QTimer::singleShot(1000, QCoreApplication::instance(), SLOT(quit())); //if you need quit() only

Also you can use Ctrl+C to exit. If user send Ctrl+C signal QCoreApplication_quit_example will use non-Qt function SigInt_Handler(). It tested on Ubuntu.

# QCoreApplication_quit_SIGINT_example
QCoreApplication_quit_SIGINT_example is more powerfull then QCoreApplication_quit_example. If user send Ctrl+C signal QCoreApplication_quit_SIGINT_example will use Qt non-static method rial::handleSignal(). In this method Qt start QTimer for 3 seconds and after do closeApp(). If user don't press Ctrl+C in console for QCoreApplication_quit_SIGINT_example this app will wating forever.

# How run?
You can run this apps using Qt Creator. You can use external terminal if you need use this way


Qt Creator. Run proj in external terminal


Run proj in external terminal

You can send SIGINT by Ctr+C key. But also you can send SIGINT using Debug mode via GDB console. Before sending "signal 2" don't forget make Pause!


Qt Creator. Debug using gdb creator. Emit signal 2 via gdb console


SIGINT by GDB in Qt Creator