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


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

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


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

示例1: printMsgHandler

// Qt4 code
void printMsgHandler(QtMsgType type, const char * _str)
{
    static QMutex _logmut;
    _logmut.lock();
    QString time=QTime::currentTime().toString("hh:mm:ss");
    QString str=QString("[%1]["+time+"] %2\n").arg(type).arg(_str);

    switch (type)
    {
        case QtDebugMsg:
            _logfile.write(str.toLocal8Bit());
            _logfile.flush();
        break;
        case QtWarningMsg:
            fprintf(stderr, "Debug: %s\n", str.toLocal8Bit().data());
            _logfile.write(str.toLocal8Bit());
            _logfile.flush();
        break;
        case QtCriticalMsg:
            _logfile.write(str.toLocal8Bit());
            _logfile.flush();
        break;
        case QtFatalMsg:
            _logfile.write(str.toLocal8Bit());
            _logfile.flush();
            exit(-1);
        break;
    }
    _logmut.unlock();
};
开发者ID:portah,项目名称:repeats,代码行数:31,代码来源:Main.hpp

示例2: messageHandler

void QxtDaemon::messageHandler(QtMsgType type, const char *msg)
{
    QFile * f = qxt_daemon_singleton->logfile;
    f->write("[");
    f->write(QDateTime::currentDateTime().toString(Qt::ISODate).toLocal8Bit());
    f->write("] ");
    if (type == QtDebugMsg)
        f->write("[qDebug] ");
    else if (type == QtWarningMsg)
        f->write("[qWarning] ");
    else if (type == QtCriticalMsg)
        f->write("[qCritical] ");
    else if (type == QtFatalMsg)
    {
        f->write("[qFatal] ");
        f->write(msg);
        f->write("\n");
        f->write("aborting \n");
        f->flush();
        abort();
    }

    f->write(msg);
    f->write("\n");
    f->flush();
}
开发者ID:MorS25,项目名称:OpenPilot,代码行数:26,代码来源:qxtdaemon.cpp

示例3: DownloadUpdate

void UpdateManager::DownloadUpdate()
{
    QNetworkAccessManager *manager = new QNetworkAccessManager(this);
    connect(manager, &QNetworkAccessManager::finished,
            [=](QNetworkReply *reply)
            {
                if(reply->error())
                    emit errorSignal("UpdateManager: "+reply->errorString());
                else
                {
                    // todo: progress bar
                    // todo: compression
                    QFile *file = new QFile("Baka MPlayer.exe");
                    if(file->open(QFile::Truncate))
                    {
                        file->write(reply->readAll());
                        file->flush();
                        file->close();
                    }
                    delete file;
                }
                reply->deleteLater();
            });
    manager->get(QNetworkRequest(QUrl("http://bakamplayer.u8sand.net/Baka MPlayer.exe")));
}
开发者ID:starks,项目名称:Baka-MPlayer,代码行数:25,代码来源:updatemanager.cpp

示例4: SaveFile

void ConfigFile::SaveFile(QString path)
{
    QString current = QDir::currentPath();
    QString destinyFile;
    QStringList list = ConfigFileName.split(QDir::separator());
    QString fileName = list.at(list.count()-1);
    if(path!=""){
        //destinyFile = current + QDir::separator() + path + QDir::separator() + fileName;
        destinyFile = path + QDir::separator() + fileName;
    } else {
        destinyFile = current + QDir::separator() + fileName;
    }
    destinyFile = destinyFile.replace("/", QDir::separator());
    destinyFile = destinyFile.replace("\\", QDir::separator());

    DeleteOldFileIfExists(destinyFile);
    QFile *file = OpenFileForWriting(destinyFile);
    if (!file){
        saveSuccess = false;
        return;
    }

    std::string str = this->ConfigContents.toStdString();
    file->write(str.c_str());
    file->flush();
    file->close();
    saveSuccess=true;
}
开发者ID:capnjj,项目名称:taiga-wizard,代码行数:28,代码来源:configfile.cpp

示例5: download

void HttpClient::download(const QString &destinationPath,
                          std::function<void (const QString &)> successHandler,
                          std::function<void (const QString &)> errorHandler) {
    bool  debug = d->debug;
    QFile *file = new QFile(destinationPath);

    if (file->open(QIODevice::WriteOnly)) {
        download([=](const QByteArray &data) {
            file->write(data);
        }, [=](const QString &) {
            // 请求结束后释放文件对象
            file->flush();
            file->close();
            file->deleteLater();

            if (debug) {
                qDebug().noquote() << QString("下载完成,保存到: %1").arg(destinationPath);
            }

            if (nullptr != successHandler) {
                successHandler(QString("下载完成,保存到: %1").arg(destinationPath));
            }
        }, errorHandler);
    } else {
        // 打开文件出错
        if (debug) {
            qDebug().noquote() << QString("打开文件出错: %1").arg(destinationPath);
        }

        if (nullptr != errorHandler) {
            errorHandler(QString("打开文件出错: %1").arg(destinationPath));
        }
    }
}
开发者ID:xtuer,项目名称:Qt,代码行数:34,代码来源:HttpClient.cpp

示例6: stream

int QMacPasteboardMimeQt3Any::registerMimeType(const QString &mime)
{
    if(!mime_registry.contains(mime)) {
        if(!loadMimeRegistry()) {
            qWarning("QMacPasteboardMimeAnyQt3Mime: Internal error");
            return 0;
        }
        if(!mime_registry.contains(mime)) {
            if(!library_file.isOpen()) {
                if(!library_file.open(QIODevice::WriteOnly)) {
                    qWarning("QMacPasteboardMimeAnyQt3Mime: Failure to open %s -- %s", library_file.fileName().toLatin1().constData(),
                             library_file.errorString().toLatin1().constData());
                    return false;
                }
            }
            int ret = ++current_max;
            mime_registry_loaded = QFileInfo(library_file).lastModified();
            QTextStream stream(&library_file);
            stream << mime << endl;
            stream << ret << endl;
            mime_registry.insert(mime, ret);
            library_file.flush(); //flush and set mtime
            return ret;
        }
    }
    return mime_registry[mime];
}
开发者ID:FilipBE,项目名称:qtextended,代码行数:27,代码来源:qmime_mac.cpp

示例7: replyFinished

void Downloader::replyFinished (QNetworkReply *reply){
    if(reply->error()){
        qDebug() << "ERROR!";
        m_stat = "ERROR!";
        qDebug() << reply->errorString();
    }else{
        qDebug() << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString();

        //QString name = m_image;
        //make the directory here
        QDir dir;
        bool ok = dir.mkpath(m_path);

        if(ok){
            QFile *file = new QFile(m_path + m_image);
            if(file->open(QFile::Append)) {
                file->write(reply->readAll());
                file->flush();
                file->close();
                m_stat = "FINISHED";
            }
            delete file;
        }

    }
    reply->deleteLater();
}
开发者ID:ZakiLab,项目名称:quran_android,代码行数:27,代码来源:downloader.cpp

示例8: QString

/*!
 *\~english
 *	Writes text to log.
 *\~russian
 *	Пишет текст в лог.
 *\~
 *	\param log_name - \~english Full path to logfile \~russian Полный путь к лог файлу \~
 *	\param test_name - \~english Test name \~russian Имя теста \~
 *	\param status - \~english OK, ERROR or SKIP \~russian OK, ОШИБКА или ПРОПУЩЕН \~
 *	\param text - \~english Comment \~russian Комментарий \~
*/
void
aTests::print2log(	const QString &log_name,
			const QString &test_name,
			const QString &status,
			const QString &text)
{
	QString toWrite = QString("%1::%2::%3::%4\r\n")\
			  .arg(QDateTime::currentDateTime().toString(Qt::ISODate).replace('T',' '))\
			  .arg(test_name)\
			  .arg(status)\
			  .arg(text);

	QFile f;
	if(log_name==QString::null)
	{
		f.open( QIODevice::WriteOnly, stdout );
		f.writeBlock((const char*)toWrite,strlen((const char*)toWrite));
	}
	else
	{
		f.setName(log_name);
		f.open( QIODevice::WriteOnly | QIODevice::Append );
		f.writeBlock((const char*)toWrite,strlen((const char*)toWrite));
		f.flush();
	}
	f.close();

//	else printf("error write to log\n");
}
开发者ID:K-Be,项目名称:ananas-labs-qt4,代码行数:40,代码来源:atests.cpp

示例9: writeBatteryPar

bool TextHelper::writeBatteryPar(QString batteryPar)
{
    QFile *dtsFile = new QFile(Global::srcPath + "/" + Global::dtsPath);
    QFile *tempFile = new QFile(QDir::currentPath() + "/tmp/temp.txt");
    QTextStream dtsTS(dtsFile);
    QTextStream tempTS(tempFile);
    if(!dtsFile->open(QIODevice::ReadOnly))
    {
        qDebug() << Global::srcPath + "/" + Global::dtsPath << " open fail";
        return false;
    }
    if(!tempFile->open(QIODevice::WriteOnly))
    {
        qDebug() << QDir::currentPath() + "/tmp/temp.txt" << " open fail";
        dtsFile->close();
        return false;
    }
    QString strLine;
    while (!dtsTS.atEnd())
    {
        strLine = dtsTS.readLine();
        if(strLine.contains("battery {"))
        {
            tempTS << strLine << "\n";
            strLine = dtsTS.readLine();
            tempTS << strLine << "\n";
            tempTS << "      ocv_table = <";
            QStringList strList = batteryPar.trimmed().split(" ");
            for(int i = 1; i < 21; i++)
            {
                tempTS << strList[i -1] << " ";
                if(i%7 == 0)
                {
                    tempTS << "\n\t\t\t";
                }
            }
            tempTS << strList[20];
            tempTS << ">;\n";
            dtsTS.readLine();
            dtsTS.readLine();
            dtsTS.readLine();
            continue;
        }
        tempTS << strLine << "\n";
    }
    dtsFile->close();
    tempFile->flush();
    tempFile->close();
    if(!dtsFile->remove())
    {
        qDebug() << "dtsFile remove fail";
        return false;
    }
    if(!tempFile->copy(Global::srcPath + "/" + Global::dtsPath))
    {
        qDebug() << "copy fail" << Global::srcPath + "/" + Global::dtsPath;
        return false;
    }
    return true;
}
开发者ID:yuanairong,项目名称:FirewareMaker_windows,代码行数:60,代码来源:texthelper.cpp

示例10: onDownload

void Scanner::onDownload(QNetworkReply* reply)
{
    qDebug() << "onDownload";
    m_active = false;

    if(reply->error() != QNetworkReply::NoError) {
        qDebug() << reply->errorString();
        return;
    }

    qDebug() << "saving " << reply->url().toString();
    QString random = (QString) qrand();
    QString path = m_path + reply->url().fileName();

    QFile* file = new QFile(path);
    if(file->open(QIODevice::WriteOnly)) {
        file->write(reply->readAll());
    }
    file->flush();
    file->close();
    delete file;
    file = 0;

    if(!downloadQueue.isEmpty())
        BeginDownload();

    return;
}
开发者ID:Ahlforn,项目名称:Reddit-Scanner,代码行数:28,代码来源:scanner.cpp

示例11: Menu

void GameBoard::Menu()
{
    QDialog *menu = new QDialog;
    QLabel *texto = new QLabel;
    QLabel *title = new QLabel("<b><big>Atalhos</big></b>");

    QFile *config = new QFile("/home/vinicius/svn/unball/estrategia/visualization/Visualization Last Version/Visualization_last/Tabela.txt"); //Colocar o diretório ao qual se encontra o arquivo Tabela.txt

    if(!config->open(QFile::ReadOnly | QFile::Text))
    {
        return;
    }
    QTextStream mOut(config);
    QString mTexto = mOut.readAll();


    texto->setText(mTexto);

    QVBoxLayout *lay =new QVBoxLayout;
    lay->addWidget(title);
    lay->addWidget(texto);

    menu->setLayout(lay);
    menu->show();

    config->flush();
    mOut.flush();
    config->close();

}
开发者ID:unball,项目名称:ieee-very-small-2012,代码行数:30,代码来源:gameboard.cpp

示例12: processViewCaptureAck

void PortGroup::processViewCaptureAck(PbRpcController *controller)
{
    QFile *capFile = static_cast<QFile*>(controller->binaryBlob());

    QString viewer = appSettings->value(kWiresharkPathKey, 
            kWiresharkPathDefaultValue).toString();

    qDebug("In %s", __FUNCTION__);

    capFile->flush();
    capFile->close();

    if (!QFile::exists(viewer))
    {
        QMessageBox::warning(NULL, "Can't find Wireshark", 
                viewer + QString(" does not exist!\n\nPlease correct the path"
                " to Wireshark in the Preferences."));
        goto _exit;
    }

    if (!QProcess::startDetached(viewer, QStringList() << capFile->fileName()))
        qDebug("Failed starting Wireshark");

_exit:
    delete controller;
}
开发者ID:Raman325,项目名称:ostinato,代码行数:26,代码来源:portgroup.cpp

示例13: save

void Global::save(QString filename)
{
  GASSERT(_db != NULL, "Cannot save empty database");

  QFile fd (filename);
  if (!fd.open(QIODevice::WriteOnly))
    GEXITDIALOG("Could not open project file for writing " + filename);
  QTextStream file (&fd);

  file << "VERSION=" << DB_VERSION << "\n";
  file << "IMAGE_PATH=.\n"; // Images are always in the same directory as the project file
  file << "QUESTIONS_PER_STUDENT=" << Global::db()->getNumQuestions() << "\n";
  GASSERT(_numPagesPerStudent > 0, "_numPagesPerStudent %zu is not valid", _numPagesPerStudent);
  file << "PAGES_PER_STUDENT=" << _numPagesPerStudent << "\n";
  file << "TOTAL_STUDENTS=" << Global::db()->getNumStudents() << "\n";
  file << "SAVE_DATE_TIME=" << QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss") << "\n";
  file << "NUM_IMAGES=" << Global::getPages()->size() << "\n";
  if (Global::getPages()->size() != Global::db()->getNumStudents() * _numPagesPerStudent)
  {
    GDEBUG("Detected mismatch in number of pages %zu, number of students %zu, and number of pages per student %zu",
           Global::getPages()->size(), Global::db()->getNumStudents(), _numPagesPerStudent);
    GINFODIALOG("Detected page mismatch during save, but will continue anyway");
  }

  file << "-2\tPAGE\tPAGE\t" << -1;
  for (size_t q = 0; q < Global::db()->getNumQuestions(); q++)
    file << "\t" << Global::db()->getQuestionPage(q);
  for (size_t q = 0; q < Global::db()->getNumQuestions(); q++)
    file << "\t" << "NF"; // Emit empty feedback columns
  file << "\n";

  file << "-1\tMAX\tMAX\t" << Global::db()->getTotalMaximum();
  for (size_t q = 0; q < Global::db()->getNumQuestions(); q++)
    file << "\t" << Global::db()->getQuestionMaximum(q);
  for (size_t q = 0; q < Global::db()->getNumQuestions(); q++)
    file << "\t" << "NF"; // Emit empty feedback columns
  file << "\n";

  for (size_t s = 0; s < Global::db()->getNumStudents(); s++)
  {
    Student& student = Global::db()->getStudent(s);
    file << s << "\t" << student.getStudentId() << "\t" << student.getStudentName();
    file << "\t" << student.getTotal();
    for (size_t q = 0; q < Global::db()->getNumQuestions(); q++)
      file << "\t" << student.getGrade(q);
    for (size_t q = 0; q < Global::db()->getNumQuestions(); q++)
      file << "\t" << student.getFeedback(q);
    file << "\n";
  }

  // Verify that the write actually worked ok
  fd.flush();
  if (fd.error() != QFile::NoError)
    GINFODIALOG ("Failed to write out complete project file - will not exit, but you need to re-save your work!");
  fd.close();

  // TODO: We could also dump out the Qt table as well as a backup in a different file
}
开发者ID:waynepiekarski,项目名称:qtgrader,代码行数:58,代码来源:global.cpp

示例14: writeLog

void cLogFile::writeLog(QString msg)
{

    QString date = myLocaltime.currentDateTime().toLocalTime().toString( "yyyy.MM.dd_hh:mm:ss" );
    QByteArray log;
    log = QByteArray((date+";"+msg+"\n").toUtf8());
    file.write(log);
    file.flush();

}
开发者ID:BackupTheBerlios,项目名称:osibs-svn,代码行数:10,代码来源:cLogFile.cpp

示例15: saveToTmpFile

/* used for scripting IPC
    accepts an open writable file.
    returns false on failure */
bool Matrix::saveToTmpFile(QFile &fp) {
  qint64 n_written;
  qint64 n_write;

  n_write = _nX*_nY*sizeof(double);

  n_written = fp.write((char *)_z, n_write);

  fp.flush();

  return (n_write == n_written);
}
开发者ID:KDE,项目名称:kst-plot,代码行数:15,代码来源:matrix.cpp


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