本文整理汇总了C++中QFile::copy方法的典型用法代码示例。如果您正苦于以下问题:C++ QFile::copy方法的具体用法?C++ QFile::copy怎么用?C++ QFile::copy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QFile
的用法示例。
在下文中一共展示了QFile::copy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: accept
void ProRataMerge::merge()
{
accept();
// Get the list of files.
for (int i = 0; i < qlwInput->count() ; i++ )
{
QString qsDir = (qlwInput->item( i ))->text();
QDir dir( qsDir );
QString qsBaseName = qsDir.section( '/', -1 );
dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
QFileInfoList list = dir.entryInfoList();
for (int j = 0; j < list.size(); ++j) {
QFileInfo fileInfo = list.at(j);
QString qsNewFile = qsOutputDirectory + "/" + qsBaseName + "_" + fileInfo.fileName();
//QFile::copy( fileInfo.absoluteFilePath(), qsNewFile );
QFile qfInputFile;
qfInputFile.setFileName( fileInfo.absoluteFilePath() );
qfInputFile.copy( qsNewFile );
}
dir.setFilter(QDir::AllDirs | QDir::NoSymLinks);
QFileInfoList qfileDirList = dir.entryInfoList();
QString qsDirList = "";
for (int j = 0; j < qfileDirList.size(); ++j)
{
QFileInfo dirInfo = qfileDirList.at(j);
if ( dirInfo.fileName() == "." || dirInfo.fileName() == ".." )
{
continue;
}
QDir qdCurrentPointer;
QString qsDestDirectory = qsOutputDirectory + "/" + qsBaseName + "_" + dirInfo.fileName();
qdCurrentPointer.mkdir( qsDestDirectory );
QDir sourceDir( dirInfo.absoluteFilePath() );
sourceDir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
QFileInfoList list = sourceDir.entryInfoList();
for (int j = 0; j < list.size(); ++j) {
QFileInfo dirInfo = list.at(j);
QString qsNewFile = qsDestDirectory + "/" + qsBaseName + "_" + dirInfo.fileName();
//QFile::copy( dirInfo.absoluteFilePath(), qsNewFile );
QFile qfInputFile;
qfInputFile.setFileName( dirInfo.absoluteFilePath() );
qfInputFile.copy( qsNewFile );
}
}
//QMessageBox::information(this, "dir list ", qsDirList );
}
}
示例2: writeSettings
void MysqLoader::writeSettings()
{
QFile autostartFile;
LanguageTools language;
QSettings mysqloader_conf(QSettings::NativeFormat,
QSettings::UserScope, APP_NAME);
mysqloader_conf.beginGroup("MySQLoader");
mysqloader_conf.setValue("Autostart",
autostartCheckBox->isChecked());
mysqloader_conf.setValue("Desktop_Icon",
desktopIconCheckBox->isChecked());
mysqloader_conf.setValue("Set_Language",
languageGroup->isChecked());
mysqloader_conf.setValue("languageNiceName",
languageCombo->currentText());
mysqloader_conf.setValue("languageFileName",
fileToNiceName->value(
languageCombo->currentText()));
mysqloader_conf.setValue("Meldung",
showMeldungCheckBox->isChecked());
mysqloader_conf.setValue("Meldung_App",
meldungAppCheckBox->isChecked());
mysqloader_conf.setValue("Zeige_Fenster",
showDialogCheckBox->isChecked());
mysqloader_conf.endGroup();
mysqloader_conf.beginGroup("MySQL_Paths");
mysqloader_conf.setValue("MySQL_PID_FILE",
pidFileEdit->text());
mysqloader_conf.setValue("MySQL_Server",
mysqlEdit->text());
mysqloader_conf.endGroup();
if (autostartCheckBox->isChecked() == true) {
autostartFile.copy("/usr/share/applications/mysqloader.desktop",
QDir::homePath() +
"/.config/autostart/mysqloader.desktop");
} else {
autostartFile.remove(QDir::homePath() +
"/.config/autostart/mysqloader.desktop");
}
if (desktopIconCheckBox->isChecked() == true) {
autostartFile.copy("/usr/share/applications/mysqloader.desktop",
QDir::homePath() +
"/Desktop/mysqloader.desktop");
} else {
autostartFile.remove(QDir::homePath() +
"/Desktop/mysqloader.desktop");
}
}
示例3: loadOBJ
void OBJBaker::loadOBJ() {
if (!QDir().mkpath(_bakedOutputDir)) {
handleError("Failed to create baked OBJ output folder " + _bakedOutputDir);
return;
}
if (!QDir().mkpath(_originalOutputDir)) {
handleError("Failed to create original OBJ output folder " + _originalOutputDir);
return;
}
// check if the OBJ is local or it needs to be downloaded
if (_modelURL.isLocalFile()) {
// loading the local OBJ
QFile localOBJ { _modelURL.toLocalFile() };
qDebug() << "Local file url: " << _modelURL << _modelURL.toString() << _modelURL.toLocalFile() << ", copying to: " << _originalModelFilePath;
if (!localOBJ.exists()) {
handleError("Could not find " + _modelURL.toString());
return;
}
// make a copy in the output folder
if (!_originalOutputDir.isEmpty()) {
qDebug() << "Copying to: " << _originalOutputDir << "/" << _modelURL.fileName();
localOBJ.copy(_originalOutputDir + "/" + _modelURL.fileName());
}
localOBJ.copy(_originalModelFilePath);
// local OBJ is loaded emit signal to trigger its baking
emit OBJLoaded();
} else {
// OBJ is remote, start download
auto& networkAccessManager = NetworkAccessManager::getInstance();
QNetworkRequest networkRequest;
// setup the request to follow re-directs and always hit the network
networkRequest.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
networkRequest.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysNetwork);
networkRequest.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT);
networkRequest.setUrl(_modelURL);
qCDebug(model_baking) << "Downloading" << _modelURL;
auto networkReply = networkAccessManager.get(networkRequest);
connect(networkReply, &QNetworkReply::finished, this, &OBJBaker::handleOBJNetworkReply);
}
}
示例4: preparePatches
void TestAusmt::preparePatches()
{
GET_DIR;
GET_FILES_DIR;
GET_PATCHES_DIR;
// Dump patches
QDir patchesResDir (":/patches/");
foreach (const QString &fileName, patchesResDir.entryList(QDir::Files)) {
QFile file (patchesResDir.absoluteFilePath(fileName));
if (patchesDir.exists(fileName)) {
QVERIFY(QFileInfo(patchesDir.absoluteFilePath(fileName)).isFile());
QVERIFY(patchesDir.remove(fileName));
}
QVERIFY(file.copy(patchesDir.absoluteFilePath(fileName)));
}
foreach (const QString &dirName, patchesResDir.entryList(QDir::Dirs)) {
if (patchesDir.exists(dirName)) {
QVERIFY(QFileInfo(patchesDir.absoluteFilePath(dirName)).isDir());
QDir subDir (patchesDir);
QVERIFY(subDir.cd(dirName));
QVERIFY(subDir.removeRecursively());
}
patchesDir.mkdir(dirName);
QDir patchesSubDir (patchesDir);
QVERIFY(patchesSubDir.cd(dirName));
QDir patchesResSubDir (patchesResDir);
QVERIFY(patchesResSubDir.cd(dirName));
foreach (const QString &fileName, patchesResSubDir.entryList(QDir::Files)) {
QFile file (patchesResSubDir.absoluteFilePath(fileName));
QVERIFY(file.copy(patchesSubDir.absoluteFilePath(fileName)));
}
}
// Update patches
QString makePatchName = patchesDir.absoluteFilePath(MAKE_PATCH_SH);
QFile makePatch (makePatchName);
QVERIFY(makePatch.exists());
QVERIFY(makePatch.setPermissions(QFileDevice::ReadUser | QFileDevice::WriteUser | QFileDevice::ExeUser));
QProcess makePatchProcess;
makePatchProcess.setWorkingDirectory(patchesDir.absolutePath());
makePatchProcess.start(patchesDir.absoluteFilePath(MAKE_PATCH_SH),
QStringList() << filesDir.absolutePath());
makePatchProcess.waitForFinished(-1);
QCOMPARE(makePatchProcess.exitCode(), 0);
}
示例5: relocateImages
/*
* Move the images to the images folder.
*/
bool relocateImages(void)
{
bool status = 1;
QStringList filters;
filters << "*.png";
fileDir[ROOT]->setNameFilters(filters);
QDirIterator iterator(*fileDir[ROOT]);
QFile *file;
QString *name;
while(iterator.hasNext() && status)
{
file = new QFile(iterator.next());
name = new QString(file->fileName());
name->remove(0,
name->lastIndexOf(QString(fileDir[ROOT]->separator()))+1);
status = file->copy(fileDir[IMAGES]->absolutePath() +
fileDir[IMAGES]->separator() + *name);
file->remove();
delete file;
delete name;
}
return status;
}
示例6: prepareSimple
void TestAusmt::prepareSimple()
{
GET_DIR;
GET_VAR_DIR;
GET_FILES_DIR;
if (varDir.exists()) {
QVERIFY(varDir.removeRecursively());
}
if (filesDir.exists()) {
QVERIFY(filesDir.removeRecursively());
}
QVERIFY(QDir::root().mkpath(varDir.absolutePath()));
QVERIFY(QDir::root().mkpath(filesDir.absolutePath()));
QDir filesResDir (":/files");
foreach (const QString &fileName, filesResDir.entryList(QDir::Files)) {
QFile file (filesResDir.absoluteFilePath(fileName));
if (filesDir.exists(fileName)) {
QVERIFY(QFileInfo(filesDir.absoluteFilePath(fileName)).isFile());
QVERIFY(filesDir.remove(fileName));
}
QVERIFY(file.copy(filesDir.absoluteFilePath(fileName)));
QFile destFile (filesDir.absoluteFilePath(fileName));
QVERIFY(destFile.exists());
destFile.setPermissions(QFileDevice::ReadUser | QFileDevice::WriteUser);
}
generateFileMd5sums();
}
示例7: moveFile
bool FileSystem::moveFile(const QString &locationTo,
const QString &locationFrom)
{
// QImage img(getCurrentAbsoluteFileName());
// bool success;
// if(SaveConfirmation::imageWasChanged(getCurrentAbsoluteFileName()))
// {
// img = SaveConfirmation::getChagedImage(getCurrentAbsoluteFileName());
// success = img.save(locationForSaving);
// if(success)
// SaveConfirmation::deleteImage(getCurrentAbsoluteFileName());
// }
// else
// success = img.save(locationForSaving);
QFile file;
if(file.exists(locationTo))
file.remove(locationTo);
bool success = file.copy(locationFrom, locationTo);
if(success)
SaveConfirmation::deleteImage(locationTo);
return success;
}
示例8: add
bool QDSDataStore::add( const QUniqueId& id,
QFile& data,
const QMimeType& type )
{
// Create info file and copy data file (in an atomic fashion)
QDSLockedFile infoFile( infoFileName( id ) );
if ( infoFile.exists() ) {
qLog(DataSharing) << "QDSDataStore::add - info file already exists";
return false;
}
if ( !infoFile.openLocked( QIODevice::WriteOnly ) ) {
qLog(DataSharing) << "QDSDataStore::add - "
<< "info file can't be written to";
return false;
}
if ( !data.copy( dataFileName( id ) ) ) {
qLog(DataSharing) << "QDSDataStore::add - couldn't copy data file";
return false;
}
QDataStream ds(&infoFile);
ds << 1;
ds << 0;
ds << type.id();
return true;
}
示例9: writeBatteryPar
bool TextHelper::writeBatteryPar(QString batteryPar)
{
QFile *dtsFile = new QFile(Global::srcPath + "/" + Global::dtsPath);
QFile *tempFile = new QFile(QDir::currentPath() + "/tmp/temp.txt");
QTextStream dtsTS(dtsFile);
QTextStream tempTS(tempFile);
if(!dtsFile->open(QIODevice::ReadOnly))
{
qDebug() << Global::srcPath + "/" + Global::dtsPath << " open fail";
return false;
}
if(!tempFile->open(QIODevice::WriteOnly))
{
qDebug() << QDir::currentPath() + "/tmp/temp.txt" << " open fail";
dtsFile->close();
return false;
}
QString strLine;
while (!dtsTS.atEnd())
{
strLine = dtsTS.readLine();
if(strLine.contains("battery {"))
{
tempTS << strLine << "\n";
strLine = dtsTS.readLine();
tempTS << strLine << "\n";
tempTS << " ocv_table = <";
QStringList strList = batteryPar.trimmed().split(" ");
for(int i = 1; i < 21; i++)
{
tempTS << strList[i -1] << " ";
if(i%7 == 0)
{
tempTS << "\n\t\t\t";
}
}
tempTS << strList[20];
tempTS << ">;\n";
dtsTS.readLine();
dtsTS.readLine();
dtsTS.readLine();
continue;
}
tempTS << strLine << "\n";
}
dtsFile->close();
tempFile->flush();
tempFile->close();
if(!dtsFile->remove())
{
qDebug() << "dtsFile remove fail";
return false;
}
if(!tempFile->copy(Global::srcPath + "/" + Global::dtsPath))
{
qDebug() << "copy fail" << Global::srcPath + "/" + Global::dtsPath;
return false;
}
return true;
}
示例10: cargarImagen
void NuevoCandidato::cargarImagen()
{
QFile *file =new QFile();
QString dirImagen = QFileDialog::getOpenFileName(this, tr("Imagen Candidato"), "/home/documents/imagenes/logopal", tr("Image Files (*.png *.jpg *.bmp)"));
if(dirImagen.isEmpty())
{
return;
}
QFileInfo *file2 = new QFileInfo(dirImagen);
QString dirLocal("documents/imagenes/");
QString nombreImagen;
QString extension;
extension = file2->completeSuffix();
nombreImagen = file2->completeBaseName();
dirLocal.append(nombreImagen);
dirLocal.append(".");
dirLocal.append(extension);
file->copy ( dirImagen, dirLocal );
imagen = dirLocal;
QPixmap *logo = new QPixmap(imagen);
QSize *iconSize = new QSize(95 , 95);
imgen->setPixmap(logo->scaled(*iconSize));
}
示例11: saveAs
void FaceTrackNoIR::saveAs()
{
looping++;
QSettings settings("opentrack");
QString oldFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString();
QString fileName = QFileDialog::getSaveFileName(this, tr("Save file"),
oldFile,
tr("Settings file (*.ini);;All Files (*)"));
if (!fileName.isEmpty()) {
QFileInfo newFileInfo ( fileName );
if ((newFileInfo.exists()) && (oldFile != fileName)) {
QFile newFileFile ( fileName );
newFileFile.remove();
}
QFileInfo oldFileInfo ( oldFile );
if (oldFileInfo.exists()) {
QFile oldFileFile ( oldFile );
oldFileFile.copy( fileName );
}
settings.setValue ("SettingsFile", fileName);
save();
}
looping--;
fill_profile_cbx();
}
示例12: copyFileToFolder
void FileManager::copyFileToFolder(QString originPath, QString originName,QString newPath,QString newName) {
QFile *originFile = new QFile(originPath + "/" + originName);
if(QString::compare(originPath,newPath)==0 && QString::compare(originName,newName)==0) return;
if(QFile::exists(newPath+"/"+newName)) QFile::remove(newPath+"/"+newName);
originFile->copy(newPath + "/" + newName);
delete originFile;
}
示例13: on_toolButtonOPenGroup_clicked
void DialogConfigBooks::on_toolButtonOPenGroup_clicked()
{
QFileDialog dlg;
QString homeDir=QDir::homePath () ;
QString fn = dlg.getOpenFileName(0, tr("Open xml Files..."),
homeDir , trUtf8("ملف قائمة الكتب (group.xml );;xml (group.xml)"));
qDebug()<<fn;
if(!dlg.AcceptOpen)
// return;
if (!fn.isEmpty())
{
QString groupPath=QDir::homePath()+"/.kirtasse/data/group.xml";
QString groupPathNew=QDir::homePath()+"/.kirtasse/data/group.xml.old";
QFile file;
if(file.exists(groupPathNew))
file.remove(groupPathNew);
if(file.rename(groupPath,groupPathNew)) {
if(file.copy(fn,groupPath)){
Messages->treeChargeGroupe( ui->treeWidgetBooks,0,true);
ui->lineEditGroup->setText(fn);
ui->toolButtonGroupUpdat->setEnabled(true);
}
}
if(ui->treeWidgetBooks->topLevelItemCount()<1)
on_toolButtonGroupUpdat_clicked();
}
}
示例14: sourceFile
QString
SoundSettings::saveFile (
const QString &filePath)
{
QFile sourceFile (filePath);
QString baseDir;
QString fileName;
QString xmlFileName;
QString retval = filePath;
QDir baseDirectory;
QString targetFilePath;
suggestedTargetFilePath (filePath, baseDir, fileName, xmlFileName);
SYS_DEBUG ("*** baseDir = %s", SYS_STR(baseDir));
SYS_DEBUG ("*** fileName = %s", SYS_STR(fileName));
baseDirectory = QDir (baseDir);
if (!baseDirectory.exists()) {
if (!QDir::root().mkpath(baseDir)) {
SYS_WARNING ("ERROR: mkdir(%s) failed.", SYS_STR(baseDir));
goto finalize;
}
}
targetFilePath =
baseDir + QDir::separator() + fileName;
xmlFileName =
baseDir + QDir::separator() + xmlFileName;
if (QFile(targetFilePath).exists()) {
SYS_DEBUG ("The file '%s' already exists.", SYS_STR(targetFilePath));
retval = targetFilePath;
goto finalize;
}
if (sourceFile.copy(targetFilePath)) {
SYS_DEBUG ("File copy to %s success.", SYS_STR(targetFilePath));
retval = targetFilePath;
} else {
SYS_WARNING ("ERROR: Unable to copy %s -> %s: %m",
SYS_STR(filePath),
SYS_STR(targetFilePath));
}
finalize:
if (retval != filePath) {
TrackerConnection *tracker = TrackerConnection::instance();
QString title;
tracker->registerFileCopy (filePath, retval);
title = tracker->niceNameFromFileName (filePath);
saveXML (xmlFileName, filePath, retval, title);
}
return retval;
}
示例15: loadSourceFBX
void FBXBaker::loadSourceFBX() {
// check if the FBX is local or first needs to be downloaded
if (_modelURL.isLocalFile()) {
// load up the local file
QFile localFBX { _modelURL.toLocalFile() };
qDebug() << "Local file url: " << _modelURL << _modelURL.toString() << _modelURL.toLocalFile() << ", copying to: " << _originalModelFilePath;
if (!localFBX.exists()) {
//QMessageBox::warning(this, "Could not find " + _fbxURL.toString(), "");
handleError("Could not find " + _modelURL.toString());
return;
}
// make a copy in the output folder
if (!_originalOutputDir.isEmpty()) {
qDebug() << "Copying to: " << _originalOutputDir << "/" << _modelURL.fileName();
localFBX.copy(_originalOutputDir + "/" + _modelURL.fileName());
}
localFBX.copy(_originalModelFilePath);
// emit our signal to start the import of the FBX source copy
emit sourceCopyReadyToLoad();
} else {
// remote file, kick off a download
auto& networkAccessManager = NetworkAccessManager::getInstance();
QNetworkRequest networkRequest;
// setup the request to follow re-directs and always hit the network
networkRequest.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
networkRequest.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysNetwork);
networkRequest.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT);
networkRequest.setUrl(_modelURL);
qCDebug(model_baking) << "Downloading" << _modelURL;
auto networkReply = networkAccessManager.get(networkRequest);
connect(networkReply, &QNetworkReply::finished, this, &FBXBaker::handleFBXNetworkReply);
}
}