事情很简单:最近公司项目在做即时通讯软件,类似QQ。该软件应该支持开机启动这样的常用功能。但是实际上开发该功能的时候碰到了个问题:开机启动程序无法正常加载皮肤文件。

这个问题让我头疼了很久啊。最终确定问题出现在程序的打包皮肤文件上。因为界面使用的是qt所以,皮肤等资源文件都是应该放在qrc文件中进行统一管理的。但是实际上该程序的资源文件却都是在外面的。这样的结果就是正常启动程序没有问题,开机启动就会加载不上皮肤文件。

下面就是我想到的解决方法:

方法一:修改qrc文件,将所有的资源文件都添加到qrc文件中进行管理。这样问题就应该能够解决。另外我找到了官方的style的具体使用方法,具体使用方式和我说的基本一致。

方法二(我师父想出来的):修改程序运行时的所在目录。这个不太好理解。大概是windows启动的时候,程序虽然启动了,但是程序所在的文件夹却没有被识别,导致开机启动无法正常加载皮肤资源的等文件。具体解决办法就是在程序的main函数中设置程序所在目录。请看代码选段:

 //获取当前exe文件所在路径
std::string get_app_run_path()
{
char szFilePath[MAX_PATH + ];
GetModuleFileNameA(NULL, szFilePath, MAX_PATH);
(strrchr(szFilePath, ('\\')))[] = ;//删除文件名,只获得路径
return std::string(szFilePath);
}
bool GetCurrentProcessDirectory(std::wstring &wstrCurrentProcessPath)
{
bool is_success = false; do
{
WCHAR *lpProcessPath = (WCHAR* )malloc(sizeof(WCHAR)*MAX_PATH);
if (lpProcessPath)
{
ZeroMemory(lpProcessPath, MAX_PATH);
DWORD nBufferLength = MAX_PATH;
is_success = GetCurrentDirectory(nBufferLength, lpProcessPath);
wstrCurrentProcessPath = lpProcessPath;
free(lpProcessPath);
lpProcessPath = NULL;
} } while (false); return is_success;
} int main(int argc,char**argv)
{ std::wstring wstrCurrentProcessPath;
GetCurrentProcessDirectory(wstrCurrentProcessPath);
std::string strCurrentProcessPath = get_app_run_path();
SetCurrentDirectoryA(strCurrentProcessPath.c_str() );
。。。 QApplication a(argc,argv); QFile file(QString( "../qss/gocomUi.qss") );
file.open( QFile::ReadOnly );
QString styleSheet = QLatin1String( file.readAll() );
file.close(); a.setStyleSheet( styleSheet ); a.setStyle(new CProxyStyle);//去除焦点虚框 mainWindow w;
w.show(); 。。。
int rt = a.exec();
return rt;
}

使用SetCurrentDirectoryA(strCurrentProcessPath.c_str() );就完成了程序所在目录的设置工作。

*注:

SetCurrentDirectory function

Changes the current directory for the current process.

参考:http://msdn.microsoft.com/en-us/library/windows/desktop/aa365530%28v=vs.85%29.aspx

最新文章

  1. PHP 后台定时循环刷新某个页面 屏蔽apache意外停止
  2. SQL Server 父子迭代查询语句,树状查询(转)
  3. 在Toast里面显示图片
  4. VC 项目支撑文件解释
  5. win8商店应用验证,二进制文件是在调试模式下生成的解决方案。
  6. 小米Java程序员第二轮面试10个问题,你是否会被刷掉?
  7. Java中RuntimeException和Exception的区别
  8. ELK学习总结(2-5)elk的版本控制
  9. 【翻译】如何创建Ext JS暗黑主题之二
  10. Ubuntu下useradd与adduser区别
  11. spring5 reactive
  12. image magick 批量转换文件
  13. 读取txt数据存入数据库中
  14. How to use, monitor, and disable transparent hugepages in Red Hat Enterprise Linux 6
  15. 手机访问电脑中部署的tomcat应用
  16. maven安装之后,或者升级之后遇到的问题:could not find or load main class org.codehaus.plexus.class.....
  17. 20179223《Linux内核原理与分析》第七周学习笔记
  18. 用临时用户数据目录启动Chrome,关闭安全检查等(解决Cross origin requests are only supported for HTTP?)
  19. Windows API函数大全一
  20. NOT IN、NOT EXISTS的相关子查询改用LEFT JOIN--sql2000性能优化

热门文章

  1. 51单片机产生1Hz-5kHz可调占空比方波
  2. Hadoop版Helloworld之wordcount运行示例
  3. 【JAVA - SSM】之MyBatis输出映射
  4. iOS开发总结-UITableView 自定义cell和动态计算cell的高度
  5. Rsync同步工具安装文档
  6. Android - 封装Fragment不依赖于Activity
  7. Android注解支持(Support Annotations)
  8. Struck: Structrued Output Tracking with Kernels 论文笔记
  9. NETBSD-DTARCE
  10. activity-intent-startActivity-startActivityResult