本文整理汇总了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;
}
示例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;
}