qt程序开机自启动

1.代码

// 开机自启动
void AutoStart()
{
    QSettings* settings = new QSettings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat);
    auto application_name = QApplication::applicationName();
    auto path = settings->value(application_name).toString();
    QString appPath = QApplication::applicationFilePath();
    QString newPath = QDir::toNativeSeparators(appPath);
    if (path != newPath) {
        settings->setValue(application_name, newPath);
    }
    delete settings;
}

你可能感兴趣的:(qt程序开机自启动)