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


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

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


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

示例1: sendFile

bool HttpRequestProcessor::sendFile(QFile& file)
{
    writeString(_socket, "HTTP/1.");
    writeString(_socket, _httpVersion);
    if (file.open(QIODevice::ReadOnly))
    {
        writeString(_socket, " 200 OK\n");
        writeString(_socket, "Content-Length: ");
        writeString(_socket, QString::number(file.size()) + "\n");
        writeString(_socket, "Pragma: no-cache\n");
        writeString(_socket, "Cache-Control: no-store\n");
        writeString(_socket, "\n");
        _socket->flush();
        char data[66000];
        int bytesRead=0;
        int bytesWritten=0;
        while ((file.bytesAvailable() > 0) && (bytesWritten != -1))
        {
            //64KB-Häppchen der Datei lesen und versenden
            bytesRead = file.read(data, 1023);
            if (bytesRead != -1)
            {
                bytesWritten = _socket->write(data, bytesRead);
                _socket->waitForBytesWritten();
                _socket->flush();
                if (bytesRead != bytesWritten)
                {
                    std::cerr << "error while sending data" << std::endl;
                }
            }
        }
    }
    else
    {
        this->send500();
        _socket->flush();
        return false;
    }
    //TODO: Header, die zum Dateiinhalt passen
    //TODO: Dateiinhalt senden
    //TODO: Bei Fehler false zurückgeben
    //writeString(_socket, "<!DOCTYPE html>\n<html><head><title>Bad request</title></head><body><p>400 Bad Request</p></body></html>");
    _socket->flush();
    
    return true;
}
开发者ID:lenalebt,项目名称:studienprojekt-routing,代码行数:46,代码来源:webserver.cpp

示例2: fInfo

QFile *FileExplorer::openFileForUpload() {
  QString fileName = QFileDialog::getOpenFileName(
      this->baseWidget, tr("Select file"), QDir::currentPath()
  );

  if (! fileName.isEmpty()){
    QFile *file = new QFile(fileName);

    if (! file->exists()) {
      QMessageBox::information(
          this->baseWidget,tr("File explorer"), 
          tr("Cannot load %1.").arg(fileName)
      );
      return NULL;
    }

    QFileInfo fInfo(*file);
    uint byteCount = file->bytesAvailable();

    if (! fInfo.isFile()) {
        QMessageBox::information(
           this->baseWidget, tr("Uploader"), 
	   tr("%1. is not a regular file").arg(fileName)
        );
    } else if (! file->isReadable()) {
        QMessageBox::information(
           this->baseWidget, tr("Uploader"), 
           tr("No read permissions for %1.").arg(fileName)
        );
    } else if (! byteCount) {
        QMessageBox::information(
           this->baseWidget, tr("Uploader"), 
           tr("Attempting to upload an empty file")
        );
    } else { // Good for return
        return file;
    }

    // By this point, release memory
    delete file;
  }

  return NULL;
}
开发者ID:klindenbach,项目名称:chatClient,代码行数:44,代码来源:FileExplorer.cpp


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