本文整理汇总了C++中readAll函数的典型用法代码示例。如果您正苦于以下问题:C++ readAll函数的具体用法?C++ readAll怎么用?C++ readAll使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了readAll函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readAll
void QXmppSocksClient::slotReadyRead()
{
if (m_step == ConnectState)
{
m_step++;
// receive connect to server response
QByteArray buffer = readAll();
if (buffer.size() != 2 || buffer.at(0) != SocksVersion || buffer.at(1) != NoAuthentication)
{
qWarning("QXmppSocksClient received an invalid response during handshake");
close();
return;
}
// send CONNECT command
buffer.resize(3);
buffer[0] = SocksVersion;
buffer[1] = ConnectCommand;
buffer[2] = 0x00; // reserved
buffer.append(encodeHostAndPort(
DomainName,
m_hostName.toLatin1(),
m_hostPort));
write(buffer);
} else if (m_step == CommandState) {
m_step++;
// disconnect from signal
disconnect(this, SIGNAL(readyRead()), this, SLOT(slotReadyRead()));
// receive CONNECT response
QByteArray buffer = readAll();
if (buffer.size() < 6 ||
buffer.at(0) != SocksVersion ||
buffer.at(1) != Succeeded ||
buffer.at(2) != 0)
{
qWarning("QXmppSocksClient received an invalid response to CONNECT command");
close();
return;
}
// parse host
quint8 hostType;
QByteArray hostName;
quint16 hostPort;
if (!parseHostAndPort(buffer.mid(3), hostType, hostName, hostPort))
{
qWarning("QXmppSocksClient could not parse type/host/port");
close();
return;
}
// FIXME : what do we do with the resulting name / port?
// notify of connection
emit ready();
}
}
示例2: inst
std::shared_ptr<Shader> ResourceManager::shader(const Arx::String &path) {
return inst().shaders.getOrElseUpdate(path,[&](){
auto ret = std::make_shared<Shader>();
auto vpath = ResourceManager::adjustedPath(path + ".vertex");
Arx::String vsrc = readAll(vpath.path.raw());
auto fpath = ResourceManager::adjustedPath(path + ".fragment");
Arx::String fsrc = readAll(fpath.path.raw());
ret->load(vsrc.raw(),fsrc.raw());
return ret;
});
}
示例3: readAll
bool Socket::receive(void *data, int dataSize) {
readAll();
if (buffer.readBytes(data, dataSize)) {
return true;
}
return false;
}
示例4: readAll
void
ScrobSocket::onReadyRead()
{
QByteArray bytes = readAll();
if (bytes != "OK\n") qWarning() << bytes.trimmed();
disconnectFromHost();
}
示例5: reply_finished
void MyCtl::reply_finished(QNetworkReply *reply) {
if (!reply->property(kAuthGetSalt).isNull()) {
reply->deleteLater(); // let's not leak the reply
if (reply->error() == QNetworkReply::NoError) {
auto salt = reply->readAll();
auto email = reply->property(kEmail).toString();
auto password = reply->property(kPassword).toString();
Q_ASSERT(!password.isEmpty() && !email.isEmpty());
QCryptographicHash hasher{QCryptographicHash::Sha1};
hasher.addData(salt); // the server must hash the same way
hasher.addData("----");
hasher.addData(password.toUtf8());
auto hash = hasher.result().toBase64(QByteArray::Base64UrlEncoding);
auto url = doAuthUrl.arg(email).arg(QString::fromLatin1(hash));
auto reply = manager.get(QNetworkRequest{url});
reply->setProperty(kDoAuth, true);
reply->setProperty(kEmail, email);
}
}
else if (!reply->property(kDoAuth).isNull()) {
if (reply->error() == QNetworkReply::NoError) {
auto email = reply->property(kEmail).toString();
// ...
}
}
}
示例6: readAll
bool LLWebRequest::request(const char* httpMethod, const char* url, const char* contentData, char* readBuffer, size_t readBufferLength)
{
bool result = FALSE;
if (readBuffer) readBuffer[0] = 0; // terminate result buffer in case of failure
if (sendRequest(httpMethod, url, contentData))
{
if (readBuffer)
{
// read HTTP headers:
if (readHeaders())
{
// read content data as c-string, keep 1 byte for termination:
int bytesRead = readAll(readBuffer, readBufferLength - 1);
readBuffer[bytesRead] = 0; // Terminate read buffer with \0
result = TRUE;
}
}
else
{
// okay, not expecting any result
readHeaders(); // at least read headers
result = TRUE;
}
stop();
}
return result;
}
示例7: qCDebug
void ModelBaker::handleModelNetworkReply() {
auto requestReply = qobject_cast<QNetworkReply*>(sender());
if (requestReply->error() == QNetworkReply::NoError) {
qCDebug(model_baking) << "Downloaded" << _modelURL;
// grab the contents of the reply and make a copy in the output folder
QFile copyOfOriginal(_originalOutputModelPath);
qDebug(model_baking) << "Writing copy of original model file to" << _originalOutputModelPath << copyOfOriginal.fileName();
if (!copyOfOriginal.open(QIODevice::WriteOnly)) {
// add an error to the error list for this model stating that a duplicate of the original model could not be made
handleError("Could not create copy of " + _modelURL.toString() + " (Failed to open " + _originalOutputModelPath + ")");
return;
}
if (copyOfOriginal.write(requestReply->readAll()) == -1) {
handleError("Could not create copy of " + _modelURL.toString() + " (Failed to write)");
return;
}
// close that file now that we are done writing to it
copyOfOriginal.close();
// emit our signal to start the import of the model source copy
emit modelLoaded();
} else {
// add an error to our list stating that the model could not be downloaded
handleError("Failed to download " + _modelURL.toString());
}
}
示例8: QWidget
MainWidget::MainWidget(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
ui.tree->deserialize(readAll(treeFileName()));
}
示例9: readAll
void
IrcSocket::Receive ()
{
QByteArray bytes = readAll ();
qDebug () << __PRETTY_FUNCTION__ << " got " << bytes.size() << " bytes " << bytes;
numBytesIn += bytes.size();
QByteArray last2 = lineData.right(2);
if (last2.size () < 2) {
last2.prepend ("??");
last2 = last2.right (2);
}
int nb = bytes.size();
char byte;
char last0, last1;
last0 = last2[0];
last1 = last2[1];
for (int b=0; b< nb; b++) {
byte = bytes[b];
lineData.append (byte);
last0 = last1;
last1 = byte;
if (last0 == '\r' && last1 == '\n') {
emit ReceivedLine (this, lineData);
lineData.clear ();
}
}
emit IOActivity ();
}
示例10: handleReplyFinished
void RecentReleasesFetcher::handleReplyFinished ()
{
auto reply = qobject_cast<QNetworkReply*> (sender ());
reply->deleteLater ();
const auto& data = reply->readAll ();
qDebug () << data;
QDomDocument doc;
if (!doc.setContent (data))
{
qWarning () << Q_FUNC_INFO
<< "error parsing reply";
return;
}
const auto& docElem = doc.documentElement ();
if (docElem.attribute ("status") != "ok")
{
qWarning () << Q_FUNC_INFO
<< "reply is not ok:"
<< docElem.attribute ("status");
return;
}
QList<Media::AlbumRelease> releases;
static auto months = { "Jan", "Feb", "Mar",
"Apr", "May", "Jun",
"Jul", "Aug", "Sep",
"Oct", "Nov", "Dec" };
const auto monthsBegin = months.begin ();
const auto monthsEnd = months.end ();
auto album = docElem.firstChildElement ("albums").firstChildElement ("album");
while (!album.isNull ())
{
const auto& strs = album.attribute ("releasedate").split (' ', QString::SkipEmptyParts);
const int day = strs.value (1).toInt ();
const int month = std::distance (monthsBegin,
std::find (monthsBegin, monthsEnd, strs.value (2))) + 1;
const int year = strs.value (3).toInt ();
const QUrl& thumb = GetImage (album, "large");
const QUrl& full = GetImage (album, "extralarge");
Media::AlbumRelease release =
{
album.firstChildElement ("name").text (),
album.firstChildElement ("artist").firstChildElement ("name").text (),
QDateTime (QDate (year, month, day)),
thumb,
full,
QUrl (album.firstChildElement ("url").text ())
};
releases << release;
album = album.nextSiblingElement ("album");
}
emit gotRecentReleases (releases);
}
示例11: readAll
unsigned int CC3DataReader::readUnsignedInteger()
{
unsigned int value;
readAll( sizeof(value), (char*)&value );
// return _isBigEndian ? NSSwapBigIntToHost(value) : NSSwapLittleIntToHost(value);
return value;
}
示例12: QStringLiteral
void DialogNewCamera::login(std::function<void(const QString &sid)> cb)
{
QString url = authUrl;
url += QStringLiteral("&format=2&account=%1&passwd=%2").arg(ui->dsm_username->text()).arg(ui->dsm_password->text());
QUrl u(url);
QNetworkRequest request(u);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
auto reply = nm->get(request);
connect(reply, &QNetworkReply::finished, [=]()
{
reply->deleteLater();
if (reply->error() != QNetworkReply::NoError)
{
QMessageBox::warning(this, tr("Calaos Installer"), reply->errorString());
cb({});
return;
}
QByteArray bytes = reply->readAll();
bool err;
QJsonObject jdata = parseResult(bytes, err);
if (err || !jdata["sid"].isString())
{
cb({});
return;
}
cb(jdata["sid"].toString());
});
}
示例13: handleGetFinished
void SelfAvatarFetcher::handleGetFinished ()
{
auto reply = qobject_cast<QNetworkReply*> (sender ());
reply->deleteLater ();
const QImage& image = QImage::fromData (reply->readAll ());
emit gotImage (image);
}
示例14: log_message
quint8 ma_log::get_hash( QString *hash)
{
if( init() )
{
emit log_message( QString( Q_FUNC_INFO ), QString("Fail on init file log activity: ") + fileName() );
return 1;
}
hash->clear();
if( save() ) return 3;
if( !exists() )
{
emit log_message( QString( Q_FUNC_INFO ), QString("file not exists, filename: ") + fileName() );
return 1;
}
if( !open( QIODevice::ReadOnly | QIODevice::Text ) )
{
emit log_message( QString( Q_FUNC_INFO ), QString("can't open file: ") + fileName() );
return 2;
}
QByteArray file_data = readAll();
close();
QByteArray md5 = QCryptographicHash::hash( file_data, QCryptographicHash::Md5 );
file_data.append( md5 );
*hash = ( QCryptographicHash::hash( file_data, QCryptographicHash::Sha1 ) ).toHex();
return 0;
}
示例15: request
void Script::setUrl(QUrl url)
{
if (url == m_url)
return;
QNetworkRequest request(url);
auto reply = m_networkAccessManager.get(request);
m_status = Loading;
emit statusChanged(m_status);
connect(reply, &QNetworkReply::finished, [=] () {
if (m_status == Loading) {
if (reply->error() == QNetworkReply::NoError) {
m_source = QString::fromUtf8(reply->readAll());
emit sourceChanged(m_source);
m_status = Loaded;
emit statusChanged(m_status);
} else {
emit error(nullptr, QString("Failed to load “").append(url.toString()).append("”"));
m_status = Error;
emit statusChanged(m_status);
}
}
reply->deleteLater();
});
}