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


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

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


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

示例1: parseSingleConfigFile

void KConfigINIBackEnd::parseSingleConfigFile(QFile &rFile, KEntryMap *pWriteBackMap, bool bGlobal, bool bDefault)
{
    const char *s;   // May get clobbered by sigsetjump, but we don't use them afterwards.
    const char *eof; // May get clobbered by sigsetjump, but we don't use them afterwards.
    QByteArray data;

    if(!rFile.isOpen()) // come back, if you have real work for us ;->
        return;

    // using kdDebug() here leads to an infinite loop
    // remove this for the release, aleXXX
    // qWarning("Parsing %s, global = %s default = %s",
    //           rFile.name().latin1(), bGlobal ? "true" : "false", bDefault ? "true" : "false");

    QCString aCurrentGroup("<default>");

    unsigned int ll = localeString.length();

#ifdef HAVE_MMAP
    static volatile const char *map;
    map = (const char *)mmap(0, rFile.size(), PROT_READ, MAP_PRIVATE, rFile.handle(), 0);

    if(map != MAP_FAILED)
    {
        s = (const char *)map;
        eof = s + rFile.size();

#ifdef SIGBUS
        struct sigaction act;
        act.sa_handler = mmap_sigbus_handler;
        sigemptyset(&act.sa_mask);
#ifdef SA_ONESHOT
        act.sa_flags = SA_ONESHOT;
#else
        act.sa_flags = SA_RESETHAND;
#endif
        sigaction(SIGBUS, &act, &mmap_old_sigact);

        if(sigsetjmp(mmap_jmpbuf, 1))
        {
            qWarning("SIGBUS while reading %s", rFile.name().latin1());
            munmap((char *)map, rFile.size());
            sigaction(SIGBUS, &mmap_old_sigact, 0);
            return;
        }
#endif
    }
    else
#endif
    {
        rFile.at(0);
        data = rFile.readAll();
        s = data.data();
        eof = s + data.size();
    }

    bool fileOptionImmutable = false;
    bool groupOptionImmutable = false;
    bool groupSkip = false;

    int line = 0;
    for(; s < eof; s++)
    {
        line++;

        while((s < eof) && isspace(*s) && (*s != '\n'))
            s++; // skip leading whitespace, shouldn't happen too often

        // skip empty lines, lines starting with #
        if((s < eof) && ((*s == '\n') || (*s == '#')))
        {
        sktoeol: // skip till end-of-line
            while((s < eof) && (*s != '\n'))
                s++;
            continue; // Empty or comment or no keyword
        }
        const char *startLine = s;

        if(*s == '[') // group
        {
            // In a group [[ and ]] have a special meaning
            while((s < eof) && (*s != '\n'))
            {
                if(*s == ']')
                {
                    if((s + 1 < eof) && (*(s + 1) == ']'))
                        s++; // Skip "]]"
                    else
                        break;
                }

                s++; // Search till end of group
            }
            const char *e = s;
            while((s < eof) && (*s != '\n'))
                s++; // Search till end of line / end of file
            if((e >= eof) || (*e != ']'))
            {
                fprintf(stderr, "Invalid group header at %s:%d\n", rFile.name().latin1(), line);
                continue;
//.........这里部分代码省略.........
开发者ID:serghei,项目名称:kde3-kdelibs,代码行数:101,代码来源:kconfigbackend.cpp

示例2: file

bool
K2sendPlayer::bluePlay (QString * filename)
{

    char buffer[buffer_size];
    int bytes_done;
    int file_len;
    int bytes_sent;
    int current_bytes_sent;
    int rc;
    int play_length;
    bool stop = FALSE;
    unsigned long long now;
    fd_set rfds, wfds;
    struct timeval tv;
    K2sendPlayerCommand *cmd = 0;
    K2sendPlayerCommand *new_cmd = 0;
    K2sendStatusEvent *se = 0;

    TagLib::MPEG::File mp3file (filename->latin1 ());
    play_length = mp3file.audioProperties ()->length ();
    QFile file (*filename);
    kdDebug (200010) << "K2sendPlayer::bluePlay name=" << *filename << " lenght=" << play_length << endl;
    setReset (0);
    setLoudness (loud_filt);
    setVolume (100 - volume);

    if (!file.open (IO_ReadOnly)) {
        QString msg = QString ("Error opening file ");
        se = new K2sendStatusEvent (K2sendStatusEvent::EventError, msg);
        //kdDebug(200010) << "post 34" << endl;
        QApplication::postEvent (m_parent, se);
        return FALSE;
    }
    se = new K2sendStatusEvent (K2sendStatusEvent::EventTitle, *filename);
    //kdDebug(200010) << "post 35" << endl;
    QApplication::postEvent (m_parent, se);

    file_len = file.size ();
    current_bytes_sent = bytes_sent = 0;
    last_ticks = start_ticks = getTime ();

    do {
        /* check if we can send(write) or receive(read) data */
        FD_ZERO (&rfds);
        FD_SET (blue_sock, &rfds);
        FD_ZERO (&wfds);
        FD_SET (blue_sock, &wfds);

        tv.tv_sec = 3;
        tv.tv_usec = 0;

        rc = select (FD_SETSIZE, &rfds, &wfds, NULL, &tv);
        if (rc < 1) {
            kdDebug (200010) << "K2sendPlayer::bluePlay select()" << endl;
            QString msg = QString ("Communication error");
            se = new K2sendStatusEvent (K2sendStatusEvent::EventMessage, msg, 2000);
            //kdDebug(200010) << "post 36" << endl;
            QApplication::postEvent (m_parent, se);
            blueClose ();
            return FALSE;
        }


        /* are we allowed to write? */
        if (FD_ISSET (blue_sock, &wfds)) {
            buffer[0] = K2sendPlayerCommand::Data;

            if (!(bytes_done = file.readBlock (buffer + 1, sizeof (buffer) - 1))) {
                if (file.atEnd ()) {
                    kdDebug (200010) << "K2sendPlayer::bluePlay Error reading file " << endl;
                    QString msg = QString ("Error reading file");
                    se = new K2sendStatusEvent (K2sendStatusEvent::EventMessage, msg, 2000);
                    //kdDebug(200010) << "post 37" << endl;
                    QApplication::postEvent (m_parent, se);

                }
            }
            else {
                if (write (blue_sock, buffer, bytes_done + 1) != bytes_done + 1) {
                    kdDebug (200010) << "K2sendPlayer::bluePlay Error sending" << endl;
                    QString msg = QString ("Error sending data");
                    se = new K2sendStatusEvent (K2sendStatusEvent::EventMessage, msg, 2000);
                    //kdDebug(200010) << "post 38" << endl;
                    QApplication::postEvent (m_parent, se);
                }
            }
            bytes_sent += bytes_done;
            current_bytes_sent += bytes_done;
        }
        if (FD_ISSET (blue_sock, &rfds)) {
            rc = read (blue_sock, buffer, sizeof (buffer));
            kdDebug (200010) << "K2sendPlayer::bluePlay  got data " << rc << " " << buffer[0] << " " << buffer[1] <<
                endl;
            /* handle commands */
            switch (buffer[0]) {
            case K2sendPlayerCommand::Buttons:
                if ((buffer[1] & 1) == 1) {
                    volume += 10;
                    if (volume > 100)
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:k2send-svn,代码行数:101,代码来源:k2sendplayer.cpp

示例3: load

bool CSVData::load(QString filename, QWidget * parent)
{
  QFile file;

  file.setName(filename);
  if(!file.open(QIODevice::ReadOnly))
  {
    if(parent)
      QMessageBox::critical(parent, tr("Open Failed"),
        tr("Could not open file for reading: %1").arg(qApp->translate("QFile", file.errorString())));
    return FALSE;
  }

  CSVLoadProgress * progress = 0;
  QTime time;
  if(parent)
  {
    progress = new CSVLoadProgress(parent, "csv load progress");
    progress->setModal(TRUE);
    progress->_file->setText(filename);
    progress->_totBytes->setText(QString("%1").arg(file.size()));
    progress->_readBytes->setText(QString("%1").arg(file.at()));
    progress->_readRecords->setText("0");
    progress->_progressBar->setProgress(file.at(), file.size());

    progress->show();
    qApp->processEvents();
  }
  time.start();

  Q3TextStream in(&file);

  bool inQuote = FALSE;
  bool haveText = FALSE;
  bool peeked = FALSE;
  QString field = QString::null;
  QChar c = QChar();
  QStringList row = QStringList();
  while(!in.atEnd())
  {
    if(progress && time.elapsed() > 200)
    {
      qApp->processEvents();

      if(!progress->isShown())
      {
        delete progress;
        return FALSE; // True for False?
      }

      progress->_readBytes->setText(QString("%1").arg(file.at()));
      progress->_readRecords->setText(QString("%1").arg(rows()));
      progress->_progressBar->setProgress(file.at());

      time.restart();
    }

    if(peeked)
      peeked = FALSE;
    else
      in >> c;

    // If we are inside a quoted string we handle
    // everything differently
    if(inQuote)
    {
      if('"' == c)
      {
        in >> c;
        if('"' == c)
          field += c;
        else
        {
          peeked = TRUE;
          inQuote = FALSE;
        }
      }
      else
        field += c;
    }
开发者ID:Wushaowei001,项目名称:xtuple,代码行数:80,代码来源:csvdata.cpp


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