PDA

View Full Version : Converting a QString to a LPCTSTR?



dobedidoo
3rd December 2009, 14:12
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

dobedidoo
3rd December 2009, 14:41
Ok, I finally made it myself, using the following:

SetFileAttributes((LPCTSTR)fileName.utf16(), FILE_ATTRIBUTE_HIDDEN);
/Urban

squidge
3rd December 2009, 19:01
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.

dobedidoo
7th December 2009, 14:27
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.