本文整理汇总了C++中QNetworkReply::bytesAvailable方法的典型用法代码示例。如果您正苦于以下问题:C++ QNetworkReply::bytesAvailable方法的具体用法?C++ QNetworkReply::bytesAvailable怎么用?C++ QNetworkReply::bytesAvailable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QNetworkReply
的用法示例。
在下文中一共展示了QNetworkReply::bytesAvailable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: checkReplyFeedback
void ProfileController::checkReplyFeedback() {
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
QString response;
if (reply) {
if (reply->error() == QNetworkReply::NoError) {
const int available = reply->bytesAvailable();
if (available > 0) {
const QByteArray buffer(reply->readAll());
response = QString::fromUtf8(buffer);
QString directory = QDir::homePath() + QLatin1String("/HFRBlackData");
QFile file(directory + "/cache.txt");
if (file.open(QIODevice::WriteOnly)) {
file.write(buffer);
file.close();
}
parseFeedback(response);
}
} else {
connectionTimedOut();
}
reply->deleteLater();
}
}
示例2: checkReply
void GoogleConnectController::checkReply() {
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
QString response;
if (reply) {
if (reply->error() == QNetworkReply::NoError) {
const int available = reply->bytesAvailable();
if (available > 0) {
const QByteArray buffer(reply->readAll());
response = QString::fromUtf8(buffer);
parse(response);
}
} else {
qDebug() << "reply... " << reply->errorString();
if(reply->errorString() == "Host not found") {
emit failedConnection();
} else
emit failedRenew();
}
reply->deleteLater();
}
}
示例3: checkReply
void LoginController::checkReply() {
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
QString response;
if (reply) {
if (reply->error() == QNetworkReply::NoError) {
const int available = reply->bytesAvailable();
if (available > 0) {
const QByteArray buffer(reply->readAll());
response = QString::fromUtf8(buffer);
// save cookies on disk
CookieJar::get()->saveToDisk();
saveUserName();
emit complete();
}
} else {
connectionTimedOut();
}
reply->deleteLater();
}
if (response.trimmed().isEmpty()) {
errorMessage();
}
}
示例4: responseCreateGameMode
/**
* Response: create GameMode
*/
void RatingsProcessor::responseCreateGameMode() {
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
QString response;
if (reply) {
if (reply->error() == QNetworkReply::NoError) {
const int available = reply->bytesAvailable();
if (available > 0) {
const QByteArray buffer(reply->readAll());
response = QString::fromUtf8(buffer);
requestGameModes();
}
} else {
if (reply->error() < 100) {
showError("Please check your internet connection");
return;
}
response =
tr("ResponseCreateGameMode. Error: %1 status: %2").arg(reply->errorString(),
reply->attribute(
QNetworkRequest::HttpStatusCodeAttribute).toString());
if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString()
== "422") {
}
}
reply->deleteLater();
}
}
示例5: checkReply
void SmileyPickerController::checkReply() {
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
QString response;
if (reply) {
if (reply->error() == QNetworkReply::NoError) {
const int available = reply->bytesAvailable();
if (available > 0) {
const QByteArray buffer(reply->readAll());
response = QString::fromUtf8(buffer);
m_Page = response;
m_IndexSubpagesInFile.clear();
m_IndexSubpagesInFile.append(0);
m_lastId = 0;
m_Mutex.lockForWrite();
m_Pushing = true;
m_Mutex.unlock();
parse(response);
}
} else {
response = tr("Error: %1 status: %2").arg(reply->errorString(), reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString());
qDebug() << response;
}
reply->deleteLater();
}
}
示例6: onTimelineReply
//! [1]
void TwitterRequest::onTimelineReply()
{
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
QString response;
bool success = false;
if (reply) {
if (reply->error() == QNetworkReply::NoError) {
const int available = reply->bytesAvailable();
if (available > 0) {
const QByteArray buffer = reply->readAll();
response = QString::fromUtf8(buffer);
success = true;
}
} else {
response = tr("Error: %1 status: %2").arg(reply->errorString(), reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString());
}
reply->deleteLater();
}
if (response.trimmed().isEmpty()) {
response = tr("Twitter request failed. Check internet connection");
}
emit complete(response, success);
}
示例7: checkReply
void WebResourceManager::checkReply() {
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
if (reply) {
if (reply->error() == QNetworkReply::NoError) {
const int available = reply->bytesAvailable();
if (available > 0) {
QImage qImage;
qImage.loadFromData(reply->readAll());
if (qImage.isNull()) {
return;
}
QString diskPath = QDir::homePath() + "/Cache/"
+ QString::number(qHash(reply->url().host())) + "_"
+ QString::number(qHash(reply->url().path())) + ".PNG";
if (qImage.save(diskPath)) {
emit onImageReady(reply->url().toString(), diskPath);
}
// remove item from download queue
m_EditQueue->lockForWrite();
for(int i = 0 ; i < m_DownloadQueue->length() ; ++i)
if(m_DownloadQueue->at(i).compare(reply->url().toString()) == 0) {
m_DownloadQueue->removeAt(i);
m_EditQueue->unlock();
break;
}
m_EditQueue->unlock();
}
}
}
}
示例8: onCurrentUserReply
/*
* ForumRequest::onLoginReply()
*
* Callback handler for QNetworkReply finished() signal fired when requesting the currently logged in user.
*/
void Authenticator::onCurrentUserReply()
{
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
QString response;
if (reply) {
if (reply->error() == QNetworkReply::NoError) {
const int available = reply->bytesAvailable();
if (available > 0) {
const QByteArray buffer = reply->readAll();
response = QString::fromUtf8(buffer);
}
}
reply->deleteLater();
}
if (response.contains("status=\"success\"", Qt::CaseInsensitive))
{
int valStart = response.indexOf("<id type=\"int\">") + 15;
int valEnd = response.indexOf("</id>");
mUserId = "id/" + response.mid(valStart, (valEnd - valStart));
}
else
{
mUserId = "";
}
}
示例9: responseScoreAverage
/**
* Response: score average
*/
void RatingsProcessor::responseScoreAverage() {
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
QString response;
if (reply) {
if (reply->error() == QNetworkReply::NoError) {
const int available = reply->bytesAvailable();
if (available > 0) {
const QByteArray buffer(reply->readAll());
response = QString::fromUtf8(buffer);
bb::data::JsonDataAccess jda;
QVariant vlist = jda.loadFromBuffer(response);
QVariantMap list = vlist.toMap();
float temp = list["value"].toFloat();
m_ratValue = temp;
}
} else {
m_ratValue = 0;
if (reply->error() < 100) {
showError("Please check your internet connection");
return;
}
response =
tr("Error: %1 status: %2").arg(reply->errorString(),
reply->attribute(
QNetworkRequest::HttpStatusCodeAttribute).toString());
//another error
showError("ResponseScoreAverage. QBlox Server Error = " + response);
return;
}
reply->deleteLater();
}
emit ratValueChanged();
emit imageChanged();
m_label.clear();
emit labelChanged();
emit idRatChanged();
m_loading = false;
emit loadingChanged();
m_urlImage = m_imageUrl;
emit urlImageChanged();
m_showing = true;
emit showingChanged();
emit ratValueChanged();
return;
}
示例10: bytesAvailable
qint64 QNetworkReplyProto::bytesAvailable() const
{
QNetworkReply *item = qscriptvalue_cast<QNetworkReply*>(thisObject());
if (item)
return item->bytesAvailable();
return 0;
}
示例11: manifestReadyRead
void PAAlternativeLauncher::manifestReadyRead()
{
QNetworkReply *reply = dynamic_cast<QNetworkReply *>(sender());
if(reply)
{
if(reply->error() == QNetworkReply::NoError)
{
qint64 bytes_available = reply->bytesAvailable();
QByteArray input = reply->read(bytes_available);
Q_ASSERT(input.size() == bytes_available);
mZstream.next_in = (Bytef *)input.constData();
mZstream.avail_in = bytes_available;
uInt old_avail_out = mZstream.avail_out;
int res = inflate(&mZstream, Z_SYNC_FLUSH);
if(res != Z_OK && res != Z_STREAM_END)
{
reply->abort();
info.warning("ZLib", mZstream.msg, false);
return;
}
mManifestJson.write((const char *)mBuffer, old_avail_out - mZstream.avail_out);
mZstream.avail_out = mBufferSize;
mZstream.next_out = mBuffer;
Q_ASSERT(mZstream.avail_in == 0);
}
else
{
reply->abort();
info.critical(tr("Manifest"), tr("Error while getting manifest (1).\n%1").arg(reply->errorString()));
}
}
}
示例12: onGetReply
/**
* PostHttp::onGetReply()
*
* SLOT
* Read and return the http response from our http post request
*/
void PostHttp::onGetReply()
{
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
QString response;
if (reply) {
if (reply->error() == QNetworkReply::NoError) {
const int available = reply->bytesAvailable();
if (available > 0) {
const QByteArray buffer(reply->readAll());
response = QString::fromUtf8(buffer);
}
} else {
response = tr("Error: %1 status: %2").arg(reply->errorString(), reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString());
qDebug() << response;
}
reply->deleteLater();
}
if (response.trimmed().isEmpty()) {
response = tr("Unable to retrieve post response");
}
emit complete(response);
}
示例13: onReplyFinished
void ImageLoader::onReplyFinished() {
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
QString response;
if (reply) {
if (reply->error() == QNetworkReply::NoError) {
const int available = reply->bytesAvailable();
if (available > 0) {
const QByteArray data(reply->readAll());
QImage image;
image.loadFromData(data);
image = image.scaled(120, 120, Qt::KeepAspectRatioByExpanding);
const QImage swappedImage = image.rgbSwapped();
const bb::ImageData imageData = bb::ImageData::fromPixels(swappedImage.bits(), bb::PixelFormat::RGBA_Premultiplied, swappedImage.width(), swappedImage.height(), swappedImage.bytesPerLine());
_image = bb::cascades::Image(imageData);
emit imageChanged();
_loading = false;
emit loadingChanged();
reply->deleteLater();
return;
}
}
reply->deleteLater();
}
// TODO: handle error: set default icon
}
示例14: onTimelineReply
/*
* TwitterRequest::onTimelineReply()
*
* Callback handler for QNetworkReply finished() signal
*/
void TwitterRequest::onTimelineReply()
{
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
QString response;
bool success = false;
if (reply)
{
if (reply->error() == QNetworkReply::NoError)
{
int available = reply->bytesAvailable();
if (available > 0)
{
int bufSize = sizeof(char) * available + sizeof(char);
QByteArray buffer(bufSize, 0);
int read = reply->read(buffer.data(), available);
response = QString::fromUtf8(buffer);
success = true;
}
}
else
{
response = QString("Error: ") + reply->errorString() + QString(" status:") + reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString();
qDebug() << response;
}
reply->deleteLater();
}
if (response.trimmed().isEmpty())
{
response = "Twitter request failed. Check internet connection";
qDebug() << response;
}
emit complete(response, success);
}
示例15: onRequestUsers
void QBNetwork::onRequestUsers() {
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
if (reply) {
const int available = reply->bytesAvailable();
if (available > 0) {
const QByteArray buffer(reply->readAll());
QString response = QString::fromUtf8(buffer);
JsonDataAccess jda;
QVariant qtData = jda.loadFromBuffer(response);
if (jda.hasError()) {
const DataAccessError err = jda.error();
emit error(
tr("Error converting JSON data: %1").arg(
err.errorMessage()));
} else {
emit usersReceived(response);
}
} else {
emit error("Wrong reply for request users request");
}
reply->deleteLater();
} else {
emit error("Wrong reply for request users request");
}
disconnectFromAll();
}