I'm using the MingW32 G++ compiler in the Qt Creator at the moment.
I've ported over working code from CodeBlocks into Qt so I can use Qt's networking features, but the moment I port over the code, it fails to compile with the errors of:
C:\software\Qt\AutoUpload\main.cpp:90: error: cannot convert 'std::__cxx11::string {aka std::__cxx11::basic_string<char>}' to 'LPCWSTR {aka const wchar_t*}' for argument '1' to 'void* FindFirstFileW(LPCWSTR, LPWIN32_FIND_DATAW)'
HANDLE handle = FindFirstFile(dir, &search_data);
The piece of code that gives this error is line 8:
1 vector<string> getFilesInDir(string directory)
2 {
3 vector<string> filenames;
4 string dir = string(directory + "\\*");
5
6 WIN32_FIND_DATA search_data;
7 memset(&search_data, 0, sizeof(WIN32_FIND_DATA));
8 HANDLE handle = FindFirstFile(dir.c_str(), &search_data);
9 while (handle != INVALID_HANDLE_VALUE)
10 {
11 if (FindNextFile(handle, &search_data) == FALSE) break;
12 if (search_data.cFileName == string(".") || search_data.cFileName == string(".."))
13 {
14 cout << "Ignoring..." << endl;
15 continue;
16 }
17 filenames.push_back(search_data.cFileName);
18 cout << search_data.cFileName << endl;
19 }
20
21 FindClose(handle);
22 return filenames;
23 }
Other questions such as ones found here and here state that this is some issue with Unicode encoding that the Windows API uses with the LPCWSTR
type, but this answer is either incomplete or incorrect. My encoding settings with both CodeBlocks and Qt Creator are UTF-8 and not Unicode or any other encoding method.
If this were a Unicode issue, this code would not have compiled in Visual Studio or CodeBlocks, but it is regardless. The ONLY environment it doesn't compile perfectly fine is in Qt.
What is Qt Creator doing that is suddenly making this code non-functional?