0

我在Mac OS&上工作Qt,我想复制文件(使用自制功能),/Library/Frameworks但每次复制都失败。问题来自识别,但我不知道如何解决它。

这是我的复制功能,在复制到家时可以完美地工作(例如)

void copyFolder(QString sourceFolder, QString destFolder)
{
    QDir sourceDir(sourceFolder);
    if(!sourceDir.exists())
        return;
    QDir destDir(destFolder);
    if(!destDir.exists())
    {
        if(destDir.mkdir(destFolder))
        {
            QStringList files = sourceDir.entryList(QDir::Files);
            for(int i = 0; i< files.count(); i++)
            {
                QString srcName = sourceFolder + "/" + files[i];
                QString destName = destFolder + "/" + files[i];
                QFile::copy(srcName, destName);
            }
            files.clear();
            files = sourceDir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot);
            for(int i = 0; i< files.count(); i++)
            {
                QString srcName = sourceFolder + "/" + files[i];
                QString destName = destFolder + "/" + files[i];
                copyFolder(srcName, destName);
            }
        }
        else
        {
            qDebug() << "There's a problem while creating : " + destFolder;
        }
    }

}
4

1 回答 1

1

As the problem you have is with permissions, you can solve this, but not with Qt alone.

Apple's solution, for security, is that when an application is required to access something with elevated privileges (in this case, the Frameworks folder), a second helper application is required that is spawned via launchd and it is that 2nd application that is given the privileges to perform the task.

There is an example of this called SMJobBless, which you can see here: -

However, you'll notice that it is written in Objective-C. If that's new to you, just be aware that it's only an extension of C, so you should be able to pick up the new parts reasonably easily; enough to modify the SMJobBless example for your needs.

With little documentation available for SMJobBless, there's more about it here

于 2013-06-17T13:31:57.380 回答