当前位置: 首页>>代码示例>>C++>>正文


C++ QTemporaryFile::write方法代码示例

本文整理汇总了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;
}
开发者ID:xjohncz,项目名称:qt5,代码行数:34,代码来源:qtemporaryfile.cpp

示例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;
}
开发者ID:Xekyo,项目名称:bitcoin,代码行数:27,代码来源:paymentservertests.cpp

示例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));
            };
        };
    };
}
开发者ID:cheliequan,项目名称:qt-virt-manager,代码行数:33,代码来源:snapshot_action_dialog.cpp

示例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;
}
开发者ID:kenya888,项目名称:qt-virt-manager,代码行数:28,代码来源:storage_pool_control_thread.cpp

示例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;
}
开发者ID:RealworldSystems,项目名称:Quantum-GIS,代码行数:59,代码来源:qgsremotedatasourcebuilder.cpp

示例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
        }
开发者ID:RostaTasha,项目名称:xpiks,代码行数:18,代码来源:metadatareadingworker.cpp

示例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;
}
开发者ID:KDE,项目名称:okular,代码行数:57,代码来源:epubdocument.cpp

示例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();
  }
}
开发者ID:rrnntt,项目名称:plugins,代码行数:14,代码来源:TableLoader.cpp

示例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);
}
开发者ID:TurBoss,项目名称:makoureactor,代码行数:11,代码来源:GZIP.cpp

示例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;
    }
开发者ID:project-renard-survey,项目名称:utopia-documents-mirror,代码行数:54,代码来源:pdf_parser.cpp

示例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);
}
开发者ID:m4r71n,项目名称:CopyQ,代码行数:12,代码来源:configtabappearance.cpp

示例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();
}
开发者ID:,项目名称:,代码行数:12,代码来源:

示例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);
}
开发者ID:UIKit0,项目名称:qt-creator,代码行数:52,代码来源:iosdeploystep.cpp

示例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;
}
开发者ID:benklop,项目名称:qt-virt-manager,代码行数:51,代码来源:storage_pool_control_thread.cpp

示例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;
}
开发者ID:jcan87,项目名称:gaia,代码行数:14,代码来源:svmpredict.cpp


注:本文中的QTemporaryFile::write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。