Qt Windows下开机自动启动自己的程序

源地址:http://blog.csdn.net/chrisfxs/article/details/13279491

[cpp] view plain copy
 
  1. void Widget::Readregedit()  
  2. {  
  3.     QString path;  
  4.     QDir dir;  
  5.     path=dir.currentPath();//在QtCreator中点击运行的话地址是工程地址,想要获得应用地址就点击文档中的应用程序(.exe文件)  
  6.     QString sApp = path + "/RemoveFiles.exe";//我的程序名称  
  7.     sApp.replace("/","\");  
  8.     qDebug()<<sApp;  
  9.     QSettings *reg=new QSettings("HKEY_LOCAL_MACHINE",QSettings::NativeFormat);  
  10.     //开机自动运行  
  11.     reg->setValue("SOFTWARE/Microsoft/Windows/CurrentVersion/Run/RemoveFiles.exe",QVariant(sApp));  
  12.   
  13. }  
[cpp] view plain copy
 
  1.   

如果在QtCreator内执行的话,因为获取的当前地址是项目目录,所以路径会不对

所以如果要进行测试也要到目录下的应用文件(如我的:RemoveFiles.exe)

 
原文地址:https://www.cnblogs.com/lanye/p/5363601.html