最近在开发qt在windows下的跨平台开发,涉及到windows的所有版本,发布的静态版本,目前在windows xp(32)上运行没有问题,但是有个客户的电脑是win7的土耳其系统,在其电脑上运行程序,发现无法运行,出现两个致命问题:
(1)无法添加注册表,因为我要实现开机自动启动功能,我的代码如下:
void MainWindow::Readregedit()
{
#ifdef Q_OS_WIN
//qDebug()<<ui->checkBox_5->isChecked();
QSettings *reg=new QSettings("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft"
"\\Windows\\CurrentVersion\\Run",QSettings::NativeFormat);//开机自动运行
if (Restart_para)
{
QString tmpPath;
tmpPath = QApplication::applicationFilePath();
tmpPath = tmpPath.replace("/","\\",Qt::CaseInsensitive);
reg->setValue("upsmate_en",tmpPath);
}
else
{
reg->setValue("upsmate_en","");
reg->remove("upsmate_en");
}
delete reg;
#endif
这里用了QApplication::applicationFilePath();这个函数读取程序路径。
}
(2)我的程序路径读取不到,我使用的函数是:
path.dir = QApplication::applicationDirPath();
这个问题主要有两种情况,在有的win7系统上,只要不把程序安装在C:\Program Files下就可以运行,而有的win7系统是都不行,,初步估计是函数在win7系统下无法读到程序路径。
现在客户在急等解决方法,希望各位大侠感觉帮忙,跪谢跪谢!
网上搜索方法,有的人说是因为在win7系统下没有管理员权限,可是我在win7下就是以管理员登陆的,另外qt要怎么获取win7的管理员权限?