本文整理汇总了C++中QTemporaryFile::write方法的典型用法代码示例。如果您正苦于以下问题:C++ QTemporaryFile::write方法的具体用法?C++ QTemporaryFile::write怎么用?C++ QTemporaryFile::write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTemporaryFile
的用法示例。
在下文中一共展示了QTemporaryFile::write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: handleRequest
static SendCoinsRecipient handleRequest(PaymentServer* server, std::vector<unsigned char>& data)
{
RecipientCatcher sigCatcher;
QObject::connect(server, SIGNAL(receivedPaymentRequest(SendCoinsRecipient)),
&sigCatcher, SLOT(getRecipient(SendCoinsRecipient)));
// Write data to a temp file:
QTemporaryFile f;
f.open();
f.write((const char*)&data[0], data.size());
f.close();
// Create a QObject, install event filter from PaymentServer
// and send a file open event to the object
QObject object;
object.installEventFilter(server);
QFileOpenEvent event(f.fileName());
// If sending the event fails, this will cause sigCatcher to be empty,
// which will lead to a test failure anyway.
QCoreApplication::sendEvent(&object, &event);
QObject::disconnect(server, SIGNAL(receivedPaymentRequest(SendCoinsRecipient)),
&sigCatcher, SLOT(getRecipient(SendCoinsRecipient)));
// Return results from sigCatcher
return sigCatcher.recipient;
}
示例3: showSnapsotXMLDesc
void SnapshotActionDialog::showSnapsotXMLDesc()
{
if ( snapshotTree->currentIndex().isValid() ) {
TreeItem *item = static_cast<TreeItem*>(
snapshotTree->currentIndex().internalPointer());
if ( nullptr!=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 ( nullptr!=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));
};
};
};
}
示例4: getStoragePoolXMLDesc
Result StoragePoolControlThread::getStoragePoolXMLDesc()
{
Result result;
QString name = task.object;
bool read = false;
char *Returns = NULL;
virStoragePoolPtr storagePool = virStoragePoolLookupByName(task.sourceConn, name.toUtf8().data());
if ( storagePool!=NULL ) {
Returns = (virStoragePoolGetXMLDesc(storagePool, VIR_STORAGE_XML_INACTIVE));
if ( Returns==NULL ) sendConnErrors();
else read = true;
virStoragePoolFree(storagePool);
} else 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;
}
示例5: vectorLayerFromRemoteVDS
QgsVectorLayer* QgsRemoteDataSourceBuilder::vectorLayerFromRemoteVDS( const QDomElement& remoteVDSElem, const QString& layerName, QList<QTemporaryFile*>& filesToRemove, QList<QgsMapLayer*>& layersToRemove, bool allowCaching ) const
{
QString providerString;
QString formatString = remoteVDSElem.attribute( "format" );
if ( formatString.compare( "gml", Qt::CaseInsensitive ) == 0 )
{
providerString = "WFS";
}
else
{
providerString = formatString;
}
//load file with QgsHttpTransaction
QByteArray fileContents;
QString uri = remoteVDSElem.text();
QgsVectorLayer* vl = 0;
if ( loadData( uri, fileContents ) != 0 )
{
return 0;
}
//store content into temporary file
QTemporaryFile* tmpFile = new QTemporaryFile();
if ( tmpFile->open() )
{
tmpFile->write( fileContents );
tmpFile->flush();
}
else
{
delete tmpFile;
return 0;
}
//create vector layer
//SOS has a special datasource key...
if ( formatString.compare( "SOS", Qt::CaseInsensitive ) == 0 )
{
QString url = "url=" + tmpFile->fileName() + " method=FILE xml=";
vl = new QgsVectorLayer( url, layerNameFromUri( tmpFile->fileName() ), providerString );
}
else
{
vl = new QgsVectorLayer( tmpFile->fileName(), layerNameFromUri( tmpFile->fileName() ), providerString );
}
if ( !( vl->isValid() ) )
{
QgsMapServerLogger::instance()->printMessage( "vl is not valid" );
}
layersToRemove.push_back( vl );
filesToRemove.push_back( tmpFile );
return vl;
}
示例6: process
void MetadataReadingWorker::process() {
bool success = false;
initWorker();
QTemporaryFile argumentsFile;
if (argumentsFile.open()) {
LOG_INFO << "Created arguments file" << argumentsFile.fileName();
QStringList exiftoolArguments = createArgumentsList();
foreach (const QString &line, exiftoolArguments) {
argumentsFile.write(line.toUtf8());
#ifdef Q_OS_WIN
argumentsFile.write("\r\n");
#else
argumentsFile.write("\n");
#endif
}
示例7: loadResource
QVariant EpubDocument::loadResource(int type, const QUrl &name)
{
int size;
char *data;
QString fileInPath = mCurrentSubDocument.resolved(name).path();
// Get the data from the epub file
size = epub_get_data(mEpub, fileInPath.toUtf8().constData(), &data);
QVariant resource;
if (data) {
switch(type) {
case QTextDocument::ImageResource:{
QImage img = QImage::fromData((unsigned char *)data, size);
const int maxHeight = maxContentHeight();
const int maxWidth = maxContentWidth();
if(img.height() > maxHeight)
img = img.scaledToHeight(maxHeight);
if(img.width() > maxWidth)
img = img.scaledToWidth(maxWidth);
resource.setValue(img);
break;
}
case QTextDocument::StyleSheetResource: {
QString css = QString::fromUtf8(data);
checkCSS(css);
resource.setValue(css);
break;
}
case EpubDocument::MovieResource: {
QTemporaryFile *tmp = new QTemporaryFile(QStringLiteral("%1/okrXXXXXX").arg(QDir::tempPath()),this);
if(!tmp->open()) qCWarning(OkularEpuDebug) << "EPUB : error creating temporary video file";
if(tmp->write(data,size) == -1) qCWarning(OkularEpuDebug) << "EPUB : error writing data" << tmp->errorString();
tmp->flush();
resource.setValue(tmp->fileName());
break;
}
case EpubDocument::AudioResource: {
QByteArray ba(data,size);
resource.setValue(ba);
break;
}
default:
resource.setValue(QString::fromUtf8(data));
break;
}
free(data);
}
// add to cache
addResource(type, name, resource);
return resource;
}
示例8: load
/**
* Called when data become available
*/
void TableLoader::load( const QByteArray& data)
{
QTemporaryFile file;
if (file.open()) {
// file.fileName() returns the unique file name
file.write( data );
file.close();
m_workspace->loadAscii( file.fileName().toStdString() );
m_workspace->modified();
}
}
示例9: decompress
QByteArray GZIP::decompress(const char *data, int size, int decSize, Strategy strategy)
{
QTemporaryFile temp;
if(!temp.open()) {
return QByteArray();
}
temp.write(data, size);
temp.close();
return decompress(temp.fileName(), decSize, strategy);
}
示例10: parse
// Parse!
Node* PDFParser::parse(Parser::Context& ctx, QIODevice& stream_) const
{
QTemporaryFile tmp;
// Ensure valid stream
if (!stream_.isOpen() || !stream_.isReadable())
{
ctx.setErrorCode(StreamError);
ctx.setMessage("Invalid Stream");
}
// Ensure not empty stream
if (stream_.atEnd())
{
ctx.setErrorCode(StreamEmpty);
ctx.setMessage("Empty Stream");
}
QFile * file = dynamic_cast< QFile * >(&stream_);
// Ensure of type file
if (file == 0)
{
// Save to temporary file FIXME
tmp.open();
tmp.write(stream_.readAll());
tmp.close();
tmp.open();
file = &tmp;
tmp.setAutoRemove(false);
}
QString pdfFile = file->fileName();
Node * c_Document = UtopiaDomain.term("Document");
Node * authority = Utopia::createAuthority();
Node * model = Utopia::createNode(authority, c_Document);
authority->relations(Utopia::UtopiaSystem.hasPart).append(model);
QString fileName = pdfFile;
model->attributes.set("papyro:pdfFile", fileName);
Spine::DocumentHandle doc = Papyro::DocumentFactory::load(model);
// If failed to open
if (!doc) {
ctx.setErrorCode(SyntaxError);
ctx.setMessage("Unknown file format");
}
return authority;
}
示例11: onThemeModified
void ConfigTabAppearance::onThemeModified(const QByteArray &bytes)
{
QTemporaryFile tmpfile;
if ( !openTemporaryFile(&tmpfile, ".ini") )
return;
tmpfile.write(bytes);
tmpfile.flush();
QSettings settings(tmpfile.fileName(), QSettings::IniFormat);
loadTheme(settings);
}
示例12: write
void tst_QTemporaryFile::write()
{
QByteArray data("OLE\nOLE\nOLE");
QTemporaryFile file;
QVERIFY(file.open());
QCOMPARE((int)file.write(data), data.size());
file.reset();
QFile compare(file.fileName());
compare.open(QIODevice::ReadOnly);
QCOMPARE(compare.readAll() , data);
file.close();
}
示例13: checkProvisioningProfile
void IosDeployStep::checkProvisioningProfile()
{
IosDevice::ConstPtr device = iosdevice();
if (device.isNull())
return;
Utils::FileName provisioningFilePath = Utils::FileName::fromString(appBundle());
provisioningFilePath.appendPath(QLatin1String("embedded.mobileprovision"));
// the file is a signed plist stored in DER format
// we simply search for start and end of the plist instead of decoding the DER payload
if (!provisioningFilePath.exists())
return;
QFile provisionFile(provisioningFilePath.toString());
if (!provisionFile.open(QIODevice::ReadOnly))
return;
QByteArray provisionData = provisionFile.readAll();
int start = provisionData.indexOf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
int end = provisionData.indexOf("</plist>");
if (start == -1 || end == -1)
return;
end += 8;
QTemporaryFile f;
if (!f.open())
return;
f.write(provisionData.mid(start, end - start));
f.flush();
QSettings provisionPlist(f.fileName(), QSettings::NativeFormat);
if (!provisionPlist.contains(QLatin1String("ProvisionedDevices")))
return;
QStringList deviceIds = provisionPlist.value(QLatin1String("ProvisionedDevices")).toStringList();
QString targetId = device->uniqueDeviceID();
foreach (const QString &deviceId, deviceIds) {
if (deviceId == targetId)
return;
}
m_expectFail = true;
QString provisioningProfile = provisionPlist.value(QLatin1String("Name")).toString();
QString provisioningUid = provisionPlist.value(QLatin1String("UUID")).toString();
Task task(Task::Warning,
tr("The provisioning profile \"%1\" (%2) used to sign the application "
"does not cover the device %3 (%4). Deployment to it will fail.")
.arg(provisioningProfile, provisioningUid, device->displayName(),
targetId),
Utils::FileName(), /* filename */
-1, /* line */
ProjectExplorer::Constants::TASK_CATEGORY_COMPILE);
emit addTask(task);
}
示例14: getStoragePoolXMLDesc
QStringList StoragePoolControlThread::getStoragePoolXMLDesc()
{
QStringList result;
QString name = args.first();
/*
virStoragePoolPtr *storagePool;
unsigned int flags = VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE |
VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE;
int ret = virConnectListAllStoragePools( currWorkConnect, &storagePool, flags);
if ( ret<0 ) {
sendConnErrors();
free(storagePool);
return result;
};
//qDebug()<<QString(virConnectGetURI(currWorkConnect));
int i = 0;
*/
bool read = false;
char *Returns = NULL;
/*
while ( storagePool[i] != NULL ) {
QString currNetName = QString( virStoragePoolGetName(storagePool[i]) );
if ( !read && currNetName==name ) {
Returns = (virStoragePoolGetXMLDesc(storagePool[i], VIR_STORAGE_XML_INACTIVE));
if ( Returns==NULL ) sendGlobalErrors();
else read = true;
};
virStoragePoolFree(storagePool[i]);
i++;
};
free(storagePool);
*/
virStoragePoolPtr storagePool = virStoragePoolLookupByName(currWorkConnect, name.toUtf8().data());
if ( storagePool!=NULL ) {
Returns = (virStoragePoolGetXMLDesc(storagePool, VIR_STORAGE_XML_INACTIVE));
if ( Returns==NULL ) sendConnErrors();
else read = true;
virStoragePoolFree(storagePool);
} else 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.append(f.fileName());
f.close();
free(Returns);
result.append(QString("'<b>%1</b>' StoragePool %2 XML'ed").arg(name).arg((read)?"":"don't"));
return result;
}
示例15: loadModel
struct svm_model* SVMPredict::loadModel() const {
QTemporaryFile modelFile;
modelFile.open();
QString filename = modelFile.fileName(); // need to keep the filename while it's open
modelFile.write(_modelData.constData());
modelFile.close();
struct svm_model* model = svm_load_model(filename.toUtf8().constData());
if (!model) {
throw GaiaException("SVMPredict: could not load model");
}
return model;
}