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: 6 days ago
JSON representation
simpe example How to exit after QCoreApplication::exec()
- Host: GitHub
- URL: https://github.com/andreicherniaev/qcoreapplication_quit_example
- Owner: AndreiCherniaev
- License: apache-2.0
- Created: 2023-01-13T05:13:47.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-16T17:47:24.000Z (10 months ago)
- Last Synced: 2025-03-26T16:26:26.224Z (3 months ago)
- Topics: example, qt, sigint
- Language: C++
- Homepage:
- Size: 310 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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() onlyAlso 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
![]()
Run proj in external terminalYou 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!
![]()
SIGINT by GDB in Qt Creator