本文整理汇总了C++中QTemporaryFile::copy方法的典型用法代码示例。如果您正苦于以下问题:C++ QTemporaryFile::copy方法的具体用法?C++ QTemporaryFile::copy怎么用?C++ QTemporaryFile::copy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTemporaryFile
的用法示例。
在下文中一共展示了QTemporaryFile::copy方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: save
FileFactory::FileError FileFactory::save(FileVersion version)
{
if(version == FileFactory::Version_Auto) {
version = (FileVersion)mCurrentFileVersion;
} else {
mCurrentFileVersion = version;
}
//Don't save a file without at least 1 tab.
if(mTabWidget->count() <= 0)
return FileFactory::Err_NoTabsToSave;
QTemporaryFile f;
if(!f.open()) {
//TODO: some nice dialog to warn the user.
qWarning() << "Couldn't open file for writing..." << f.fileName();
return FileFactory::Err_OpeningFile;
}
QDataStream out(&f);
// Write a header with a "magic number" and a version
out << AppInfo::inst()->magicNumber;
File *saveFile = 0;
switch(version) {
default:
case FileFactory::Version_1_2:
saveFile = new File_v2(mMainWindow, this);
break;
case FileFactory::Version_1_0:
saveFile = new File_v1(mMainWindow, this);
break;
}
int error = saveFile->save(&out);
f.close();
if(error != FileFactory::No_Error)
return (FileFactory::FileError)error;
QDir d(QFileInfo(fileName).path());
//only try to delete the file if it exists.
if(d.exists(fileName)) {
if(!d.remove(fileName))
return FileFactory::Err_RemovingOrigFile;
}
if(!f.copy(fileName)) {
qDebug() << "Could not write final output file." << f.fileName() << fileName;
return FileFactory::Err_RenamingTempFile;
}
return FileFactory::No_Error;
}
示例2: build
void ArchivBuilder::build( QByteArray stubData, QString fileName ) {
QTemporaryFile tmpArchiv;
tmpArchiv.open();
qDebug() << "Will create temporarty file: " << tmpArchiv.fileName();
QDataStream ds( &tmpArchiv );
ds.writeRawData( stubData, stubData.size() );
// Set dataMarker
for( uint i = 0; i < ArchivBuilder::DATA_MARKER_LENGTH - 1; i++ ) {
ds.writeRawData( ArchivBuilder::DATA_MARKER + i , 1 );
}
// qDebug() << "Marker size: " << ArchivBuilder::DATA_MARKER_LENGTH;
ds.writeRawData( ArchivBuilder::DATA_MARKER_REPLACECHAR + 0 , 1 );
QByteArray indexData = _index->compressedIndexData();
int indexSize = indexData.size();
qDebug() << "Index size: " << indexSize;
QString indexSizeString;
indexSizeString.setNum( indexSize );
ds.writeRawData( indexSizeString.toAscii(), indexSizeString.toAscii().size() );
ds.writeRawData( "\n", 1 );
// qDebug() << "Wrote size string: " << indexSizeString.toAscii();
ds.writeRawData( indexData, indexData.size() );
QByteArray archivData = _data->data();
ds.writeRawData( archivData, archivData.size() );
qDebug() << "Wrote data section of size: " << archivData.size();
if ( QFileInfo( fileName ).exists() ) {
QFile( fileName ).remove();
// QFile( fileName ).rename( QString( "%1_back_%2" ).arg( fileName ).arg( RedBullPlayer::Tools::UuidCreator::create() ) );
}
if( tmpArchiv.copy( fileName ) ) {
qDebug() << "Created Archive at: " << QFileInfo( fileName ) .absoluteFilePath();
} else {
qWarning() << "Could not copy archiv file to: " << QFileInfo( fileName ) .absoluteFilePath();
}
qDebug() << "Will create temporarty file: " << tmpArchiv.fileName();
tmpArchiv.close();
tmpArchiv.remove();
}
示例3: stream
void ImageManager::ThumbnailCache::save() const
{
m_timer->stop();
m_unsaved = 0;
QTemporaryFile file;
if ( !file.open() ) {
qWarning("Failed to create temporary file");
return;
}
QDataStream stream(&file);
stream << FILEVERSION
<< m_currentFile
<< m_currentOffset
<< m_map.count();
for( QMap<DB::FileName,CacheFileInfo>::ConstIterator it = m_map.begin(); it != m_map.end(); ++it ) {
const CacheFileInfo& cacheInfo = it.value();
stream << it.key().relative()
<< cacheInfo.fileIndex
<< cacheInfo.offset
<< cacheInfo.size;
}
file.close();
const QString realFileName = thumbnailPath(QString::fromLatin1("thumbnailindex"));
QFile::remove( realFileName );
if ( !file.copy( realFileName ) )
qWarning("Failed to copy the temporary file %s to %s", qPrintable( file.fileName() ), qPrintable( realFileName ) );
QFile realFile( realFileName );
realFile.open( QIODevice::ReadOnly );
realFile.setPermissions( QFile::ReadOwner | QFile::WriteOwner | QFile::ReadGroup | QFile::WriteGroup | QFile::ReadOther );
realFile.close();
}
示例4: logItem
void BootloaderInstallHex::installStage2(void)
{
emit logItem(tr("Adding bootloader to firmware file"), LOGINFO);
QCoreApplication::processEvents();
// local temp file
QTemporaryFile tempbin;
tempbin.open();
QString tempbinName = tempbin.fileName();
tempbin.close();
// get temporary files filenames -- external tools need this.
m_descrambled.open();
QString descrambledName = m_descrambled.fileName();
m_descrambled.close();
m_tempfile.open();
QString tempfileName = m_tempfile.fileName();
m_tempfile.close();
int origin = 0;
switch(m_model) {
case 3:
origin = 0x3f0000;
break;
case 2:
case 1:
origin = 0x1f0000;
break;
default:
origin = 0;
break;
}
// iriver decode already done in stage 1
int result;
if((result = mkboot_iriver(descrambledName.toLocal8Bit().constData(),
tempfileName.toLocal8Bit().constData(),
tempbinName.toLocal8Bit().constData(), origin)) < 0)
{
QString error;
switch(result) {
case -1: error = tr("could not open input file"); break;
case -2: error = tr("reading header failed"); break;
case -3: error = tr("reading firmware failed"); break;
case -4: error = tr("can't open bootloader file"); break;
case -5: error = tr("reading bootloader file failed"); break;
case -6: error = tr("can't open output file"); break;
case -7: error = tr("writing output file failed"); break;
}
emit logItem(tr("Error in patching: %1").arg(error), LOGERROR);
emit done(true);
return;
}
QTemporaryFile targethex;
targethex.open();
QString targethexName = targethex.fileName();
if((result = iriver_encode(tempbinName.toLocal8Bit().constData(),
targethexName.toLocal8Bit().constData(), FALSE)) < 0)
{
emit logItem(tr("Error in scramble: %1").arg(scrambleError(result)), LOGERROR);
targethex.close();
emit done(true);
return;
}
// finally check the md5sum of the created file
QByteArray filedata;
filedata = targethex.readAll();
targethex.close();
QString hash = QCryptographicHash::hash(filedata,
QCryptographicHash::Md5).toHex();
qDebug() << "[BootloaderInstallHex] created hexfile hash:" << hash;
emit logItem(tr("Checking modified firmware file"), LOGINFO);
if(hash != QString(md5sums[m_hashindex].patched)) {
emit logItem(tr("Error: modified file checksum wrong"), LOGERROR);
targethex.remove();
emit done(true);
return;
}
// finally copy file to player
targethex.copy(m_blfile);
emit logItem(tr("Success: modified firmware file created"), LOGINFO);
logInstall(LogAdd);
emit done(false);
return;
}