Results 1 to 4 of 4

Thread: Converting a QString to a LPCTSTR?

  1. #1
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    34
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default 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

  2. #2
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    34
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Converting a QString to a LPCTSTR?

    Ok, I finally made it myself, using the following:
    Qt Code:
    1. SetFileAttributes((LPCTSTR)fileName.utf16(), FILE_ATTRIBUTE_HIDDEN);
    To copy to clipboard, switch view to plain text mode 
    /Urban

  3. #3
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default 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.

  4. #4
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    34
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default 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.

Similar Threads

  1. File rename detection
    By bunjee in forum Qt Programming
    Replies: 6
    Last Post: 23rd July 2009, 15:22
  2. Converting QString to char array
    By srohit24 in forum Qt Programming
    Replies: 3
    Last Post: 22nd July 2009, 18:19
  3. Problem in converting QString to QChar array?
    By KaKa in forum Qt Programming
    Replies: 2
    Last Post: 19th March 2007, 00:38
  4. Convert from iso-8859-1 to... Something else :-)
    By Nyphel in forum Qt Programming
    Replies: 4
    Last Post: 7th March 2007, 17:59
  5. QString to char* not converting
    By DPinLV in forum Qt Programming
    Replies: 17
    Last Post: 6th August 2006, 12:15

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.