As is known, QSettings class allows you to store application settings in the registry of Windows . Due to this possibility, and a good knowledge of your Windows registry, you can add an application to autostart, or remove it from there, through, for example, the application settings dialog. You can use the checkbox, and if it is marked, then by clicking on the button in the confirmation dialog box to write an application to the startup, otherwise, remove it from the startup.
In any case, it all comes down to the two actions.
Write an application to autostart
#ifdef Q_OS_WIN32 QSettings settings("HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat); settings.setValue(APPLICATION_NAME, QDir::toNativeSeparators(QCoreApplication::applicationFilePath())); settings.sync(); #endif
To delete an application from the startup
#ifdef Q_OS_WIN32 QSettings settings("HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat); settings.remove(APPLICATION_NAME); #endif
Naturally, we wrap the entire code in the environment for the compiler, because the code is platform-dependent in this case.