当前位置: 首页 > news >正文

Qt在Win,Mac和Linux的开机自启设置

Windows

Windows 使用注册表来管理开机自启的应用程序。

void runWithSystem(const QString& name, const QString& path, bool autoRun) {QSetting reg("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", QSetting::NativeFormat);reg.setValue(name, autoRun ? path : "");
}

Linux

Linux 使用 ~/.config/autostart/*.desktop 来管理开机自启的应用程序。

void runWithSystem(const QString& name, const QString& path, bool autoRun) {QString desktopFilePath = QStandarPaths::writableLocation(QStandardPaths::HomeLocation) + "/.config/autostart" + name + ".desktop";if (autoRun) {QFile file(desktopFilePath);if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {QTextStream out(&file);out << "[Desktop Entry]\n"<< "Type=Application\n"<< "Name=" << name << "\n"<< "Exec=" << path << "\n"<< "X-GNOME-Autostart-enabled=true";file.close();}}else {QFile::remove(desktopFilePath);}
}

Macos

Macos 采用 launchd 来管理启动项。

void runWithSystem(const QString& name, const QString& path, bool autoRun) {QString plistPath = QStandardPaths::writableLocation(QStandards::HomeLocation) + "/Library/LaunchAgents/" + name + ".plist";if (autoRun) {QFile file(plistPath);if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {QTextStream out(&file);out << "<?xml version\"1.0\" encoding=\"UTF-8\"?>\n""!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\"\n""	\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n""<plist version=\"1.0\">\n""<dict>\n""	<key>Label</key>\n""	<string>" << name << "</string>\n""	<key>ProgramArguments</key>\n""	<array>\n""		<string>" << path << "</string>\n""	</array>\n""	<key>RunAtLoad</key>\n""	<true/>\n""</dict>\n""</plist>";file.close();}}else {QFile::remove(plistPatch);}
}

资料参考:https://github.com/0voice

http://www.lryc.cn/news/462607.html

相关文章:

  • spring boot热部署
  • 网关与蓝牙网关有什么不同之处?
  • JAVA计算双十一多产品实付款优惠券的省钱方案
  • 零售行业的数字化营销转型之路
  • js的for in 和 for of的详解
  • 前端工具函数库
  • Java程序设计:Spring boot(4)——Freemarker Thymeleaf视图技术集成
  • JavaScript 第19章:Web Storage
  • [山河2024] week2
  • 无限可能LangChain——开启大模型世界
  • URL路径以及Tomcat本身引入的jar包会导致的 SpringMVC项目 404问题、Tomcat调试日志的开启及总结
  • 如何引起Java中的System.in.read()函数的异常
  • 深入理解Flutter鸿蒙next版本 中的Widget继承:使用extends获取数据与父类约束
  • Loss:Focal Loss for Dense Object Detection
  • Unity3D中Excel表格的数据处理模块详解
  • 【python】OpenCV—Fun Mirrors
  • QT IEEE754 16进制浮点数据转成10进制
  • 无人机+视频推流直播EasyCVR视频汇聚/EasyDSS平台在森林防护巡检中的解决方案
  • Rancher—多集群Kubernetes管理平台
  • 使用多IP香港站群服务器对网站管理seo优化提升排名有益处
  • 网管平台(基础篇):网管系统的重要性
  • Ubuntu20.04下安装多CUDA版本,以及后续切换卸载
  • 图像处理高频面试题及答案
  • 尤雨溪都打赏的虚拟列表组件,到底有多强
  • FrameWork使用EfCore数据库映射举例
  • 汽车与航空领域的功能安全对比:ISO 26262-6 与 DO-178C 的差异浅析
  • linux命令之lspci用法
  • 虚幻闪烁灯光材质
  • UNION ALL函数用法
  • JavaWeb合集14-WebSocket