Converting a simple folder to shared folder in Qt C++
I just made a program in Qt that creates a folder in a specific diretory.
the code is:
QDir directory;
directory.mkdir("Sample")开发者_运维知识库;
my problem is how could i convert the folder to a shared folder using Qt codes?
Or is there a way to create a shared folder using Qt??
You can share a directory using NetShareAdd
. As far as I know, Qt doesn't provide anything with the same basic capability as NetShareAdd
.
Edit: here's a quite bit of demo code:
#include <windows.h>
#include <lm.h>
int main() {
SHARE_INFO_2 info = {0};
info.shi2_netname = L"test_share";
info.shi2_type = STYPE_DISKTREE;
info.shi2_permissions = ACCESS_ALL;
info.shi2_max_uses = -1;
info.shi2_path = L"C:\\a\\b\\c";
NetShareAdd(NULL, 2, (BYTE *)&info, NULL);
return 0;
}
Note that NetShareAdd (like most of the Net* functions) is only available in a "wide" version that uses wide character strings.
This seems like it would be operating system dependent; Qt's abstraction of the OS-native directory functions isn't likely to be concerned with such a thing.
You'll probably want to look into your OS' specific methods for changing the "shared" status of a directory. On Windows, this might involve using WMI.
精彩评论