本文整理汇总了C++中QTemporaryDir类的典型用法代码示例。如果您正苦于以下问题:C++ QTemporaryDir类的具体用法?C++ QTemporaryDir怎么用?C++ QTemporaryDir使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QTemporaryDir类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testMoveRootFolder
void KInotifyTest::testMoveRootFolder()
{
// create some test folders
QTemporaryDir dir;
const QString src(QStringLiteral("%1/randomJunk1").arg(dir.path()));
const QString dest(QStringLiteral("%1/randomJunk2").arg(dir.path()));
mkdir(src);
// start watching the new subfolder only
KInotify kn(nullptr /*no config*/);
kn.addWatch(src, KInotify::EventAll);
// listen for the moved signal
QSignalSpy spy(&kn, SIGNAL(moved(QString,QString)));
// actually move the file
QFile::rename(src, dest);
// check the desired signal
QEXPECT_FAIL("", "KInotify cannot handle moving of top-level folders.", Abort);
QVERIFY(spy.wait(500));
QCOMPARE(spy.count(), 1);
QList<QVariant> args = spy.takeFirst();
QCOMPARE(args.at(0).toString(), src);
QCOMPARE(args.at(1).toString(), dest);
// check the path cache
QVERIFY(!kn.watchingPath(src));
QVERIFY(kn.watchingPath(dest));
}
示例2: testRenameFolder
void KInotifyTest::testRenameFolder()
{
// create some test files
QTemporaryDir dir;
const QString f1(QStringLiteral("%1/randomJunk1").arg(dir.path()));
mkdir(f1);
// start the inotify watcher
KInotify kn(nullptr /*no config*/);
kn.addWatch(dir.path(), KInotify::EventAll);
// listen to the desired signal
QSignalSpy spy(&kn, SIGNAL(moved(QString,QString)));
// actually move the file
const QString f2(QStringLiteral("%1/randomJunk2").arg(dir.path()));
QFile::rename(f1, f2);
// check the desired signal
QVERIFY(spy.wait());
QCOMPARE(spy.count(), 1);
QList<QVariant> args = spy.takeFirst();
QCOMPARE(args.at(0).toString(), f1);
QCOMPARE(args.at(1).toString(), f2);
// check the path cache
QVERIFY(!kn.watchingPath(f1));
QVERIFY(kn.watchingPath(f2));
// test a subsequent rename
const QString f3(QStringLiteral("%1/randomJunk3").arg(dir.path()));
QFile::rename(f2, f3);
// check the desired signal
QVERIFY(spy.wait());
QCOMPARE(spy.count(), 1);
args = spy.takeFirst();
QCOMPARE(args.at(0).toString(), f2);
QCOMPARE(args.at(1).toString(), f3);
// check the path cache
QVERIFY(!kn.watchingPath(f1));
QVERIFY(!kn.watchingPath(f2));
QVERIFY(kn.watchingPath(f3));
// KInotify claims it has updated its data structures, lets see if that is true
// by creating a file in the new folder
// listen to the desired signal
const QString f4(QStringLiteral("%1/somefile").arg(f3));
QSignalSpy createdSpy(&kn, SIGNAL(created(QString,bool)));
// test creating a file
touchFile(f4);
QVERIFY(createdSpy.wait());
QCOMPARE(createdSpy.count(), 1);
QCOMPARE(createdSpy.takeFirst().at(0).toString(), f4);
}
示例3: build
bool PuppetCreator::build(const QString &qmlPuppetProjectFilePath) const
{
PuppetBuildProgressDialog progressDialog;
m_compileLog.clear();
QTemporaryDir buildDirectory;
bool buildSucceeded = false;
if (qtIsSupported()) {
if (buildDirectory.isValid()) {
QStringList qmakeArguments;
qmakeArguments.append(QStringLiteral("-r"));
qmakeArguments.append(QStringLiteral("-after"));
qmakeArguments.append(QStringLiteral("DESTDIR=") + qmlpuppetDirectory(UserSpacePuppet));
#ifndef QT_DEBUG
qmakeArguments.append(QStringLiteral("CONFIG+=release"));
#endif
qmakeArguments.append(qmlPuppetProjectFilePath);
buildSucceeded = startBuildProcess(buildDirectory.path(), qmakeCommand(), qmakeArguments);
if (buildSucceeded) {
progressDialog.show();
buildSucceeded = startBuildProcess(buildDirectory.path(), buildCommand(), QStringList(), &progressDialog);
progressDialog.hide();
}
} else {
buildSucceeded = true;
}
}
m_useOnlyFallbackPuppet = !buildSucceeded; // fall back to creator puppet and don't compile again
return buildSucceeded;
}
示例4: lookForFstabEntries
FstabEntryList
lookForFstabEntries( const QString& partitionPath )
{
FstabEntryList fstabEntries;
QTemporaryDir mountsDir;
int exit = QProcess::execute( "mount", { partitionPath, mountsDir.path() } );
if ( !exit ) // if all is well
{
QFile fstabFile( mountsDir.path() + "/etc/fstab" );
if ( fstabFile.open( QIODevice::ReadOnly | QIODevice::Text ) )
{
QStringList fstabLines = QString::fromLocal8Bit( fstabFile.readAll() )
.split( '\n' );
foreach ( const QString& rawLine, fstabLines )
{
QString line = rawLine.simplified();
if ( line.startsWith( '#' ) )
continue;
QStringList splitLine = line.split( ' ' );
if ( splitLine.length() != 6 )
continue;
fstabEntries.append( { splitLine.at( 0 ), // path, or UUID, or LABEL, etc.
splitLine.at( 1 ), // mount point
splitLine.at( 2 ), // fs type
splitLine.at( 3 ), // options
splitLine.at( 4 ).toInt(), //dump
splitLine.at( 5 ).toInt() //pass
} );
}
示例5: order
void TestBuddies::testDisableAll()
{
/* 6. Disable buddy option, Disable open next to active tab
Open foo.cpp bar.h foo.h
Activate bar.h
Open bar.cpp
Verify order (foo.cpp bar.h foo.h bar.cpp)
Verify that bar.cpp is activated*/
enableBuddies(false);
enableOpenAfterCurrent(false);
QTemporaryDir tempDirA;
QDir dirA(tempDirA.path());
createFile(dirA, "foo.h");
createFile(dirA, "foo.cpp");
createFile(dirA, "bar.h");
createFile(dirA, "bar.cpp");
m_documentController->openDocument(QUrl::fromLocalFile(dirA.filePath("foo.cpp")));
m_documentController->openDocument(QUrl::fromLocalFile(dirA.filePath("bar.h")));
m_documentController->openDocument(QUrl::fromLocalFile(dirA.filePath("foo.h")));
Sublime::Area *area = m_uiController->activeArea();
Sublime::AreaIndex* areaIndex = area->indexOf(toSublimeWindow(m_uiController->activeMainWindow())->activeView());
//activate bar.h
toSublimeWindow(m_uiController->activeMainWindow())->activateView(areaIndex->views().value(1));
m_documentController->openDocument(QUrl::fromLocalFile(dirA.filePath("bar.cpp")));
verifyFilename(areaIndex->views().value(0), "foo.cpp");
verifyFilename(areaIndex->views().value(1), "bar.h");
verifyFilename(areaIndex->views().value(2), "foo.h");
verifyFilename(areaIndex->views().value(3), "bar.cpp");
verifyFilename(toSublimeWindow(m_uiController->activeMainWindow())->activeView(), "bar.cpp");
}
示例6: enableBuddies
void TestBuddies::testMultiDotFilenames()
{
enableBuddies();
enableOpenAfterCurrent();
QTemporaryDir tempDirA;
QDir dirA(tempDirA.path());
createFile(dirA, "a.cpp");
createFile(dirA, "lots.of.dots.cpp");
createFile(dirA, "b.cpp");
createFile(dirA, "lots.of.dots.h");
m_documentController->openDocument(QUrl::fromLocalFile(dirA.filePath("a.cpp")));
m_documentController->openDocument(QUrl::fromLocalFile(dirA.filePath("lots.of.dots.cpp")));
m_documentController->openDocument(QUrl::fromLocalFile(dirA.filePath("b.cpp")));
m_documentController->openDocument(QUrl::fromLocalFile(dirA.filePath("lots.of.dots.h")));
Sublime::Area *area = m_uiController->activeArea();
Sublime::AreaIndex* areaIndex = area->indexOf(toSublimeWindow(m_uiController->activeMainWindow())->activeView());
QCOMPARE(m_documentController->openDocuments().count(), 4);
//QCOMPARE(m_sublimeController->documents().count(), 4);
QCOMPARE(areaIndex->viewCount(), 4);
verifyFilename(areaIndex->views().value(0), "a.cpp");
verifyFilename(areaIndex->views().value(1), "lots.of.dots.h");
verifyFilename(areaIndex->views().value(2), "lots.of.dots.cpp");
verifyFilename(areaIndex->views().value(3), "b.cpp");
}
示例7: testCreateFolder
void KInotifyTest::testCreateFolder()
{
QTemporaryDir dir;
// start the inotify watcher
KInotify kn(nullptr /*no config*/);
kn.addWatch(dir.path(), KInotify::EventAll);
// listen to the desired signal
QSignalSpy createdSpy(&kn, SIGNAL(created(QString,bool)));
// create the subdir
const QString d1(QStringLiteral("%1/randomJunk1").arg(dir.path()));
mkdir(d1);
QVERIFY(createdSpy.wait());
QCOMPARE(createdSpy.count(), 1);
QCOMPARE(createdSpy.takeFirst().at(0).toString(), d1);
QVERIFY(kn.watchingPath(d1));
// lets go one level deeper
const QString d2 = QStringLiteral("%1/subdir1").arg(d1);
mkdir(d2);
QVERIFY(createdSpy.wait());
QCOMPARE(createdSpy.count(), 1);
QCOMPARE(createdSpy.takeFirst().at(0).toString(), d2);
QVERIFY(kn.watchingPath(d2));
// although we are in the folder test lets try creating a file
const QString f1 = QStringLiteral("%1/somefile1").arg(d2);
touchFile(f1);
QVERIFY(createdSpy.wait());
QCOMPARE(createdSpy.count(), 1);
QCOMPARE(createdSpy.takeFirst().at(0).toString(), f1);
}
示例8: QVERIFY
void Tests::doBasicTests(const QString &pFileName)
{
// Save the given COMBINE archive to the given file
QString fileName = pFileName.isEmpty()?mCombineArchive->fileName():pFileName;
mCombineArchive->save(fileName);
QVERIFY(QFile::exists(fileName));
// Unzip our COMBINE archive and make sure that its manifest is correct and
// that the various files are present
OpenCOR::ZIPSupport::QZipReader zipReader(fileName);
QTemporaryDir temporaryDir;
QVERIFY(zipReader.extractAll(temporaryDir.path()));
QCOMPARE(OpenCOR::fileContents(temporaryDir.path()+QDir::separator()+"manifest.xml"),
OpenCOR::fileContents(OpenCOR::fileName("src/plugins/support/COMBINESupport/tests/data/manifest.xml")));
for (int i = 1; i <= 3; ++i) {
for (int j = 1; j <= 3; ++j)
QVERIFY(QFile::exists(temporaryDir.path()+QDir::separator()+QString("dir0%1/file0%2.txt").arg(QString::number(i), QString::number(j))));
}
}
示例9: combineArchive
void Tests::basicTests()
{
// Create a simple COMBINE archive that contains various files
QString fileName = OpenCOR::Core::temporaryFileName();
OpenCOR::COMBINESupport::CombineArchive combineArchive(fileName);
int counter = 0;
for (int i = 1; i <= 3; ++i) {
for (int j = 1; j <= 3; ++j, ++counter) {
combineArchive.addFile(QDir::currentPath()+QDir::separator()+OpenCOR::fileName("src/plugins/support/COMBINESupport/tests/data/dir0%1/file0%2.txt").arg(QString::number(i), QString::number(j)),
QString("dir0%1/file0%2.txt").arg(QString::number(i), QString::number(j)),
OpenCOR::COMBINESupport::CombineArchiveFile::Format(1+counter%4),
!(counter%2));
}
}
combineArchive.save();
QVERIFY(QFile::exists(fileName));
// Unzip our COMBINE archive
OpenCOR::ZIPSupport::QZipReader zipReader(fileName);
QTemporaryDir temporaryDir;
QVERIFY(zipReader.extractAll(temporaryDir.path()));
zipReader.close();
// Make sure that our COMBINE archive's manifest is correct
QCOMPARE(OpenCOR::fileContents(temporaryDir.path()+QDir::separator()+"manifest.xml"),
OpenCOR::fileContents(OpenCOR::fileName("src/plugins/support/COMBINESupport/tests/data/manifest.xml")));
}
示例10: testZipAddLocalDirectory
void KArchiveTest::testZipAddLocalDirectory()
{
// Prepare local dir
QTemporaryDir tmpDir;
const QString dirName = tmpDir.path() + '/';
const QByteArray file1Data = "Hello Shantanu";
const QString file1 = QStringLiteral("file1");
QVERIFY(writeFile(dirName, file1, file1Data));
{
KZip zip(s_zipFileName);
QVERIFY(zip.open(QIODevice::WriteOnly));
QVERIFY(zip.addLocalDirectory(dirName, "."));
QVERIFY(zip.close());
}
{
KZip zip(s_zipFileName);
QVERIFY(zip.open(QIODevice::ReadOnly));
const KArchiveDirectory *dir = zip.directory();
QVERIFY(dir != nullptr);
const KArchiveEntry *e = dir->entry(file1);
QVERIFY(e && e->isFile());
const KArchiveFile *f = (KArchiveFile *)e;
QCOMPARE(f->data(), file1Data);
}
}
示例11: testMoving
void MoveTest::testMoving()
{
QTemporaryDir temporaryDir;
QFETCH(QString, archiveName);
const QString archivePath = temporaryDir.path() + QLatin1Char('/') + archiveName;
QVERIFY(QFile::copy(QFINDTESTDATA(QStringLiteral("data/") + archiveName), archivePath));
QFETCH(Plugin*, plugin);
QVERIFY(plugin);
auto loadJob = Archive::load(archivePath, plugin);
QVERIFY(loadJob);
loadJob->setAutoDelete(false);
TestHelper::startAndWaitForResult(loadJob);
auto archive = loadJob->archive();
QVERIFY(archive);
if (!archive->isValid()) {
QSKIP("Could not find a plugin to handle the archive. Skipping test.", SkipSingle);
}
QFETCH(QVector<Archive::Entry*>, targetEntries);
QFETCH(Archive::Entry*, destination);
QFETCH(QStringList, expectedNewPaths);
// Retrieve current paths in the archive.
QStringList oldPaths = getEntryPaths(archive);
// Check that the entries to be moved are in the archive.
foreach (const auto entry, targetEntries) {
QVERIFY(oldPaths.contains(entry->fullPath()));
}
示例12: bbMin
void TestShpFilter::testWritePolygonZFile() const
{
CCVector3d bbMin(1422671.7232666016, 4188903.4295959473, 71.99445343017578);
CCVector3d shift = ccGlobalShiftManager::BestShift(bbMin);
bool shiftEnabled = true;
ccHObject container;
FileIOFilter::LoadParameters params;
params.alwaysDisplayLoadDialog = false;
params.shiftHandlingMode = ccGlobalShiftManager::Mode::NO_DIALOG;
params.coordinatesShiftEnabled = &shiftEnabled;
params.coordinatesShift = &shift;
params.preserveShiftOnSave = true;
ShpFilter filter;
CC_FILE_ERROR error = filter.loadFile(POLYGONZ_FILE, container, params);
QVERIFY(error == CC_FERR_NO_ERROR);
QTemporaryDir tmpDir;
QString tmpMultipatch = tmpDir.path() + "polygon_z.shp";
FileIOFilter::SaveParameters saveParams;
saveParams.alwaysDisplaySaveDialog = false;
filter.save3DPolyAs2D(false);
filter.treatClosedPolylinesAsPolygons(true);
error = filter.saveToFile(&container, tmpMultipatch, saveParams);
QVERIFY(error == CC_FERR_NO_ERROR);
readPolygonZFile(tmpMultipatch);
}
示例13: qCDebug
bool GeneratePage::unpackArchive(const KArchiveDirectory *dir, const QString &dest)
{
qCDebug(KAPPTEMPLATE) << "unpacking dir:" << dir->name() << "to" << dest;
QStringList entries = dir->entries();
qCDebug(KAPPTEMPLATE) << "entries:" << entries.join(",");
QTemporaryDir tdir;
bool ret = true;
//create path were we want copy files to
if (!QDir::root().mkpath(dest)) {
displayError(i18n("%1 cannot be created.", dest));
return false;
}
int progress = 0;
bool failed = false;
foreach (const QString &entry, entries) {
progress++;
ui_generate.progressBar->setValue((progress / entries.size()) * 100);
if (entry.endsWith(".kdevtemplate"))
continue;
if (entry == templateName + ".png")
continue;
if (dir->entry(entry)->isDirectory()) {
const KArchiveDirectory *file = dynamic_cast<const KArchiveDirectory *>(dir->entry(entry));
QString newdest = dest + "/" + file->name();
if (!QFileInfo(newdest).exists()) {
if (!QDir::root().mkdir(newdest)) {
displayError(i18n("Path %1 could not be created.", newdest));
return false;
}
}
ret |= unpackArchive(file, newdest);
}
else if (dir->entry(entry)->isFile()) {
const KArchiveFile *file = dynamic_cast<const KArchiveFile *>(dir->entry(entry));
file->copyTo(tdir.path());
QString destName = KMacroExpander::expandMacros(dest + '/' + file->name(), m_variables);
if (QFile(QDir::cleanPath(tdir.path() + '/' + file->name())).copy(destName)) {
if (!extractFileMacros(destName)) {
displayError(i18n("Failed to integrate your project information into "
"the file %1. The project has not been generated and "
"all temporary files will be removed.", destName));
failed = true;
break;
}
} else {
displayError(i18n("Could not copy template file to %1.", destName));
failed = true;
break;
}
}
}
示例14: getMask
terrama2::core::DataSetSeries terrama2::core::DataAccessorDcpToa5::getSeries(const std::string& uri,
const terrama2::core::Filter& filter,
terrama2::core::DataSetPtr dataSet) const
{
std::string mask = getMask(dataSet);
std::string folder = getFolder(dataSet);
QTemporaryDir tempBaseDir;
if(!tempBaseDir.isValid())
{
QString errMsg = QObject::tr("Can't create temporary folder.");
TERRAMA2_LOG_ERROR() << errMsg;
throw DataAccessException() << ErrorDescription(errMsg);
}
QDir tempDir(tempBaseDir.path());
tempDir.mkdir(QString::fromStdString(folder));
tempDir.cd(QString::fromStdString(folder));
QUrl url((uri+"/"+folder+"/"+mask).c_str());
QFileInfo originalInfo(url.path());
QFile file(url.path());
QFile tempFile(tempDir.path()+"/"+originalInfo.fileName());
if(!file.open(QIODevice::ReadOnly))
{
QString errMsg = QObject::tr("Can't open file: dataset %1.").arg(dataSet->id);
TERRAMA2_LOG_ERROR() << errMsg;
throw DataAccessException() << ErrorDescription(errMsg);
}
if(!tempFile.open(QIODevice::ReadWrite))
{
QString errMsg = QObject::tr("Can't open temporary file: dataset %1.").arg(dataSet->id);
TERRAMA2_LOG_ERROR() << errMsg;
throw DataAccessException() << ErrorDescription(errMsg);
}
file.readLine();//ignore first line
tempFile.write(file.readLine()); //headers line
//ignore third and fourth lines
file.readLine();
file.readLine();
//read all file
tempFile.write(file.readAll()); //headers line
//update file path
std::string tempUri = "file://"+tempBaseDir.path().toStdString();
file.close();
tempFile.close();
auto dataSeries = terrama2::core::DataAccessorFile::getSeries(tempUri, filter, dataSet);
return dataSeries;
}
示例15: doBasicTests
void Tests::basicTests()
{
// Some basic tests to save our COMBINE archive either directly or to a
// different file and checking that its contents is sound
QString otherFileName = OpenCOR::Core::temporaryFileName();
doBasicTests();
doBasicTests(otherFileName);
// Check that we can load our other COMBINE archive and save it in yet
// another file
OpenCOR::COMBINESupport::CombineArchive otherCombineArchive(otherFileName);
QString yetAnotherFileName = OpenCOR::Core::temporaryFileName();
QVERIFY(otherCombineArchive.load());
QVERIFY(otherCombineArchive.isValid());
QVERIFY(otherCombineArchive.save(yetAnotherFileName));
// Unzip our two COMBINE archives and make sure that their contents is the
// same
// Note: the original plan was to check that the SHA-1 value of the two
// files was the same, but the fact is that the ZIP file format
// contains various date and time information, so the SHA-1 value of
// two files may be different...
QTemporaryDir temporaryDir;
QString otherDir = temporaryDir.path()+"/otherDir";
QString yetAnotherDir = temporaryDir.path()+"/yetAnotherDir";
OpenCOR::ZIPSupport::QZipReader otherZipReader(otherFileName);
OpenCOR::ZIPSupport::QZipReader yetAnotherZipReader(yetAnotherFileName);
QVERIFY(otherZipReader.extractAll(otherDir));
QVERIFY(yetAnotherZipReader.extractAll(yetAnotherDir));
QDirIterator dirIterator(otherDir, QStringList() << "*",
QDir::Files, QDirIterator::Subdirectories);
while (dirIterator.hasNext()) {
QString otherFileName = dirIterator.next();
QString yetAnotherFileName = otherFileName.replace(otherDir, yetAnotherDir);
QByteArray otherFileContents;
QByteArray yetAnotherFileContents;
QVERIFY(OpenCOR::Core::readFileContentsFromFile(otherFileName, otherFileContents));
QVERIFY(OpenCOR::Core::readFileContentsFromFile(yetAnotherFileName, yetAnotherFileContents));
QCOMPARE(OpenCOR::Core::sha1(otherFileContents),
OpenCOR::Core::sha1(yetAnotherFileContents));
}
// Clean up after ourselves
QFile::remove(otherFileName);
QFile::remove(yetAnotherFileName);
}