Converting a QString to a LPCTSTR?
I want to use the Windows 'SetFileAttributes' function for hiding a file (since Qt 4.4.3 has no function for hiding files, as I know of!?).
The name of the file I want to hide is stored in a QString.
My problem is that the 'SetFileAttributes' function takes the file name as an argument of type 'LPCTSTR', so how on earth to I send the file name in the QString as an 'LPCTSTR' to the 'SetFileAttributes' function?
I use Qt 4.4.3 and MSVC 2005.
Thanks for all help!
Urban
Re: Converting a QString to a LPCTSTR?
Ok, I finally made it myself, using the following:
Code:
SetFileAttributes((LPCTSTR)fileName.utf16(), FILE_ATTRIBUTE_HIDDEN);
/Urban
Re: Converting a QString to a LPCTSTR?
Are you sure that works? The abbreviation LPCTSTR means a pointer to a c-style constant string, or const char *, and your returning a WCHAR, which is an array of unsigned shorts.
Re: Converting a QString to a LPCTSTR?
Well, let's just say I tried, and tried, and tried even more. What I wrote at least works fine for all the tests I've done, but if anyone has a better idea I'd be very glad to learn.