本文整理汇总了C++中QTemporaryDir::path方法的典型用法代码示例。如果您正苦于以下问题:C++ QTemporaryDir::path方法的具体用法?C++ QTemporaryDir::path怎么用?C++ QTemporaryDir::path使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTemporaryDir
的用法示例。
在下文中一共展示了QTemporaryDir::path方法的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: fstabFile
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: 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);
}
示例6: loadFromXMIFile
bool Import_Argo::loadFromXMIFile(const KZip &zipFile, const QString &fileName)
{
const KArchiveFile *file = static_cast<const KArchiveFile*>(zipFile.directory()->entry(fileName));
if (!file)
return false;
#if QT_VERSION >= 0x050000
QTemporaryDir tmpDir;
#else
KTempDir tmpDir;
#endif
tmpDir.setAutoRemove(true);
#if QT_VERSION >= 0x050000
file->copyTo(tmpDir.path());
QFile xmiFile(tmpDir.path() + QLatin1Char('/') + file->name());
#else
file->copyTo(tmpDir.name());
QFile xmiFile(tmpDir.name() + file->name());
#endif
if(!xmiFile.open(QIODevice::ReadOnly)) {
return false;
}
return UMLApp::app()->document()->loadFromXMI(xmiFile, 0);
}
示例7: basicTests
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")));
}
示例8: testMultipleFolders
void TestBuddies::testMultipleFolders()
{
/* 4. Multiple folders:
Activate buddy option
Open f/a.cpp f/xyz.cpp g/a.h
Verify g/a.h is activated
Verify order (f/a.cpp f/xyz.cpp g/a.h)*/
enableBuddies();
enableOpenAfterCurrent();
QTemporaryDir tempDirA;
QDir dirA(tempDirA.path());
createFile(dirA, "a.cpp");
createFile(dirA, "x.cpp");
QTemporaryDir tempDirB;
QDir dirB(tempDirB.path());
createFile(dirB, "a.h"); // different folder => not dirA/a.cpp's buddy!
m_documentController->openDocument(QUrl::fromLocalFile(dirA.filePath("a.cpp")));
m_documentController->openDocument(QUrl::fromLocalFile(dirA.filePath("x.cpp")));
m_documentController->openDocument(QUrl::fromLocalFile(dirB.filePath("a.h")));
Sublime::Area *area = m_uiController->activeArea();
Sublime::AreaIndex* areaIndex = area->indexOf(toSublimeWindow(m_uiController->activeMainWindow())->activeView());
verifyFilename(areaIndex->views().value(0), "a.cpp");
verifyFilename(areaIndex->views().value(1), "x.cpp");
verifyFilename(areaIndex->views().value(2), "a.h");
verifyFilename(toSublimeWindow(m_uiController->activeMainWindow())->activeView(), "a.h");
}
示例9: doBasicTests
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))));
}
}
示例10: DataAccessException
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;
}
示例11: unpackArchive
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;
}
}
}
示例12: basicTests
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);
}
示例13: testDUChainBuddyVote
void TestBuddies::testDUChainBuddyVote()
{
/*
* Test that the DUChain buddy system finds the buddy file with the most
* common declarations/definitions
*/
enableBuddies();
enableOpenAfterCurrent();
QTemporaryDir dirA;
TestFile header("void func1();\nvoid func2();\nvoid func3();\n", "h", nullptr, dirA.path());
TestFile source1(
QString("#include \"%1\"\nvoid func1() {}\n").arg(header.url().toUrl().fileName()),
"cpp", nullptr, dirA.path()
);
TestFile source2(
QString("#include \"%1\"\nvoid func2() {}\nvoid func3() {}\n").arg(header.url().toUrl().fileName()),
"cpp", nullptr, dirA.path()
);
// -> buddy(header) should resolve to source2
header.parseAndWait();
source1.parseAndWait();
source2.parseAndWait();
// Test IBuddyDocumentFinder::getPotentialBuddies()
QMimeDatabase db;
IBuddyDocumentFinder* sourceBuddyFinder = IBuddyDocumentFinder::finderForMimeType(db.mimeTypeForUrl(source1.url().toUrl()).name());
QVector< QUrl > sourceBuddies = sourceBuddyFinder->getPotentialBuddies(source1.url().toUrl());
if (!sourceBuddies.contains(header.url().toUrl())) {
qDebug() << "got source buddies: " << sourceBuddies;
qDebug() << "expected: " << header.url().toUrl();
QFAIL("Failed to find buddy for source file");
}
IBuddyDocumentFinder* source2BuddyFinder = IBuddyDocumentFinder::finderForMimeType(db.mimeTypeForUrl(source2.url().toUrl()).name());
QVector< QUrl > source2Buddies = source2BuddyFinder->getPotentialBuddies(source2.url().toUrl());
if (!source2Buddies.contains(header.url().toUrl())) {
qDebug() << "got source2 buddies: " << source2Buddies;
qDebug() << "expected: " << header.url().toUrl();
QFAIL("Failed to find buddy for source2 file");
}
IBuddyDocumentFinder* headerBuddyFinder = IBuddyDocumentFinder::finderForMimeType(db.mimeTypeForUrl(header.url().toUrl()).name());
QVector< QUrl > headerBuddies = headerBuddyFinder->getPotentialBuddies(header.url().toUrl());
if (!headerBuddies.contains(source2.url().toUrl())) {
qDebug() << "got header buddies: " << headerBuddies;
qDebug() << "expected: " << source2.url().toUrl();
QFAIL("Failed to find buddy for header file");
}
QVERIFY2(!headerBuddies.contains(source1.url().toUrl()), "header buddy list contains weaker file");
}
示例14: testFileClosedAfterWrite
void KInotifyTest::testFileClosedAfterWrite()
{
QTemporaryDir dir;
touchFile(dir.path() + QLatin1String("/file"));
KInotify kn(nullptr /*no config*/);
kn.addWatch(dir.path(), KInotify::EventAll);
QSignalSpy spy(&kn, SIGNAL(closedWrite(QString)));
touchFile(dir.path() + QLatin1String("/file"));
QVERIFY(spy.wait());
QCOMPARE(spy.count(), 1);
QCOMPARE(spy.at(0).first().toString(), QString(dir.path() + QLatin1String("/file")));
}
示例15: testWritePolygonZFile
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);
}