本文整理汇总了C++中QTemporaryFile::rename方法的典型用法代码示例。如果您正苦于以下问题:C++ QTemporaryFile::rename方法的具体用法?C++ QTemporaryFile::rename怎么用?C++ QTemporaryFile::rename使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTemporaryFile
的用法示例。
在下文中一共展示了QTemporaryFile::rename方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: zip
bool QgsArchive::zip( const QString &filename )
{
// create a temporary path
QTemporaryFile tmpFile;
tmpFile.open();
tmpFile.close();
// zip content
if ( ! QgsZipUtils::zip( tmpFile.fileName(), mFiles ) )
{
QString err = QObject::tr( "Unable to zip content" );
QgsMessageLog::logMessage( err, QStringLiteral( "QgsArchive" ) );
return false;
}
// remove existing zip file
if ( QFile::exists( filename ) )
QFile::remove( filename );
// save zip archive
if ( ! tmpFile.rename( filename ) )
{
QString err = QObject::tr( "Unable to save zip file '%1'" ).arg( filename );
QgsMessageLog::logMessage( err, QStringLiteral( "QgsArchive" ) );
return false;
}
// keep the zip filename
tmpFile.setAutoRemove( false );
return true;
}
示例2: s
void
writeXml( const QDomDocument& xml, const QString& path )
{
// we write to a temporary file, and then do an atomic move
// this prevents the client from potentially reading a corrupt XML file
QTemporaryFile f;
f.setAutoRemove( false );
if (!f.open())
throw "Couldn't write XML";
QTextStream s( &f );
xml.save( s, 2 );
if ( !f.rename( path ) )
throw QString("Couldn't move to ") + path;
}
示例3: assemble
//.........这里部分代码省略.........
QTemporaryFile file(input.outputPath);
if (!file.open()) {
throw Error(QString::fromLatin1("Cannot copy %1 to %2: %3").arg(input.installerExePath,
input.outputPath, file.errorString()));
}
const QString tempFile = file.fileName();
file.close();
file.remove();
QFile instExe(input.installerExePath);
if (!instExe.copy(tempFile)) {
throw Error(QString::fromLatin1("Cannot copy %1 to %2: %3").arg(instExe.fileName(),
tempFile, instExe.errorString()));
}
QtPatch::patchBinaryFile(tempFile, QByteArray("MY_InstallerCreateDateTime_MY"),
QDateTime::currentDateTime().toString(QLatin1String("yyyy-MM-dd - HH:mm:ss")).toLatin1());
input.installerExePath = tempFile;
#if defined(Q_OS_WIN)
// setting the windows icon must happen before we append our binary data - otherwise they get lost :-/
if (QFile::exists(settings.installerApplicationIcon())) {
// no error handling as this is not fatal
setApplicationIcon(tempFile, settings.installerApplicationIcon());
}
#elif defined(Q_OS_OSX)
if (isBundle) {
// no error handling as this is not fatal
const QString copyscript = QDir::temp().absoluteFilePath(QLatin1String("copylibsintobundle.sh"));
QFile::copy(QLatin1String(":/resources/copylibsintobundle.sh"), copyscript);
QFile::rename(tempFile, input.outputPath);
chmod755(copyscript);
QProcess p;
p.start(copyscript, QStringList() << bundle);
p.waitForFinished(-1);
QFile::rename(input.outputPath, tempFile);
QFile::remove(copyscript);
}
#endif
QTemporaryFile out;
QString targetName = input.outputPath;
#ifdef Q_OS_OSX
QDir resourcePath(QFileInfo(input.outputPath).dir());
resourcePath.cdUp();
resourcePath.cd(QLatin1String("Resources"));
targetName = resourcePath.filePath(QLatin1String("installer.dat"));
#endif
{
QFile target(targetName);
if (target.exists() && !target.remove()) {
qCritical("Cannot remove target %s: %s", qPrintable(target.fileName()),
qPrintable(target.errorString()));
QFile::remove(tempFile);
return EXIT_FAILURE;
}
}
try {
QInstaller::openForWrite(&out);
QFile exe(input.installerExePath);
示例4: save
void HistoryManager::save()
{
QSettings settings;
settings.beginGroup(QLatin1String("history"));
settings.setValue(QLatin1String("historyLimit"), m_historyLimit);
bool saveAll = m_lastSavedUrl.isEmpty();
int first = m_history.count() - 1;
if (!saveAll) {
// find the first one to save
for (int i = 0; i < m_history.count(); ++i) {
if (m_history.at(i).url == m_lastSavedUrl) {
first = i - 1;
break;
}
}
}
if (first == m_history.count() - 1)
saveAll = true;
QString directory = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
if (directory.isEmpty())
directory = QDir::homePath() + QLatin1String("/.") + QCoreApplication::applicationName();
if (!QFile::exists(directory)) {
QDir dir;
dir.mkpath(directory);
}
QFile historyFile(directory + QLatin1String("/history"));
// When saving everything use a temporary file to prevent possible data loss.
QTemporaryFile tempFile;
tempFile.setAutoRemove(false);
bool open = false;
if (saveAll) {
open = tempFile.open();
} else {
open = historyFile.open(QFile::Append);
}
if (!open) {
qWarning() << "Unable to open history file for saving"
<< (saveAll ? tempFile.fileName() : historyFile.fileName());
return;
}
QDataStream out(saveAll ? &tempFile : &historyFile);
for (int i = first; i >= 0; --i) {
QByteArray data;
QDataStream stream(&data, QIODevice::WriteOnly);
HistoryItem item = m_history.at(i);
stream << HISTORY_VERSION << item.url << item.dateTime << item.title;
out << data;
}
tempFile.close();
if (saveAll) {
if (historyFile.exists() && !historyFile.remove())
qWarning() << "History: error removing old history." << historyFile.errorString();
if (!tempFile.rename(historyFile.fileName()))
qWarning() << "History: error moving new history over old." << tempFile.errorString() << historyFile.fileName();
}
m_lastSavedUrl = m_history.value(0).url;
}