The thing is simple: Recently, our company is working on Instant Messaging Software, similar to QQ. The software should support common features such as boot. However, during the development of this function, the startup program cannot load skin files normally.
This problem has caused me a headache for a long time. Finally, the problem occurs on the packaged skin file of the program. Because the interface uses QT, skin and other resource files should be centrally managed in the qrc file. However, the resource files of the program are actually outside. The result is that there is no problem with the normal startup program, and the skin file cannot be loaded after the startup.
The following are the solutions I have come up:
Method 1: Modify the qrc file and add all resource files to the qrc file for management. In this way, the problem should be solved. In addition, I found the specific use method of the official style, which is basically the same as what I said.
Method 2: Modify the directory where the program runs. This is not easy to understand. During Windows Startup, although the program is started, the folder where the program is located is not identified, resulting in startup failure to load files such as skin resources. The specific solution is to set the directory of the program in the main function of the program. Please refer to the Code selection section:
1 // obtain the path of the current EXE file 2 STD: String get_app_run_path () 3 {4 char szfilepath [max_path + 1]; 5 getmodulefilenamea (null, szfilepath, max_path ); 6 (strrchr (szfilepath, ('\') [1] = 0; // delete the file name and only obtain the path 7 return STD: string (szfilepath ); 8} 9 bool getcurrentprocessdirectory (STD: wstring & wstrcurrentprocesspath) 10 {11 bool is_success = false; 12 13 do 14 {15 wchar * lpprocesspath = (wchar *) malloc (sizeof (wchar) * m Ax_path); 16 if (lpprocesspath) 17 {18 zeromemory (lpprocesspath, max_path); 19 DWORD nbufferlength = max_path; 20 rows = getcurrentdirectory (nbufferlength, lpprocesspath); 21 rows = lpprocesspath; 22 free (lpprocesspath); 23 lpprocesspath = NULL; 24} 25 26} while (false); 27 28 return is_success; 29} 30 31 int main (INT argc, char ** argv) 32 {33 34 STD: wstring wstrcurrentprocesspath; 35 Getcurrentprocessdirectory (wstrcurrentprocesspath); 36 STD: String strcurrentprocesspath = get_app_run_path (); 37 setcurrentdirectorya (strcurrentprocesspath. c_str (); 38... 39 40 qapplication A (argc, argv); 41 42 qfile file (qstring (".. /qss/gocomui. qss "); 43 file. open (qfile: readonly); 44 qstring stylesheet = qlatin1string (file. readall (); 45 file. close (); 46 47. setstylesheet (stylesheet); 48 49. setstyle (New cproxystyle); // remove the focus virtual box 50 51 52 mainwindow W; 53 W. show (); 54 55... 56 int RT = a.exe C (); 57 Return RT; 58}
Use setcurrentdirectorya (strcurrentprocesspath. c_str (); to complete the setting of the directory where the program is located.
* Note:
Setcurrentdirectory Function
Changes the current directory for the current process.
Reference: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365530%28v=vs.85%29.aspx
Abnormal Phenomenon of QT program startup ---- abnormal display of program skin