#ifdef Q_OS_WIN
QString startMenuPath = QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation)
.append("/Startup"); //獲取開始菜單的路徑,QStandardPaths是個好東西!
QString checkPath = startMenuPath + "/CLIENT.lnk"; //開始菜單路徑
QFile file(checkPath);
QDir dir(startMenuPath);
if(dir.exists()) //判斷開始菜單路徑是否存在
{
if(!file.exists()) //判斷是否已經創建快捷,不存在則創建
{
//獲取軟件所在路徑,帶文件名
QString application_path = QApplication::applicationFilePath();
//創建快捷
QFile::link(application_path, startMenuPath.append("/").append("CLIENT.lnk"));
}
}
#else
#endif
這個是windows的,win 10,win 7測試通過。試過修改註冊表,但是不知道爲什麼修改註冊表的能自啓,但是不加載背景資源,不知道是不是權限問題,有知道的大神可以在評論留言哦,歡迎指教
PS:如果用修改註冊表方式開機自啓的,要把所有資源都放在QT的資源文件中才能正常讀取,應該是權限問題,如果是配置文件可以寫到AppData的Roaming裏面去,這裏面的文件可以正常讀取。