本文整理汇总了C++中QTemporaryFile::setAutoRemove方法的典型用法代码示例。如果您正苦于以下问题:C++ QTemporaryFile::setAutoRemove方法的具体用法?C++ QTemporaryFile::setAutoRemove怎么用?C++ QTemporaryFile::setAutoRemove使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTemporaryFile
的用法示例。
在下文中一共展示了QTemporaryFile::setAutoRemove方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onPlot
void MainWindow::onPlot()
{
// Plot with gnuplot
QTemporaryFile dataFile;
QTemporaryFile scriptFile;
QString date=QLocale::system().dateFormat(QLocale::ShortFormat);
QString time="%H:%M:%S";
date.replace("dd","%d");
date.replace("MM","%m");
date.replace("yy","%y");
if (dataFile.open() && scriptFile.open())
{
dataFile.setAutoRemove(false);
scriptFile.setAutoRemove(false);
QTextStream out(&dataFile);
QString data = GetDataAsCsv();
data.replace(" ", "_");
out << data;
QTextStream scriptOut(&scriptFile);
scriptOut << "set xdata time\n"
<< "set timefmt" << " " << "\"" << date << "_" << time <<"\"\n"
<< "set grid\n"
<< "plot '" << dataFile.fileName() << "' u 1:2 title \"Temperature\" with linespoints lt 4 lw 2\n"
<< "pause -1\n";
QProcess *gnuplot = new QProcess();
QStringList arguments(scriptFile.fileName());
arguments << "-";
gnuplot->start("gnuplot", arguments);
gnuplot->waitForStarted();
// gnuplot->close();
}
}
示例2: setupOnData
void SeqLenAnalysis::setupOnData(const TDSVector& a_data, SeqLenAnalysis& a_instance)
{
QTemporaryFile tmpFileOut;
QTemporaryFile tmpFileIn;
tmpFileOut.setAutoRemove(true);
tmpFileOut.open();
tmpFileIn.setAutoRemove(true);
tmpFileIn.open();
{
std::ofstream outputFile(tmpFileOut.fileName().toStdString().c_str());
TDS prev = 0;
for (auto sample: a_data) {
outputFile << sample - prev << "\n";
prev = sample;
}
}
a_instance.ui->seqLenTable->setHorizontalHeaderItem(0, new QTableWidgetItem("value"));
a_instance.ui->seqLenTable->setHorizontalHeaderItem(1, new QTableWidgetItem("n"));
a_instance.ui->seqLenTable->setHorizontalHeaderItem(2, new QTableWidgetItem("mean"));
a_instance.ui->seqLenTable->setHorizontalHeaderItem(3, new QTableWidgetItem("stddev"));
a_instance.ui->seqLenTable->setHorizontalHeaderItem(4, new QTableWidgetItem("min"));
a_instance.ui->seqLenTable->setHorizontalHeaderItem(5, new QTableWidgetItem("max"));
std::cerr << (QString("../tool/bitcracker.native seqlen ") + tmpFileOut.fileName() + " >" + tmpFileIn.fileName()).toStdString().c_str() << std::endl;
system((QString("../tool/bitcracker.native seqlen ") + tmpFileOut.fileName() + " >" + tmpFileIn.fileName()).toStdString().c_str());
std::ifstream inputFile(tmpFileIn.fileName().toStdString().c_str());
while (inputFile) {
std::string str;
if (std::getline(inputFile, str)) {
std::stringstream st(str);
int bit;
int k;
int n;
double centroid;
double mean;
double stddev;
double min;
double max;
st >> k >> bit >> centroid >> n >> mean;
stddev = readNanOrDouble(st);
st >> min >> max;
if (0 && !st.good()) {
std::cerr << "Failed to read\n";
} else {
Data d;
d.bit = bit;
d.n = n;
d.mean = mean;
d.stddev = stddev;
d.min = min;
d.max = max;
a_instance.add(k, d);
}
}
}
a_instance.redraw();
}
示例3: 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();
}
示例4: projectRunHook
void QTestLibPlugin::projectRunHook(ProjectExplorer::Project *proj)
{
return; //NBS TODO QTestlibplugin
if (!proj)
return;
m_projectDirectory.clear();
//NBS proj->setExtraApplicationRunArguments(QStringList());
//NBS proj->setCustomApplicationOutputHandler(0);
const QVariant config; //NBS = proj->projectProperty(ProjectExplorer::Constants::P_CONFIGVAR);
if (!config.toStringList().contains(QLatin1String("qtestlib")))
return;
{
QTemporaryFile tempFile;
tempFile.setAutoRemove(false);
tempFile.open();
m_outputFile = tempFile.fileName();
}
//NBS proj->setCustomApplicationOutputHandler(this);
//NBS proj->setExtraApplicationRunArguments(QStringList() << QLatin1String("-xml") << QLatin1String("-o") << m_outputFile);
// const QString proFile = proj->fileName();
// const QFileInfo fi(proFile);
// if (QFile::exists(fi.absolutePath()))
// m_projectDirectory = fi.absolutePath();
}
示例5: 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"));
}
}
示例6: lock
bool MountProtector::lock(const QString& path) {
if (path.isEmpty()) {
qmlInfo(this) << "Cannot lock an empty path";
return false;
}
QString p = QString("%1%2.cameraplus_tmp_XXXXXX").arg(path).arg(QDir::separator());
QTemporaryFile *file = new QTemporaryFile(p);
file->setAutoRemove(true);
if (!file->open()) {
qmlInfo(this) << "Failed to lock" << file->errorString();
delete file;
file = 0;
return false;
}
if (!QFile::remove(file->fileName())) {
qmlInfo(this) << "Failed to remove temporarily file" << file->fileName();
}
m_locks.insert(path, file);
return true;
}
示例7: 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;
}
示例8: convertTemplate
void ReportGenerator::convertTemplate( const QString& templ )
{
// qDebug() << "Report BASE:\n" << templ;
if ( ! templ.isEmpty() ) {
QTemporaryFile temp;
temp.setAutoRemove( false );
if ( temp.open() ) {
QTextStream s(&temp);
// The following explicit coding settings were needed for Qt 4.7.3, former Qt versions
// seemed to default on UTF-8. Try to comment the following two lines for older Qt versions
// if needed and see if the trml file on the disk still is UTF-8 encoded.
QTextCodec *codec = QTextCodec::codecForName("UTF-8");
s.setCodec( codec );
s << templ;
} else {
// qDebug () << "ERROR: Could not open temporar file";
}
// qDebug () << "Wrote rml to " << temp.fileName();
QString dId( mDocId );
if ( mDocId.isEmpty() ) {
dId = ArchiveMan::self()->documentID( mArchId );
}
runTrml2Pdf( temp.fileName(), dId, mArchId.toString() );
}
}
示例9: 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;
}
示例10: uploadClipboard
/**
* Puush upload the clipboard
* @brief Systray::uploadClipboard
*/
void Systray::uploadClipboard()
{
if (!isLoggedIn())
return;
QString text = QApplication::clipboard()->text();
// just look for "file://" and upload it, else just upload the text itself as a text file
if (text.isEmpty()) {
return;
} else if (text.contains("file://")) {
Upload *u = new Upload(text);
connect(u, SIGNAL(started()), this, SLOT(puushStarted()));
connect(u, SIGNAL(finished(QString)), this, SLOT(puushDone(QString)));
} else {
QTemporaryFile file;
// The file is deleted too soon before it can be uploaded since the upload is in a callback.
// Since it's in a temporary directory it'll get deleted eventually anyways...
file.setAutoRemove(false);
if (file.open()) {
file.write(text.toLocal8Bit().data());
Upload *u = new Upload(file.fileName());
connect(u, SIGNAL(started()), this, SLOT(puushStarted()));
connect(u, SIGNAL(finished(QString)), this, SLOT(puushDone(QString)));
} else {
trayIcon->showMessage("puush-qt", tr("Error opening temporary file for writing!"),
QSystemTrayIcon::Critical);
}
}
}
示例11: checkConsistency
void KDocumentTextBuffer::checkConsistency()
{
QString bufferContents = codec()->toUnicode( slice(0, length())->text() );
QString documentContents = kDocument()->text();
if ( bufferContents != documentContents ) {
KUrl url = kDocument()->url();
kDocument()->setModified(false);
kDocument()->setReadWrite(false);
m_aboutToClose = true;
QTemporaryFile f;
f.setAutoRemove(false);
f.open();
f.close();
kDocument()->saveAs(f.fileName());
KDialog* dialog = new KDialog;
dialog->setButtons(KDialog::Ok | KDialog::Cancel);
QLabel* label = new QLabel(i18n("Sorry, an internal error occurred in the text synchronization component.<br>"
"You can try to reload the document or disconnect."));
label->setWordWrap(true);
dialog->setMainWidget(label);
dialog->button(KDialog::Ok)->setText(i18n("Reload document"));
dialog->button(KDialog::Cancel)->setText(i18n("Disconnect"));
DocumentReopenHelper* helper = new DocumentReopenHelper(url, kDocument());
connect(dialog, SIGNAL(accepted()), helper, SLOT(reopen()));
// We must not use exec() here, since that will create a nested event loop,
// which might handle incoming network events. This can easily get very messy.
dialog->show();
}
}
示例12: showSnapsotXMLDesc
void SnapshotActionDialog::showSnapsotXMLDesc()
{
if ( snapshotTree->currentIndex().isValid() ) {
TreeItem *item = static_cast<TreeItem*>(
snapshotTree->currentIndex().internalPointer());
if ( NULL!=item ) {
// flags: extra flags; not used yet, so callers should always pass 0
virDomainSnapshotPtr snapShot =
virDomainSnapshotLookupByName(
domain, item->data(0).toByteArray().data(), 0);
char *xmlDesc = virDomainSnapshotGetXMLDesc(snapShot, 0);
if ( NULL!=xmlDesc ) {
QTemporaryFile f;
f.setAutoRemove(false);
f.setFileTemplate(
QString("%1%2XML_Desc-XXXXXX.xml")
.arg(QDir::tempPath())
.arg(QDir::separator()));
bool read = f.open();
if (read) f.write(xmlDesc);
QString xml = f.fileName();
f.close();
free(xmlDesc);
QDesktopServices::openUrl(QUrl(xml));
};
};
};
}
示例13: 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;
}
示例14: 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;
}
示例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";
}