本文整理汇总了C++中QTemporaryFile::seek方法的典型用法代码示例。如果您正苦于以下问题:C++ QTemporaryFile::seek方法的具体用法?C++ QTemporaryFile::seek怎么用?C++ QTemporaryFile::seek使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTemporaryFile
的用法示例。
在下文中一共展示了QTemporaryFile::seek方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testUpgrade_data
void SettingsTest::testUpgrade_data(){
// Read recipe
QFile recipe(":/testdata/upgrade/recipe");
QVERIFY(recipe.open(QIODevice::ReadOnly));
QList<UpgradeTestHelper::TestCase> testCases = UpgradeTestHelper::readRecipe(&recipe);
// Generate settings file according to recipe
QTemporaryFile settingsFile;
QVERIFY(settingsFile.open() == true);
QSettings settings(settingsFile.fileName(), QSettings::IniFormat);
UpgradeTestHelper::fillSettings(&settings, testCases);
// Generate defaults file according to recipe
QTemporaryFile defaultSettingsFile;
QVERIFY(defaultSettingsFile.open() == true);
QSettings defaultSettings(defaultSettingsFile.fileName(), QSettings::IniFormat);
UpgradeTestHelper::fillDefaultSettings(&defaultSettings, testCases);
// Parse settings -- do upgrade
#if 0
settingsFile.seek(0);
defaultSettingsFile.seek(0);
qDebug() << "SETTINGS {{{\n" << settingsFile.readAll() << "\n}}}";
qDebug() << "DEFAULT SETTINGS {{{\n" << defaultSettingsFile.readAll() << "\n}}}";
#endif
SsuSettings ssuSettings(settingsFile.fileName(), QSettings::IniFormat,
defaultSettingsFile.fileName());
#if 0
settingsFile.seek(0);
qDebug() << "SETTINGS UPGRADED {{{\n" << settingsFile.readAll() << "\n}}}";
#endif
// Record data for verification phase
QTest::addColumn<bool>("keyIsSet");
QTest::addColumn<bool>("keyShouldBeSet");
QTest::addColumn<QString>("actualValue");
QTest::addColumn<QString>("expectedValue");
foreach (const UpgradeTestHelper::TestCase &testCase, testCases){
foreach (const QString &group, UpgradeTestHelper::groups()){
const QString key = group.isEmpty() ? testCase.key() : group + '/' + testCase.key();
QTest::newRow(qPrintable(QString("%1%2:%3:%4")
.arg(group.isEmpty() ? "" : group + "/")
.arg(testCase.history())
.arg(testCase.current())
.arg(testCase.expected())))
<< ssuSettings.contains(key)
<< testCase.keyShouldBeSet()
<< ssuSettings.value(key).toString()
<< testCase.expected();
}
}
示例2: while
QTemporaryFile *QTemporaryFile::createNativeFile(QFile &file)
{
if (QAbstractFileEngine *engine = file.d_func()->engine()) {
if(engine->fileFlags(QAbstractFileEngine::FlagsMask) & QAbstractFileEngine::LocalDiskFlag)
return 0; //native already
//cache
bool wasOpen = file.isOpen();
qint64 old_off = 0;
if(wasOpen)
old_off = file.pos();
else
file.open(QIODevice::ReadOnly);
//dump data
QTemporaryFile *ret = new QTemporaryFile;
ret->open();
file.seek(0);
char buffer[1024];
while(true) {
qint64 len = file.read(buffer, 1024);
if(len < 1)
break;
ret->write(buffer, len);
}
ret->seek(0);
//restore
if(wasOpen)
file.seek(old_off);
else
file.close();
//done
return ret;
}
return 0;
}
示例3: csvImport
void TestImport::csvImport()
{
// Fetch data
QFETCH(QString, csv);
QFETCH(char, separator);
QFETCH(char, quote);
QFETCH(QString, encoding);
QFETCH(int, numfields);
QFETCH(QVector<QStringList>, result);
// Create temporary CSV file
QTemporaryFile file;
QVERIFY(file.open());
{
QTextStream out(&file);
out.setCodec(encoding.toUtf8());
out << csv;
}
file.flush();
CSVParser csvparser(true, separator, quote);
file.seek(0);
QTextStream tstream(&file);
tstream.setCodec(encoding.toUtf8());
csvparser.parse(tstream);
// Check return values
QCOMPARE(csvparser.csv(), result);
QCOMPARE((int)csvparser.columns(), numfields);
}
示例4: replyFinished
void BrisaControlPoint::replyFinished(QNetworkReply *reply) {
QTemporaryFile *rootXml = new QTemporaryFile();
if (!rootXml->open()) {
qWarning() << "Brisa Control Point: Failed to open file for writing root XML.";
} else {
rootXml->write(reply->readAll());
rootXml->seek(0);
QUrl *urlBase = new QUrl(reply->url());
BrisaControlPointDevice *device = new BrisaControlPointDevice(rootXml, urlBase);
/* Fix embedded devices host/port attributes */
QList<BrisaControlPointService*> serviceList = device->getServiceList();
foreach(BrisaControlPointService *s, serviceList) {
s->setAttribute(BrisaControlPointService::Host, urlBase->host());
s->setAttribute(BrisaControlPointService::Port,
QString().setNum(urlBase->port()));
}
rootXml->remove();
delete rootXml;
delete urlBase;
// deleteLater as per Qt documentation (see Detailed Description section of
// QNetworkAccessManager class documentation for more details;
reply->deleteLater();
emit deviceFound(device);
}
示例5: foreach
// Follow the links (now sorted), load page from unsorted file and
// store it to the end of a new file. The file is thus sorted.
foreach(const Link &it, links)
{
temporaryFile.seek(it.second);
QString name = FileUtils::readString(temporaryFile);
QString contents = FileUtils::readString(temporaryFile);
CHECK_MSG(file.pos() == it.second + sizeof(quint32) + entryCount * sizeof(qint64), "Data corruption.");
FileUtils::writeString(file, name);
FileUtils::writeString(file, contents);
}
示例6: csvImport
void TestImport::csvImport()
{
// Fetch data
QFETCH(QString, csv);
QFETCH(char, separator);
QFETCH(char, quote);
QFETCH(QString, encoding);
QFETCH(int, numfields);
QFETCH(QVector<QVector<QByteArray>>, result);
// Create temporary CSV file
QTemporaryFile file;
QVERIFY(file.open());
{
QTextStream out(&file);
out.setCodec(encoding.toUtf8());
out << csv;
}
file.flush();
CSVParser csvparser(true, separator, quote);
file.seek(0);
QTextStream tstream(&file);
tstream.setCodec(encoding.toUtf8());
QVector<QVector<QByteArray>> parsedCsv;
int parsedCsvColumns = 0;
csvparser.parse([&parsedCsv, &parsedCsvColumns](size_t /*rowNum*/, const CSVRow& data) -> bool {
QVector<QByteArray> row;
for(size_t i=0;i<data.num_fields;i++)
row.push_back(QByteArray(data.fields[i].data, data.fields[i].data_length));
parsedCsv.push_back(row);
if(row.size() > parsedCsvColumns)
parsedCsvColumns = row.size();
return true;
}, tstream);
// Check return values
QCOMPARE(parsedCsvColumns, numfields);
QCOMPARE(parsedCsv.size(), result.size());
for(int i=0;i<parsedCsv.size();i++)
{
QCOMPARE(parsedCsv.at(i).size(), result.at(i).size());
for(int j=0;j<parsedCsv.at(i).size();j++)
QCOMPARE(parsedCsv.at(i).at(j), result.at(i).at(j));
}
QCOMPARE(parsedCsv, result);
}
示例7: checkInHead
bool SxVersionedFile::checkInHead( QFile *file, QDir *history)
{
QMap<QString,QVariant> props;
QByteArray data;
QFile revFile( makeVersionName( history, 0) );
if( revFile.exists () )
{
// Build patch
if( !revFile.open(QIODevice::ReadWrite) )
return false;
// Diff current file and revFile. save patch as rev + 1;
qDebug() << "Diff" << revFile.fileName();
QTemporaryFile patch;
patch.open();
m_versionUtils.diffQFiles( file, &revFile, &patch );
QMap<QString,QVariant> props = getHeadProps( history);
QString revName = makeNextVersionName( history );
qDebug() << "Write to" << revName;
QFile rev( revName );
if( !rev.open(QIODevice::WriteOnly) )
return false;
QDataStream outputStream( &rev );
patch.seek(0);
outputStream << props << patch.readAll();
rev.close();
patch.close();
revFile.close();
}
if( !revFile.open(QIODevice::ReadWrite) )
return false;
QDataStream outputStream( &revFile );
quint64 origPos = file->pos();
file->seek(0);
outputStream << metaInfo() << file->readAll();
file->seek(origPos);
revFile.close();
return true;
}
示例8: readwrite
void tst_qtemporaryfile::readwrite()
{
QFETCH(qint64, amount);
const int dataSize = 4096;
QByteArray data;
data.fill('a', dataSize);
QBENCHMARK {
for (qint64 i = 0; i < amount; ++i) {
QTemporaryFile file;
file.open();
file.write(data);
file.seek(0);
file.read(dataSize);
file.close();
}
}
}
示例9: size
void tst_QTemporaryFile::size()
{
QTemporaryFile file;
QVERIFY(file.open());
QVERIFY(file.exists());
QVERIFY(!file.isSequential());
QByteArray str("foobar");
file.write(str);
QVERIFY(QFile::exists(file.fileName()));
// On CE it takes more time for the filesystem to update
// the information. Usually you have to close it or seek
// to get latest information. flush() does not help either.
#if !defined(Q_OS_WINCE)
QCOMPARE(file.size(), qint64(6));
#endif
file.seek(0);
QCOMPARE(file.size(), qint64(6));
}
示例10: loadInvalidLines
void TagDatabaseInMemoryTest::loadInvalidLines()
{
QTemporaryFile file;
QVERIFY(file.open());
file.write("tag1,1\ntag3\n");
file.seek(0);
TagDatabaseInMemory database("tests/resources/tag-types.txt", file.fileName());
QVERIFY(database.load());
QMap<QString, TagType> types = database.getTagTypes(QStringList() << "tag1" << "tag3");
QCOMPARE(types.count(), 1);
QCOMPARE(types.contains("tag1"), true);
QCOMPARE(types.contains("tag3"), false);
QCOMPARE(types.value("tag1").name(), QString("artist"));
QCOMPARE(database.count(), 1);
}
示例11: loadValidData
void TagDatabaseInMemoryTest::loadValidData()
{
QTemporaryFile file;
QVERIFY(file.open());
file.write("tag1,0\ntag2,1\ntag3,3\ntag4,4");
file.seek(0);
TagDatabaseInMemory database("tests/resources/tag-types.txt", file.fileName());
QVERIFY(database.load());
QMap<QString, TagType> types = database.getTagTypes(QStringList() << "tag1" << "tag3");
QCOMPARE(types.count(), 2);
QCOMPARE(types.contains("tag1"), true);
QCOMPARE(types.contains("tag3"), true);
QCOMPARE(types.value("tag1").name(), QString("general"));
QCOMPARE(types.value("tag3").name(), QString("copyright"));
QCOMPARE(database.count(), 4);
}
示例12: randomData
Variant TestLocalSocket::randomData(uchar *type, uchar dataAmnt, uchar pkgAmnt, uchar fdAmnt, QFile **targetFile) const
{
///@todo Get actual user file number limit and use it here
const int maxFiles = 512; // Limit number of files to send
if(m_openFiles.count() >= maxFiles)
fdAmnt = 0;
ushort maxAmnt = dataAmnt + pkgAmnt + fdAmnt;
if(maxAmnt == 0)
return Variant();
ushort actVal = (qrand()/(double(RAND_MAX)))*maxAmnt;
*type = (actVal < dataAmnt ? 0 : (actVal < dataAmnt+pkgAmnt ? 1 : 2));
// *type = qMin(uchar((qrand()/(double(RAND_MAX)))*3), uchar(2)); // 0..2
// *type = qMin(uchar((qrand()/(double(RAND_MAX)))*2), uchar(1)); // 0..1 => no file descriptors yet
// *type = 2; // Only file descriptors
Variant ret;
#define SIZE_MAX 1048576 // 1 M
// #define SIZE_MAX 262144 // 256 K
switch(*type)
{
// Random data
case 0:
case 1:
{
quint32 size = qMax(quint32((qrand()/double(RAND_MAX))*SIZE_MAX), quint32(1)); // At least one byte
QByteArray data;
data.reserve(size);
for(qint64 j = 0; j < size; j += sizeof(int))
{
int r = qrand();
data.append((char*)&r, qMin(int(size - data.size()), (int)sizeof(int)));
}
ret = data;
}break;
// File descriptor
case 2:
{
QTemporaryFile * file = new QTemporaryFile(QDir::tempPath() + QDir::separator() + "testlocalsocket");
if(!file->open())
{
delete file;
qDebug("Could not create temporary file!");
return Variant();
}
// Write filename to temp file
QFileInfo info(*file);
file->write(QString("%1").arg(info.absoluteFilePath()).toUtf8());
file->flush();
file->seek(0);
ret = Variant::fromSocketDescriptor(file->handle());
*targetFile = file;
}break;
}
return ret;
}