本文整理汇总了C++中QTemporaryFile::reset方法的典型用法代码示例。如果您正苦于以下问题:C++ QTemporaryFile::reset方法的具体用法?C++ QTemporaryFile::reset怎么用?C++ QTemporaryFile::reset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTemporaryFile
的用法示例。
在下文中一共展示了QTemporaryFile::reset方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testInput
void IOHandlerTest::testInput()
{
QTemporaryFile stdIn;
stdIn.open();
IOHandler io(stdIn.handle());
QVector<quint64> ids;
quint32 size = 10;
ids.reserve(size);
QByteArray ba;
ba.append(reinterpret_cast<char*>(&size), sizeof(quint32));
for (quint64 i = 0; i < 10; ++i) {
quint64 a = std::pow(16, i);
ids.append(a);
ba.append(reinterpret_cast<char*>(&a), sizeof(quint64));
}
stdIn.write(ba.data(), ba.size());
//we will de dealing with stdin actually which is a sequential device
//hence io handler expects to read from start.
stdIn.reset();
io.newBatch();
quint32 i = 0;
while (!io.atEnd()) {
QCOMPARE(io.nextId(), ids.at(i++));
}
QCOMPARE(i, size);
}
示例2: write
void tst_QTemporaryFile::write()
{
QByteArray data("OLE\nOLE\nOLE");
QTemporaryFile file;
QVERIFY(file.open());
QCOMPARE((int)file.write(data), data.size());
file.reset();
QFile compare(file.fileName());
compare.open(QIODevice::ReadOnly);
QCOMPARE(compare.readAll() , data);
file.close();
}
示例3: main
int main(int, char *[])
{
Data data;
data.setString("Hello World");
data.setValue(42);
QTemporaryFile file;
if (!file.open()) {
qDebug() << "Temp file opening failed.";
return EXIT_FAILURE;
}
QDataStream stream(&file);
// If a custom type is searilzed using QVariant,
// serialization operators need to be provided
#ifdef USE_VARIANT
qRegisterMetaTypeStreamOperators<Data>("Data");
QVariant variantData(QVariant::fromValue(data));
stream << variantData;
#else
stream << data;
#endif
file.reset();
// Serialize from the file
Data dataFromFile;
#ifdef USE_VARIANT
QVariant variantFromFile;
stream >> variantFromFile;
dataFromFile.setString(variantFromFile.value<Data>().string());
dataFromFile.setValue(variantFromFile.value<Data>().value());
#else
stream >> dataFromFile;
#endif
qDebug() << dataFromFile.string();
qDebug() << dataFromFile.value();
file.close();
return EXIT_SUCCESS;
}
示例4: musicFile
bool KNMusicTagApev2::writeTag(const KNMusicAnalysisItem &analysisItem)
{
//Write the data according to the detail info.
const KNMusicDetailInfo &detailInfo=analysisItem.detailInfo;
//Check the file is still exist or not.
QFile musicFile(detailInfo.filePath);
//If the file is not exist then return false.
if(!musicFile.exists())
{
return false;
}
//Find the original tag data.
//ID3v1 header flag.
bool hasId3v1=false;
//Generate a header structure.
APEHeader header;
//Generate the raw tag data list.
QList<APETagItem> itemList;
//Initial the tag start position.
qint64 tagDataStart=-1, tagDataLength=-1;
//Open the file first.
if(musicFile.open(QIODevice::ReadOnly))
{
//Generate a data stream.
QDataStream musicDataStream(&musicFile);
if(musicFile.size() > 128)
{
//ID3v1 header cache.
char id3v1Header[3];
//Check whether there's ID3v1 tag in the music file.
musicDataStream.skipRawData(musicFile.size()-128);
//Read ID3v1 header.
musicDataStream.readRawData(id3v1Header, 3);
//Check the header, and we can know that whether there's ID3v1
//header.
hasId3v1=(id3v1Header[0]=='T' &&
id3v1Header[1]=='A' &&
id3v1Header[2]=='G');
}
//Check the beginning of the file.
if(checkHeader(0,
musicDataStream,
header))
{
//Set the tag data start.
tagDataStart=0;
//Set the tag length to header length.
tagDataLength=header.size;
//Check whether is a footer in the tag.
if(header.size > APEv2HeaderSize)
{
//Check the footer.
APEHeader footer;
//Tried to parse the footer.
if(checkHeader(header.size,
musicDataStream,
footer))
{
//Update the tag length.
tagDataLength+=APEv2HeaderSize;
}
}
//Reset the device to start.
musicDataStream.device()->reset();
//Skip the file data.
musicDataStream.skipRawData(APEv2HeaderSize);
}
//Check the end of the file.
else if(checkHeader(musicFile.size()-APEv2HeaderSize,
musicDataStream,
header))
{
//Save the tag start data.
int tagContentStart=musicFile.size()-header.size;
//Check the footer.
APEHeader footer;
//Check whether there's a header in the tag.
if(checkHeader(tagContentStart-APEv2HeaderSize,
musicDataStream,
footer))
{
//Save the tag data start position as the header start position.
//This is APEv2 tag.
tagDataStart=tagContentStart-APEv2HeaderSize;
//The tag length will be a header size + tag size.
tagDataLength=APEv2HeaderSize + header.size;
}
else
{
//This is APEv1 tag.
tagDataStart=tagContentStart;
//The tag length will be tag size.
tagDataLength=header.size;
}
//Reset the device to start.
musicDataStream.device()->reset();
//Skip the file data.
musicDataStream.skipRawData(tagContentStart);
}
//.........这里部分代码省略.........
示例5: writeDetail
//.........这里部分代码省略.........
//Simplified the raw line.
QString commandRawLine=rawLine.simplified();
//Generate command part and data part cache.
QString rawCommand, rawData;
//Parse the command.
parseCommand(commandRawLine, rawCommand, rawData);
//Now we are only taken care about the TRACK.
if(rawCommand=="TRACK")
{
//Use the trackIndex variable find the space temporarily.
int trackIndex=rawData.indexOf(' ');
//Get the track index.
trackIndex=
(trackIndex==-1?rawData:rawData.left(trackIndex)).toInt();
//Check the track index.
if(trackIndex==detailInfo.trackIndex)
{
//Hit the track.
//First we have to output the raw line data.
temporaryStream << rawLine << '\n';
//Then check the detail info data.
//We have to write out these informations:
// PERFORMER Artist
// TITLE Name
QString trackData;
trackData.append(generateLine(
" TITLE ",
detailInfo.textLists[Name].toString()));
trackData.append(generateLine(
" PERFORMER ",
detailInfo.textLists[Artist].toString()));
//Write the track data to temporary file.
temporaryStream << trackData;
//Read the original file again until to INDEX, skip all the
//other data.
rawLine=trackStream.readLine();
//Simplified the raw line.
commandRawLine=rawLine.simplified();
//Parse the raw line.
parseCommand(commandRawLine, rawCommand, rawData);
//Read until we get the INDEX.
while(!rawLine.isNull() && rawCommand!="INDEX")
{
//Continue skip the file.
rawLine=trackStream.readLine();
//Simplified the raw line.
commandRawLine=rawLine.simplified();
//Parse the raw line.
parseCommand(commandRawLine, rawCommand, rawData);
}
//So now the data should be the first INDEX.
//Output the data and continue copy the data.
temporaryStream << rawLine << '\n';
}
else
{
//Simply output the data.
temporaryStream << rawLine << '\n';
}
}
else
{
//Simply output the data.
temporaryStream << rawLine << '\n';
}
//Read the next line.
rawLine=trackStream.readLine();
}
//Flush the data.
temporaryStream << flush;
//Now the data should be all done.
//Close the list file.
listFile.close();
//Reset the temporary file.
updatedListFile.reset();
//Reopen the list file, open as write only mode.
if(!listFile.open(QIODevice::WriteOnly))
{
return false;
}
//Write all the data to list file.
//Generate the music data cache.
char *turboCache=new char[DataCacheSize];
//Now copy all the content from the original file to temporary file.
int bytesRead=updatedListFile.read(turboCache, DataCacheSize);
while(bytesRead>0)
{
//Write the cache to the list file.
listFile.write(turboCache, bytesRead);
//Read new data from the original file to cache.
bytesRead=updatedListFile.read(turboCache, DataCacheSize);
}
//Close the list file and temporary file.
listFile.close();
updatedListFile.close();
//Clear up the turbo cache.
delete[] turboCache;
//Written finished.
return true;
}
示例6: musicFile
//.........这里部分代码省略.........
//Stop searching.
break;
}
}
//Combine the meta expand list data.
QByteArray metaRawData=combineBoxList(metaExpandList);
//Clear up the meta expand list.
metaExpandList.clear();
//Append the first four bytes raw data to the meta box raw data.
metaRawData.prepend(metaBox.data, 4);
//Clear up the no use meta box.
clearBox(metaBox);
clearBox(updatedIlstBox);
//Set the data to new meta box.
metaBox.name="meta";
metaBox.independence=true;
metaBox.size=metaRawData.size();
metaBox.data=new char[metaBox.size];
memcpy(metaBox.data, metaRawData.data(), metaBox.size);
//Replace the original meta box.
for(int i=udtaExpandList.size()-1; i>-1; --i)
{
//Check the name.
if(udtaExpandList.at(i).name=="meta")
{
//Replace the item.
udtaExpandList.replace(i, metaBox);
//Stop Searching.
break;
}
}
//Combine the udta data together.
M4ABox updatedUdtaBox=zipBox("udta", udtaExpandList);
//Clear the list and original udta box.
udtaExpandList.clear();
clearBox(udtaBox);
//Replace the original udta box.
for(int i=moovExpandList.size()-1; i>-1; --i)
{
//Check the name.
if(moovExpandList.at(i).name=="udta")
{
//Replace the item
moovExpandList.replace(i, updatedUdtaBox);
//Stop searching.
break;
}
}
//Combine the moov data together.
M4ABox updatedMoovBox=zipBox("moov", moovExpandList);
//Clear the list and original moov box.
moovExpandList.clear();
clearBox(moovBox);
//Write the new moov box to the updated tag file.
writeBox(updatedMoovBox, updatedTagFile);
//Clear up the updated moov box.
clearBox(updatedMoovBox);
//Copy the left data to the updated tag file.
//Generate the music data cache.
char *turboCache=new char[DataCacheSize];
//Copy the music data from the original music file, copy the
//MusicDataCacheSize bytes once, until there's no bytes to copy.
int bytesRead=musicFile.read(turboCache, DataCacheSize);
while(bytesRead>0)
{
//Write the cache to temporary file.
updatedTagFile.write(turboCache, bytesRead);
//Read new data from the original file to cache.
bytesRead=musicFile.read(turboCache, DataCacheSize);
}
//Close the music file.
musicFile.close();
//Reset the temporary file.
updatedTagFile.reset();
//Reopen the music file as write only mode, write all the udpated tag file
//data to the music file.
if(!musicFile.open(QIODevice::WriteOnly))
{
//Close the updated tag file.
updatedTagFile.close();
//Failed to write data.
return false;
}
//Copy data from temporary file to music file.
bytesRead=updatedTagFile.read(turboCache, DataCacheSize);
while(bytesRead>0)
{
//Write the cache to music file.
musicFile.write(turboCache, bytesRead);
//Read new data from cache to the original file.
bytesRead=updatedTagFile.read(turboCache, DataCacheSize);
}
//Close the music file and temporary file.
musicFile.close();
updatedTagFile.close();
//Clear up the turbo memory.
delete[] turboCache;
//The tag rewrite is finished.
return true;
}