DIANIUX INNOVA SL

Main Loop Watch Dog Timer for Qt & QML

When the main loop freezes, this component can kill or restart the current application, just by adding two lines of code.

You can also use the application restart function, for a complete restart of your application.

See in action (video)

Demo in Windows 10

How it works:

  • A timer activated by the main loop triggers watch function every 250 ms.
  • Another timer, triggered by a QThread, checks the status of whatchdog status every 250ms.
  • This function should not affect the performance of the application.
  • In case the app is suspended, the watchdog timer function restarts.
  • When the watchdog timer is activated, the application aborts its execution or restarts (configurable)

Usage:

create object in main function, just before main loop exec:

mainLoopWdt wdt(true,2000, 5000,0, &app);
wdt.startWdt();
return app.exec();

Tested OS:

  • Ubuntu 20.04
  • MacOS Big Sur
  • Windows 10

Tested main loop locks:

  • QML js infinite loop
  • C++ infinite loop
  • C++ mutex double lock

Restart estrategy

  • Windows : QProcess::startDetached + std::exit (application arguments are kept)
  • Linux & macOs : exec (application arguments are kept)

Delayed restart estrategy

  • Windows : cmd.exe
  • Linux & MacOs : bash

See also

Qt LPGL App Template (create a 100 % compliant desktop/mobile Qt application using LGPLv3 libraries): https://marketplace.qt.io/products/qt-lgpl-app-template

About

Miguel Angel Pons, Dianiux Innova SL https://www.dianiuxinnova.com qtmarketplace@dianiuxinnova.com

By clicking button above, I agree Marketplace user terms and conditions

Details
Version:
1.0.0
Publisher:
Dianiux Innova S.L.
Contact:
Support
Copyright:
Dianiux Innova S.L.
License:
LGPL-3.0-or-later
Created at:
2021-01-18
Updated at:
2021-01-18
Platforms:
macOS
Windows
Linux
Supported Qt versions:
5.9-or-later
Support:
qtmarketplace@dianiuxinnova.com
Source repository:
https://github.com/mapons/QtMainLoopWDT