PDA

View Full Version : Change File Attributes



Arshia Aghaei
15th July 2015, 19:42
How to change the file attributes using Qt ?

ChrisW67
15th July 2015, 21:35
What attributes? QFile::setPermissions() can manipulate some permissions depending on OS.

Arshia Aghaei
16th July 2015, 19:38
What attributes? QFile::setPermissions() can manipulate some permissions depending on OS.

System , ReadOnly , Hidden , ...

ChrisW67
18th July 2015, 02:34
Read-only is probably handled by QFile. The others you are talking about are non-portable Windows-only things and you need to use the Windows API.
https://msdn.microsoft.com/en-us/library/aa365535%28VS.85%29.aspx

Arshia Aghaei
18th July 2015, 10:21
Read-only is probably handled by QFile. The others you are talking about are non-portable Windows-only things and you need to use the Windows API.
https://msdn.microsoft.com/en-us/library/aa365535%28VS.85%29.aspx

I have problems understanding DWORD & LPCTSTR ...
What are those classes (or structs) getting for their value??

ChrisW67
19th July 2015, 06:25
They get whatever value you give them ;)

DWORD = 32-bit integer. The parameter value is made as a bitwise OR of the desired attribute values from API docs.
LPCTSTR = Long Pointer to a Const TCHAR STRing (http://programmers.stackexchange.com/questions/194764/what-is-lpctstr). The value is the file name as, in this case, a const wchar_t*. You can get one of these from a QString using the utf16() or toWCharArray() functions.

Arshia Aghaei
21st July 2015, 19:44
They get whatever value you give them ;)

DWORD = 32-bit integer. The parameter value is made as a bitwise OR of the desired attribute values from API docs.
LPCTSTR = Long Pointer to a Const TCHAR STRing (http://programmers.stackexchange.com/questions/194764/what-is-lpctstr). The value is the file name as, in this case, a const wchar_t*. You can get one of these from a QString using the utf16() or toWCharArray() functions.

A question then , why API programmers didn't make a typedef int DWORD & typedef const wchar* LPCTSTR ??
Aren't they equal ??
What is HWND then ??

ChrisW67
21st July 2015, 22:04
You would have to ask the original Windows programmers. I suspect it is combination of personal preference/common practice and because typedef did not become standard until until the 1989 ANSI standard (and not reliably available until after that). The first Windows versions would have been constrained to K&R C.

HWND is a handle to a window (it is just a number with no encoded meaning). Look in your Windows header files to find what the macro expands to. A Qt widget can provide an equivalent HWND where one exists: see QWidget::winId()