作者:小 琛
歡迎轉(zhuǎn)載,請標(biāo)明出處文章來源:http://www.zghlxwxcb.cn/news/detail-556978.html
實現(xiàn)功能:傳入一個文件的完整路徑,實現(xiàn)運行代碼后,該文件被復(fù)制——相當(dāng)于鼠標(biāo)右鍵,復(fù)制功能。文章來源地址http://www.zghlxwxcb.cn/news/detail-556978.html
bool copyFilePath(const QString& filePath) {
bool ret = false;
if (isFileExists(filePath)) {
// create a clipboard and set the MIME type to a file path list
QClipboard* clipboard = QApplication::clipboard();
QMimeData* mimeData = new QMimeData();
QList<QUrl> urls;
urls.append(QUrl::fromLocalFile(filePath));
mimeData->setUrls(urls);
clipboard->setMimeData(mimeData);
// do copy
QProcess* process = new QProcess(this);
process->start("cmd.exe", QStringList() << "/c"
<< "xcopy"
<< "/y"
<< "/q"
<< "\"" + filePath + "\""
<< "\"%temp%\"");
// process->waitForFinished();//阻塞等待
ret = true;
}
return ret;
}
到了這里,關(guān)于編程實現(xiàn)對某個文件的復(fù)制功能——右鍵可粘貼的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!