本文整理汇总了C++中QTemporaryFile::close方法的典型用法代码示例。如果您正苦于以下问题:C++ QTemporaryFile::close方法的具体用法?C++ QTemporaryFile::close怎么用?C++ QTemporaryFile::close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTemporaryFile
的用法示例。
在下文中一共展示了QTemporaryFile::close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getReport
QFileInfoList CDspHaClusterHelper::getReport()
{
QFileInfoList output;
QFileInfo p("/usr/bin/vstorage-make-report");
if (!p.exists())
return output;
QDir d("/etc/vstorage/clusters");
if (!d.exists())
return output;
QStringList a = d.entryList(QDir::NoDotAndDotDot | QDir::Dirs);
foreach (QString x, a)
{
QTemporaryFile t;
t.setFileTemplate(QString("%1/pstorage.%2.XXXXXX.tgz")
.arg(QDir::tempPath()).arg(x));
if (!t.open())
{
WRITE_TRACE(DBG_FATAL, "QTemporaryFile::open() error: %s",
QSTR2UTF8(t.errorString()));
continue;
}
QString b, c = QString("%1 -f %2 \"%3\"").arg(p.filePath()).arg(t.fileName()).arg(x);
if (!HostUtils::RunCmdLineUtility(c, b, -1) || t.size() == 0)
{
t.close();
continue;
}
t.setAutoRemove(false);
output.append(QFileInfo(t.fileName()));
t.close();
}
示例2: jsonFile
void
FileStore::compressRide(RideFile*ride, QByteArray &data, QString name)
{
// compress via a temporary file
QTemporaryFile tempfile;
tempfile.open();
tempfile.close();
// write as json
QFile jsonFile(tempfile.fileName());
if (RideFileFactory::instance().writeRideFile(NULL, ride, jsonFile, "json") == true) {
// create a temp zip file
QTemporaryFile zipFile;
zipFile.open();
zipFile.close();
// add files using zip writer
QString zipname = zipFile.fileName();
ZipWriter writer(zipname);
// read the ride file back and add to zip file
jsonFile.open(QFile::ReadOnly);
writer.addFile(name, jsonFile.readAll());
jsonFile.close();
writer.close();
// now read in the zipfile
QFile zip(zipname);
zip.open(QFile::ReadOnly);
data = zip.readAll();
zip.close();
}
}
示例3: filewatchTest
void FileWatchUnitTest::filewatchTest()
{
QWARN("Unittest will take about 1 minute. Please wait.");
QCA::FileWatch watcher;
QCOMPARE( watcher.fileName(), QString() );
QSignalSpy spy( &watcher, SIGNAL(changed()) );
QVERIFY( spy.isValid() );
QCOMPARE( spy.count(), 0 );
QTemporaryFile *tempFile = new QTemporaryFile;
tempFile->open();
watcher.setFileName( tempFile->fileName() );
QCOMPARE( watcher.fileName(), tempFile->fileName() );
QTest::qWait(7000);
QCOMPARE( spy.count(), 0 );
tempFile->close();
QTest::qWait(7000);
QCOMPARE( spy.count(), 0 );
tempFile->open();
tempFile->write("foo");
tempFile->flush();
QTest::qWait(7000);
QCOMPARE( spy.count(), 1 );
tempFile->close();
QTest::qWait(7000);
QCOMPARE( spy.count(), 1 );
tempFile->open();
tempFile->write("foo");
tempFile->flush();
QTest::qWait(7000);
QCOMPARE( spy.count(), 2 );
tempFile->write("bar");
tempFile->flush();
QTest::qWait(7000);
QCOMPARE( spy.count(), 3 );
tempFile->close();
QTest::qWait(7000);
QCOMPARE( spy.count(), 3 );
delete tempFile;
QTest::qWait(7000);
QCOMPARE( spy.count(), 4 );
}
示例4: vectorLayerFromSentVDS
QgsVectorLayer* QgsSentDataSourceBuilder::vectorLayerFromSentVDS( const QDomElement& sentVDSElem, QList<QTemporaryFile*>& filesToRemove, QList<QgsMapLayer*>& layersToRemove ) const
{
if ( sentVDSElem.attribute( "format" ) == "GML" )
{
QTemporaryFile* tmpFile = new QTemporaryFile();
if ( tmpFile->open() )
{
filesToRemove.push_back( tmpFile ); //make sure the temporary file gets deleted after each request
QTextStream tempFileStream( tmpFile );
sentVDSElem.save( tempFileStream, 4 );
tmpFile->close();
}
else
{
return 0;
}
QgsVectorLayer* theVectorLayer = new QgsVectorLayer( tmpFile->fileName(), layerNameFromUri( tmpFile->fileName() ), "WFS" );
if ( !theVectorLayer || !theVectorLayer->isValid() )
{
QgsMSDebugMsg( "invalid maplayer" );
return 0;
}
QgsMSDebugMsg( "returning maplayer" );
layersToRemove.push_back( theVectorLayer ); //make sure the layer gets deleted after each request
if ( !theVectorLayer || !theVectorLayer->isValid() )
{
return 0;
}
return theVectorLayer;
}
return 0;
}
示例5: testAddItem
void AddCommandTest::testAddItem()
{
QTemporaryFile tempFile;
tempFile.setAutoRemove(false);
tempFile.open();
tempFile.write("Hello World!");
const char *args[6] = {
"akonadiclient",
"add",
"/res3",
tempFile.fileName().toLocal8Bit().data(),
"--base",
QDir::tempPath().toLocal8Bit().data()
};
tempFile.close();
KCmdLineArgs *parsedArgs = getParsedArgs(6, args);
AddCommand *command = new AddCommand(this);
int ret = command->init(parsedArgs);
QCOMPARE(ret, 0);
ret = runCommand(command);
QCOMPARE(ret, 0);
}
示例6: downloadFile
void downloadFile()
{
QTemporaryFile file;
file.setAutoRemove(false);
if (file.open()) {
const QString filename = file.fileName();
QInstaller::blockingWrite(&file, QByteArray(scLargeSize, '1'));
file.close();
DownloadFileTask fileTask(QLatin1String("file:///") + filename);
QFutureWatcher<FileTaskResult> watcher;
QSignalSpy started(&watcher, SIGNAL(started()));
QSignalSpy finished(&watcher, SIGNAL(finished()));
QSignalSpy progress(&watcher, SIGNAL(progressValueChanged(int)));
watcher.setFuture(QtConcurrent::run(&DownloadFileTask::doTask, &fileTask));
watcher.waitForFinished();
QTest::qWait(10); // Spin the event loop to deliver queued signals.
QCOMPARE(started.count(), 1);
QCOMPARE(finished.count(), 1);
FileTaskResult result = watcher.result();
QCOMPARE(watcher.future().resultCount(), 1);
QVERIFY(QFile(result.target()).exists());
QCOMPARE(file.size(), QFile(result.target()).size());
QCOMPARE(result.checkSum().toHex(), QByteArray("85304f87b8d90554a63c6f6d1e9cc974fbef8d32"));
}
}
示例7: process
void ExiftoolImageWritingWorker::process() {
Helpers::AsyncCoordinatorUnlocker unlocker(m_AsyncCoordinator);
Q_UNUSED(unlocker);
bool success = false;
initWorker();
QTemporaryFile jsonFile;
if (jsonFile.open()) {
LOG_INFO << "Serializing artworks to json" << jsonFile.fileName();
QJsonArray objectsToSave;
artworksToJsonArray(m_ItemsToWriteSnapshot, objectsToSave);
QJsonDocument document(objectsToSave);
jsonFile.write(document.toJson());
jsonFile.flush();
jsonFile.close();
int numberOfItems = (int)m_ItemsToWriteSnapshot.size();
QTemporaryFile argumentsFile;
if (argumentsFile.open()) {
QStringList exiftoolArguments = createArgumentsList(jsonFile.fileName());
foreach (const QString &line, exiftoolArguments) {
argumentsFile.write(line.toUtf8());
#ifdef Q_OS_WIN
argumentsFile.write("\r\n");
#else
argumentsFile.write("\n");
#endif
}
示例8: switch
/**
* Create a grouping file to extract detectors in dets. Option List - one group - one detector,
* Option Sum - one group which is a sum of the detectors
* If fname is empty create a temporary file
*/
DetXMLFile::DetXMLFile(const QList<int>& dets, Option opt, const QString& fname)
{
if (dets.empty())
{
m_fileName = "";
return;
}
if (fname.isEmpty())
{
QTemporaryFile mapFile;
mapFile.open();
m_fileName = mapFile.fileName() + ".xml";
mapFile.close();
m_delete = true;
}
else
{
m_fileName = fname;
m_delete = false;
}
switch(opt)
{
case Sum: makeSumFile(dets); break;
case List: makeListFile(dets); break;
}
}
示例9: testExportAsSinglePage
void testExportAsSinglePage()
{
// Same testcase as testVerticalScaling, for now
fillModel(1, 40);
Report report;
report.setReportMode(Report::SpreadSheet);
report.mainTable()->setAutoTableElement(AutoTableElement(&m_model));
report.scaleTo(1, 2); // must cram 40 rows into 2 page vertically
QFont font = QFont(QLatin1String(s_fontName));
font.setPointSize(86); // huge :)
report.setDefaultFont(font);
//QCOMPARE(report.numberOfPages(), 2);
//report.exportToFile( "testExportAsSinglePage.pdf" ); // for debugging
QTemporaryFile tempFile;
QVERIFY(tempFile.open());
const QString filename = tempFile.fileName();
tempFile.close();
const QSize size(1000, 2000);
bool ok = report.exportToImage( size, filename, "PNG" );
QVERIFY(ok);
QVERIFY(QFile::exists(filename));
QPixmap pix;
QVERIFY(pix.load(filename));
QCOMPARE(pix.size(), size);
QCOMPARE(report.mainTable()->pageRects()[0], QRect(0,0,1,40));
QVERIFY(report.mainTable()->lastAutoFontScalingFactor() > 0.9999);
// The only way to truly validate that it worked, though, is to open test-export.jpg and check...
QFile::remove(filename);
}
示例10: getStoragePoolXMLDesc
Result StoragePoolControlThread::getStoragePoolXMLDesc()
{
Result result;
QString name = task.object;
bool read = false;
char *Returns = NULL;
virStoragePoolPtr storagePool = virStoragePoolLookupByName(
*task.srcConnPtr, name.toUtf8().data());
if ( storagePool!=NULL ) {
Returns = (virStoragePoolGetXMLDesc(storagePool, VIR_STORAGE_XML_INACTIVE));
if ( Returns==NULL )
result.err = sendConnErrors();
else read = true;
virStoragePoolFree(storagePool);
} else
result.err = sendConnErrors();
QTemporaryFile f;
f.setAutoRemove(false);
f.setFileTemplate(QString("%1%2XML_Desc-XXXXXX.xml")
.arg(QDir::tempPath()).arg(QDir::separator()));
read = f.open();
if (read) f.write(Returns);
result.fileName.append(f.fileName());
f.close();
if ( Returns!=NULL ) free(Returns);
result.msg.append(QString("'<b>%1</b>' StoragePool %2 XML'ed")
.arg(name).arg((read)?"":"don't"));
result.name = name;
result.result = read;
return result;
}
示例11: runner
ProcessPtr
Process::execute(QString const &command,
QStringList const &args,
bool useTempFile) {
auto runner = [](QString const &commandToUse, QStringList const &argsToUse) {
auto pr = std::make_shared<Process>( commandToUse, argsToUse );
pr->run();
return pr;
};
if (!useTempFile)
return runner(command, args);
QTemporaryFile optFile;
if (!optFile.open())
throw ProcessX{ to_utf8(QY("Error creating a temporary file (reason: %1).").arg(optFile.errorString())) };
static const unsigned char utf8_bom[3] = {0xef, 0xbb, 0xbf};
optFile.write(reinterpret_cast<char const *>(utf8_bom), 3);
for (auto &arg : args)
optFile.write(QString{"%1\n"}.arg(arg).toUtf8());
optFile.close();
QStringList argsToUse;
argsToUse << QString{"@%1"}.arg(optFile.fileName());
return runner(command, argsToUse);
}
示例12: saveToFile
bool DownloadHandler::saveToFile(const QByteArray &replyData, QString &filePath)
{
QTemporaryFile *tmpfile = new QTemporaryFile;
if (!tmpfile->open()) {
delete tmpfile;
return false;
}
tmpfile->setAutoRemove(false);
filePath = tmpfile->fileName();
qDebug("Temporary filename is: %s", qPrintable(filePath));
if (m_reply->isOpen() || m_reply->open(QIODevice::ReadOnly)) {
tmpfile->write(replyData);
tmpfile->close();
// XXX: tmpfile needs to be deleted on Windows before using the file
// or it will complain that the file is used by another process.
delete tmpfile;
return true;
}
else {
delete tmpfile;
Utils::Fs::forceRemove(filePath);
}
return false;
}
示例13: zip
bool QgsArchive::zip( const QString &filename )
{
// create a temporary path
QTemporaryFile tmpFile;
tmpFile.open();
tmpFile.close();
// zip content
if ( ! QgsZipUtils::zip( tmpFile.fileName(), mFiles ) )
{
QString err = QObject::tr( "Unable to zip content" );
QgsMessageLog::logMessage( err, QStringLiteral( "QgsArchive" ) );
return false;
}
// remove existing zip file
if ( QFile::exists( filename ) )
QFile::remove( filename );
// save zip archive
if ( ! tmpFile.rename( filename ) )
{
QString err = QObject::tr( "Unable to save zip file '%1'" ).arg( filename );
QgsMessageLog::logMessage( err, QStringLiteral( "QgsArchive" ) );
return false;
}
// keep the zip filename
tmpFile.setAutoRemove( false );
return true;
}
示例14: tr
PageItem_LatexFrame::PageItem_LatexFrame(ScribusDoc *pa, double x, double y, double w, double h, double w2, QString fill, QString outline)
: PageItem_ImageFrame(pa, x, y, w, h, w2, fill, outline)
{
setUPixmap(Um::ILatexFrame);
AnName = tr("Render") + QString::number(m_Doc->TotalItems);
setUName(AnName);
imgValid = false;
m_usePreamble = true;
err = 0;
internalEditor = 0;
killed = false;
config = 0;
if (PrefsManager::instance()->latexConfigs().count() > 0)
setConfigFile(PrefsManager::instance()->latexConfigs()[0]);
latex = new QProcess();
connect(latex, SIGNAL(finished(int, QProcess::ExitStatus)),
this, SLOT(updateImage(int, QProcess::ExitStatus)));
connect(latex, SIGNAL(error(QProcess::ProcessError)),
this, SLOT(latexError(QProcess::ProcessError)));
latex->setProcessChannelMode(QProcess::MergedChannels);
QTemporaryFile *tempfile = new QTemporaryFile(QDir::tempPath() + "/scribus_temp_render_XXXXXX");
tempfile->open();
tempFileBase = getLongPathName(tempfile->fileName());
tempfile->setAutoRemove(false);
tempfile->close();
delete tempfile;
Q_ASSERT(!tempFileBase.isEmpty());
m_dpi = 0;
}
示例15: drawBitmap
void ScrPainter::drawBitmap(const libwpg::WPGBitmap& bitmap, double hres, double vres)
{
QImage image = QImage(bitmap.width(), bitmap.height(), QImage::Format_RGB32);
for(int x = 0; x < bitmap.width(); x++)
{
for(int y = 0; y < bitmap.height(); y++)
{
libwpg::WPGColor color = bitmap.pixel(x, y);
image.setPixel(x, y, qRgb(color.red, color.green, color.blue));
}
}
double w = (bitmap.rect.x2 - bitmap.rect.x1) * 72.0;
double h = (bitmap.rect.y2 - bitmap.rect.y1) * 72.0;
int z = m_Doc->itemAdd(PageItem::ImageFrame, PageItem::Unspecified, bitmap.rect.x1 * 72 + baseX, bitmap.rect.y1 * 72 + baseY, w, h, 1, m_Doc->itemToolPrefs().imageFillColor, m_Doc->itemToolPrefs().imageStrokeColor, true);
PageItem *ite = m_Doc->Items->at(z);
QTemporaryFile *tempFile = new QTemporaryFile(QDir::tempPath() + "/scribus_temp_wpg_XXXXXX.png");
tempFile->setAutoRemove(false);
tempFile->open();
QString fileName = getLongPathName(tempFile->fileName());
tempFile->close();
delete tempFile;
ite->isTempFile = true;
ite->isInlineImage = true;
image.setDotsPerMeterX ((int) (hres / 0.0254));
image.setDotsPerMeterY ((int) (vres / 0.0254));
image.save(fileName, "PNG");
m_Doc->loadPict(fileName, ite);
ite->setImageScalingMode(false, false);
ite->moveBy(m_Doc->currentPage()->xOffset(), m_Doc->currentPage()->yOffset());
finishItem(ite);
// qDebug() << "drawBitmap";
}