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


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

本文整理汇总了C++中QTemporaryFile::flush方法的典型用法代码示例。如果您正苦于以下问题:C++ QTemporaryFile::flush方法的具体用法?C++ QTemporaryFile::flush怎么用?C++ QTemporaryFile::flush使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QTemporaryFile的用法示例。


在下文中一共展示了QTemporaryFile::flush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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 );
    
}
开发者ID:fluxer,项目名称:qca,代码行数:55,代码来源:filewatchunittest.cpp

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

示例3: rasterLayerFromRemoteRDS

QgsRasterLayer* QgsRemoteDataSourceBuilder::rasterLayerFromRemoteRDS( const QDomElement& remoteRDSElem, const QString& layerName, QList<QTemporaryFile*>& filesToRemove, QList<QgsMapLayer*>& layersToRemove, bool allowCaching ) const
{
  QgsMSDebugMsg( "entering." );
  //load file with QgsHttpTransaction or QgsFtpTransaction
  QByteArray fileContents;
  QString uri = remoteRDSElem.text();

  QgsRasterLayer* rl = 0;
  if ( loadData( uri, fileContents ) != 0 )
  {
    return 0;
  }

  QTemporaryFile* tmpFile = new QTemporaryFile();
  if ( tmpFile->open() )
  {
    tmpFile->write( fileContents );
    tmpFile->flush();
  }
  else
  {
    QgsMSDebugMsg( "Error, creation of temp file failed" );
    delete tmpFile;
    return 0;
  }

  //create rasterlayer
  rl = new QgsRasterLayer( tmpFile->fileName(), layerNameFromUri( tmpFile->fileName() ) );
  layersToRemove.push_back( rl );
  filesToRemove.push_back( tmpFile );
  clearRasterSymbology( rl );
  return rl;
}
开发者ID:RealworldSystems,项目名称:Quantum-GIS,代码行数:33,代码来源:qgsremotedatasourcebuilder.cpp

示例4: removeUserChoice

static bool removeUserChoice(const QString & extension)
{
    QSettings RegCU("HKEY_CURRENT_USER", QSettings::NativeFormat);
    QString FileExtsKey = QString("Software/Microsoft/Windows/CurrentVersion/Explorer/FileExts/.") + extension;

    if(QSysInfo::WindowsVersion < QSysInfo::WV_VISTA){ //XP
        RegCU.remove(FileExtsKey + "/Progid");
        return true;
    }

    QTemporaryFile file;
    if (file.open()) {
        QTextStream out(&file);
        // Unlock Registry, make user 'everyone' can access 'UserChoice' completely.
        out << "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\." + extension + "\\UserChoice [7]";
        out.flush();
        file.flush();

        // win7 build-in tool, for user access changing. Require path argument encoded by Unicode. Chinese may cause problem.
        // Only return after execute completely.
        QProcess::execute(QString("regini.exe %1").arg(file.fileName()));

        /// Windows 7, only can remove "/UserChoice" if we own it. remove "/UserChoice/Progid" is forbidden.
        RegCU.remove(FileExtsKey + "/UserChoice");

        return true;
    }

    return false;

    // The QTemporaryFile destructor removes the temporary file
    // as it goes out of scope.
}
开发者ID:ckurdu,项目名称:ezviewer,代码行数:33,代码来源:fileassoc.cpp

示例5: csvImport

void TestImport::csvImport()
{
    // Fetch data
    QFETCH(QString, csv);
    QFETCH(char, separator);
    QFETCH(char, quote);
    QFETCH(QString, encoding);
    QFETCH(int, numfields);
    QFETCH(QVector<QStringList>, result);

    // Create temporary CSV file
    QTemporaryFile file;
    QVERIFY(file.open());
    {
    QTextStream out(&file);
    out.setCodec(encoding.toUtf8());
    out << csv;
    }
    file.flush();

    CSVParser csvparser(true, separator, quote);
    file.seek(0);
    QTextStream tstream(&file);
    tstream.setCodec(encoding.toUtf8());
    csvparser.parse(tstream);

    // Check return values
    QCOMPARE(csvparser.csv(), result);
    QCOMPARE((int)csvparser.columns(), numfields);
}
开发者ID:4sp1r3,项目名称:sqlitebrowser,代码行数:30,代码来源:TestImport.cpp

示例6: 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

示例7: slotOpen

void KoVersionDialog::slotOpen()
{
    if (!list->currentItem())
        return;

    KoVersionInfo *version = 0;
    for (int i = 0; i < m_doc->versionList().size(); ++i) {
        if (m_doc->versionList().at(i).date.toString() == list->currentItem()->text(0)) {
            version = &m_doc->versionList()[i];
            break;
        }
    }
    if (!version)
        return;

    QTemporaryFile tmp;
    tmp.setAutoRemove(false);
    tmp.open();
    tmp.write(version->data);
    tmp.flush();
    tmp.setPermissions(QFile::ReadUser);
    tmp.flush();

    if (!m_doc->documentPart()->mainWindows().isEmpty()) { //open the version in a new window if possible
        KoDocumentEntry entry = KoDocumentEntry::queryByMimeType(m_doc->nativeOasisMimeType());
        if (entry.isEmpty()) {
            entry = KoDocumentEntry::queryByMimeType(m_doc->nativeFormatMimeType());
        }
        Q_ASSERT(!entry.isEmpty());
        QString errorMsg;
        KoPart *part= entry.createKoPart(&errorMsg);
        if (!part) {
            if (!errorMsg.isEmpty())
                KMessageBox::error(0, errorMsg);
            return;
        }
        KoMainWindow *mainWindow = part->createMainWindow();
        mainWindow ->openDocument(QUrl::fromLocalFile(tmp.fileName()));
        mainWindow ->show();
    } else {
        m_doc->openUrl(QUrl::fromUserInput(tmp.fileName()));
    }

    tmp.setAutoRemove(true);
    slotButtonClicked(Close);
}
开发者ID:TheTypoMaster,项目名称:calligra,代码行数:46,代码来源:KoVersionDialog.cpp

示例8: 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

示例9: proceed

bool UltMtgReader::proceed(QList<MtgEntity>& entityList, QList<QPair<int,int> >& edgeList)
{
    //qDebug("UltMtgReader::proceed()");
    QFile file(QString::fromStdString(_in));
    if (!file.open(QIODevice::ReadOnly))
        return false;
    QDataStream in(&file);
    _unserializer = new JavaUnserializer(in);
    if(checkMtgMagic())
        qDebug("[+] file is a .mtg");
    else
    {
        qCritical("[X] file is not a .mtg");
        qCritical("[X] fail");
        file.close();
        return false;
    }
    delete _unserializer;

//Uncompress
    QByteArray inArray = in.device()->readAll();
    file.close();

    QTemporaryFile gzfileTmp;
    //QFile gzfileTmp("gzfileTemp.tmp");
    //if (!gzfileTmp.open(QIODevice::ReadWrite))
    if (!gzfileTmp.open())
        return false;
    QDataStream gzstream(&gzfileTmp);
    gzstream.writeRawData(inArray.data(),inArray.size());

    gzfileTmp.flush();

    QTemporaryFile ungzfileTmp;
    //QFile ungzfileTmp("ungzfileTemp.tmp");
    //if (!ungzfileTmp.open(QIODevice::ReadWrite))
    if (!ungzfileTmp.open())
        return false;

    unGZip(gzfileTmp.fileName().toStdString(),ungzfileTmp.fileName().toStdString());

    gzfileTmp.close();    
//End Uncompress

    QDataStream stream(&ungzfileTmp);

    _unserializer = new JavaUnserializer(stream);
    if(!readData(entityList,edgeList))
    {
        qCritical("\n[X] fail");
        delete _unserializer;
        return false;
    }
    return true;
}
开发者ID:agnousse,项目名称:netglub,代码行数:55,代码来源:ultMtgReader.cpp

示例10: 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

示例11: 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

示例12: cfg

Rules::Rules(const QString& str, bool temporary)
    : temporary_state(temporary ? 2 : 0)
{
    QTemporaryFile file;
    if (file.open()) {
        QByteArray s = str.toUtf8();
        file.write(s.data(), s.length());
    }
    file.flush();
    KConfig cfg(file.fileName(), KConfig::SimpleConfig);
    readFromCfg(cfg.group(QString()));
    if (description.isEmpty())
        description = QStringLiteral("temporary");
}
开发者ID:8l,项目名称:kwin,代码行数:14,代码来源:rules.cpp

示例13: exportContacts

bool CsvXXPort::exportContacts(const ContactList &contacts, VCardExportSelectionWidget::ExportFields) const
{
    QUrl url = QFileDialog::getSaveFileUrl(parentWidget(), QString(), QUrl::fromLocalFile(QStringLiteral("addressbook.csv")));
    if (url.isEmpty()) {
        return true;
    }

    if (QFileInfo(url.isLocalFile() ? url.toLocalFile() : url.path()).exists()) {
        if (url.isLocalFile() && QFileInfo(url.toLocalFile()).exists()) {
            PimCommon::RenameFileDialog::RenameFileDialogResult result = PimCommon::RenameFileDialog::RENAMEFILE_IGNORE;
            PimCommon::RenameFileDialog *dialog = new PimCommon::RenameFileDialog(url, false, parentWidget());
            result = static_cast<PimCommon::RenameFileDialog::RenameFileDialogResult>(dialog->exec());
            if (result == PimCommon::RenameFileDialog::RENAMEFILE_RENAME) {
                url = dialog->newName();
            } else if (result == PimCommon::RenameFileDialog::RENAMEFILE_IGNORE) {
                delete dialog;
                return true;
            }
            delete dialog;
        }
    }

    if (!url.isLocalFile()) {
        QTemporaryFile tmpFile;
        if (!tmpFile.open()) {
            const QString msg = i18n("<qt>Unable to open file <b>%1</b></qt>", url.url());
            KMessageBox::error(parentWidget(), msg);
            return false;
        }

        exportToFile(&tmpFile, contacts.addressList());
        tmpFile.flush();
        auto job = KIO::file_copy(QUrl::fromLocalFile(tmpFile.fileName()), url, -1, KIO::Overwrite);
        KJobWidgets::setWindow(job, parentWidget());
        return job->exec();
    } else {
        QFile file(url.toLocalFile());
        if (!file.open(QIODevice::WriteOnly)) {
            const QString msg = i18n("<qt>Unable to open file <b>%1</b>.</qt>", url.toLocalFile());
            KMessageBox::error(parentWidget(), msg);
            return false;
        }

        exportToFile(&file, contacts.addressList());
        file.close();

        return true;
    }
}
开发者ID:KDE,项目名称:kdepim,代码行数:49,代码来源:csv_xxport.cpp

示例14: prepare

PRL_RESULT Stunnel::prepare(QTemporaryFile& dst_, const QByteArray data_)
{
	if (!dst_.open())
	{
		WRITE_TRACE(DBG_FATAL, "Error: cannot open a temporary file");
		return PRL_ERR_OPEN_FAILED;
	}
	dst_.setAutoRemove(true);
	if (-1 == dst_.write(data_) || !dst_.flush())
	{
		WRITE_TRACE(DBG_FATAL, "Error: cannot write to a temporary file");
		return PRL_ERR_WRITE_FAILED;
	}
	return PRL_ERR_SUCCESS;
}
开发者ID:Lantame,项目名称:prl-disp-service,代码行数:15,代码来源:CDspVNCStarter.cpp

示例15: csvImport

void TestImport::csvImport()
{
    // Fetch data
    QFETCH(QString, csv);
    QFETCH(char, separator);
    QFETCH(char, quote);
    QFETCH(QString, encoding);
    QFETCH(int, numfields);
    QFETCH(QVector<QVector<QByteArray>>, result);

    // Create temporary CSV file
    QTemporaryFile file;
    QVERIFY(file.open());
    {
        QTextStream out(&file);
        out.setCodec(encoding.toUtf8());
        out << csv;
    }
    file.flush();

    CSVParser csvparser(true, separator, quote);
    file.seek(0);
    QTextStream tstream(&file);
    tstream.setCodec(encoding.toUtf8());

    QVector<QVector<QByteArray>> parsedCsv;
    int parsedCsvColumns = 0;
    csvparser.parse([&parsedCsv, &parsedCsvColumns](size_t /*rowNum*/, const CSVRow& data) -> bool {
        QVector<QByteArray> row;
        for(size_t i=0;i<data.num_fields;i++)
            row.push_back(QByteArray(data.fields[i].data, data.fields[i].data_length));
        parsedCsv.push_back(row);
        if(row.size() > parsedCsvColumns)
            parsedCsvColumns = row.size();
        return true;
    }, tstream);

    // Check return values
    QCOMPARE(parsedCsvColumns, numfields);
    QCOMPARE(parsedCsv.size(), result.size());
    for(int i=0;i<parsedCsv.size();i++)
    {
        QCOMPARE(parsedCsv.at(i).size(), result.at(i).size());
        for(int j=0;j<parsedCsv.at(i).size();j++)
            QCOMPARE(parsedCsv.at(i).at(j), result.at(i).at(j));
    }
    QCOMPARE(parsedCsv, result);
}
开发者ID:SafaAlfulaij,项目名称:sqlitebrowser,代码行数:48,代码来源:TestImport.cpp


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