本文整理汇总了C++中QBuffer::setData方法的典型用法代码示例。如果您正苦于以下问题:C++ QBuffer::setData方法的具体用法?C++ QBuffer::setData怎么用?C++ QBuffer::setData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QBuffer
的用法示例。
在下文中一共展示了QBuffer::setData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QBuffer
YandexNarodBuffer::YandexNarodBuffer(const QString &fileName, QIODevice *file,
const QByteArray &boundary, QObject *parent) :
QIODevice(parent)
{
QByteArray data;
data.append("--").append(boundary).append("\r\n");
data.append("Content-Disposition: form-data; name=\"file\"; filename=\"")
.append(fileName).append("\"\r\n");
data.append("Content-Transfer-Encoding: binary\r\n");
data.append("\r\n");
QBuffer *buffer = new QBuffer(this);
buffer->setData(data);
m_devices.append(buffer);
m_devices.append(file);
file->setParent(this);
connect(file, SIGNAL(destroyed()), SLOT(deleteLater()));
data.clear();
data.append("\r\n--").append(boundary).append("--\r\n");
buffer = new QBuffer(this);
buffer->setData(data);
m_devices.append(buffer);
}
示例2: getDirectoryListing
QNetworkReply* ownCloudInfo::getDirectoryListing( const QString& dir )
{
QNetworkRequest req;
req.setUrl( QUrl( webdavUrl(_connection) + dir ) );
req.setRawHeader("Depth", "1");
QByteArray xml("<?xml version=\"1.0\" ?>\n"
"<d:propfind xmlns:d=\"DAV:\">\n"
" <d:prop>\n"
" <d:resourcetype/>\n"
" </d:prop>\n"
"</d:propfind>\n");
QBuffer *buf = new QBuffer;
buf->setData(xml);
buf->open(QIODevice::ReadOnly);
QNetworkReply *reply = davRequest("PROPFIND", req, buf);
buf->setParent(reply);
if( reply->error() != QNetworkReply::NoError ) {
qDebug() << "getting quota: request network error: " << reply->errorString();
}
connect( reply, SIGNAL( finished()), SLOT(slotGetDirectoryListingFinished()) );
connect( reply, SIGNAL( error(QNetworkReply::NetworkError)),
this, SLOT( slotError(QNetworkReply::NetworkError)));
return reply;
}
示例3: defaultTranslator
const KeyboardTranslator* KeyboardTranslatorManager::defaultTranslator()
{
kDebug() << "Loading default translator from text" << defaultTranslatorText;
QBuffer textBuffer;
textBuffer.setData(defaultTranslatorText,strlen(defaultTranslatorText));
return loadTranslator(&textBuffer,"fallback");
}
示例4: testPut
void testPut()
{
#if defined(USE_QNAM) && QT_VERSION <= QT_VERSION_CHECK(5, 5, 0)
QSKIP("This test is broken with Qt < 5.5, the fix is 9286a8e5dd97c5d4d7e0ed07a73d4ce7240fdc1d in qtbase");
#endif
const QString aDir = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
QVERIFY(QDir::temp().mkpath(aDir));
const QString aFile = aDir + QStringLiteral("/accessmanagertest-data");
const QByteArray content = "We love free software!";
QBuffer buffer;
buffer.setData(content);
QVERIFY(buffer.open(QIODevice::ReadOnly));
QFile::remove(aFile);
QNetworkReply *reply = manager()->put(QNetworkRequest(QUrl::fromLocalFile(aFile)), &buffer);
QSignalSpy spy(reply, SIGNAL(finished()));
QVERIFY(reply->isRunning());
QVERIFY(spy.wait());
QVERIFY(QFile::exists(aFile));
QFile f(aFile);
QVERIFY(f.open(QIODevice::ReadOnly));
QCOMPARE(f.readAll(), content);
QFile::remove(aFile);
}
示例5: getQueueRequestCompleted
void NetFlixQueueProxy::getQueueRequestCompleted(int retCode, QString body){
qDebug() << "queue request completed!!";
qDebug() << retCode;
QXmlQuery query;
QString result;
QBuffer device;
device.setData(body.toUtf8());
device.open(QIODevice::ReadOnly);
query.bindVariable("netflix_queue",&device);
query.setQuery(QUrl("qrc:/queries/queue.xq"));
if (query.isValid())
{
if (query.evaluateTo(&result))
qDebug() << result;
else
qDebug() << "Evaluate failed";
}
else
qDebug() << "setQuery Failed.";
}
示例6: start
void RequestEtagJob::start()
{
QNetworkRequest req;
if (_account && _account->rootEtagChangesNotOnlySubFolderEtags()) {
// Fixed from 8.1 https://github.com/owncloud/client/issues/3730
req.setRawHeader("Depth", "0");
} else {
// Let's always request all entries inside a directory. There are/were bugs in the server
// where a root or root-folder ETag is not updated when its contents change. We work around
// this by concatenating the ETags of the root and its contents.
req.setRawHeader("Depth", "1");
// See https://github.com/owncloud/core/issues/5255 and others
}
QByteArray xml("<?xml version=\"1.0\" ?>\n"
"<d:propfind xmlns:d=\"DAV:\">\n"
" <d:prop>\n"
" <d:getetag/>\n"
" </d:prop>\n"
"</d:propfind>\n");
QBuffer *buf = new QBuffer(this);
buf->setData(xml);
buf->open(QIODevice::ReadOnly);
// assumes ownership
sendRequest("PROPFIND", makeDavUrl(path()), req, buf);
if (reply()->error() != QNetworkReply::NoError) {
qCWarning(lcEtagJob) << "request network error: " << reply()->errorString();
}
AbstractNetworkJob::start();
}
示例7: start
void PropfindJob::start()
{
QList<QByteArray> properties = _properties;
if (properties.isEmpty()) {
qWarning() << "Propfind with no properties!";
}
QNetworkRequest req;
req.setRawHeader("Depth", "0");
QByteArray propStr;
foreach (const QByteArray &prop, properties) {
if (prop.contains(':')) {
int colIdx = prop.lastIndexOf(":");
propStr += " <" + prop.mid(colIdx+1) + " xmlns=\"" + prop.left(colIdx) + "\" />\n";
} else {
propStr += " <d:" + prop + " />\n";
}
}
QByteArray xml = "<?xml version=\"1.0\" ?>\n"
"<d:propfind xmlns:d=\"DAV:\">\n"
" <d:prop>\n"
+ propStr +
" </d:prop>\n"
"</d:propfind>\n";
QBuffer *buf = new QBuffer(this);
buf->setData(xml);
buf->open(QIODevice::ReadOnly);
setReply(davRequest("PROPFIND", path(), req, buf));
buf->setParent(reply());
setupConnections(reply());
AbstractNetworkJob::start();
}
示例8: getImageType
static QString getImageType(const QByteArray& image)
{
#ifndef QXMPP_NO_GUI
QBuffer buffer;
buffer.setData(image);
buffer.open(QIODevice::ReadOnly);
QString format = QImageReader::imageFormat(&buffer);
if(format.toUpper() == "PNG")
return "image/png";
else if(format.toUpper() == "MNG")
return "video/x-mng";
else if(format.toUpper() == "GIF")
return "image/gif";
else if(format.toUpper() == "BMP")
return "image/bmp";
else if(format.toUpper() == "XPM")
return "image/x-xpm";
else if(format.toUpper() == "SVG")
return "image/svg+xml";
else if(format.toUpper() == "JPEG")
return "image/jpeg";
#endif
return "image/unknown";
}
示例9: oStream
// +-----------------------------------------------------------
bool f3::LogControl::getLogLevel(const QString &sAppName, QtMsgType &eLevel) const
{
// Try to lock the shared memory
if(!m_pSharedMemory->lock())
return false;
// Read the map from the shared memory
QBuffer oBuffer;
QDataStream oStream(&oBuffer);
oBuffer.setData((char *) m_pSharedMemory->constData(), m_pSharedMemory->size());
oBuffer.open(QBuffer::ReadOnly);
QMap<QString, int> mApps;
oStream >> mApps;
// Unlock the shared memory before returning
m_pSharedMemory->unlock();
// Return the stored value for the application name (if found on the table)
int iLevel = mApps[sAppName];
if(iLevel != 0)
{
eLevel = (QtMsgType) (iLevel - 1);
return true;
}
else
return false;
}
示例10: UpdateUserInfo
int CUserInfoXmpp::UpdateUserInfo(const QXmppVCardIq &vCard, QString jid)
{
//if(!vCard.fullName().isEmpty())
// m_szName = vCard.fullName();
m_szNick = vCard.nickName();
m_Birthday = vCard.birthday();
m_szEmail = vCard.email();
m_szDescription = vCard.description();
if(!jid.isEmpty() && m_szJid.isEmpty())
m_szJid = jid;
//保存头像
QByteArray photo = vCard.photo();
QBuffer buffer;
buffer.setData(photo);
buffer.open(QIODevice::ReadOnly);
QImageReader imageReader(&buffer);
m_imgPhoto = imageReader.read();
buffer.close();
//保存头像到本地
QImageWriter imageWriter(CGlobal::Instance()->GetFileUserAvatar(GetId()), "png");
if(!imageWriter.write(GetPhoto()))
LOG_MODEL_ERROR("CUserInfo", "Save avater error, %s", imageWriter.errorString().toStdString().c_str());
return 0;
}
示例11: open
bool FormWindowEditor::open(QString *errorString, const QString &fileName, const QString &realFileName)
{
if (Designer::Constants::Internal::debug)
qDebug() << "FormWindowEditor::open" << fileName;
auto document = qobject_cast<FormWindowFile *>(textDocument());
QDesignerFormWindowInterface *form = document->formWindow();
QTC_ASSERT(form, return false);
if (fileName.isEmpty())
return true;
const QFileInfo fi(fileName);
const QString absfileName = fi.absoluteFilePath();
QString contents;
if (document->read(absfileName, &contents, errorString) != Utils::TextFileFormat::ReadSuccess)
return false;
form->setFileName(absfileName);
const QByteArray contentsBA = contents.toUtf8();
QBuffer str;
str.setData(contentsBA);
str.open(QIODevice::ReadOnly);
if (!form->setContents(&str, errorString))
return false;
form->setDirty(fileName != realFileName);
document->syncXmlFromFormWindow();
document->setFilePath(absfileName);
document->setShouldAutoSave(false);
document->resourceHandler()->updateResources(true);
return true;
}
示例12: QBuffer
QBuffer *createBuffer (const QByteArray &data = "0123456789",
QIODevice::OpenMode mode = QIODevice::ReadWrite) {
QBuffer *buffer = new QBuffer (this);
buffer->setData (data);
buffer->open (mode);
return buffer;
}
示例13: path
bool
readStream(POLE::Storage& storage, const char* streampath, QBuffer& buffer)
{
std::string path(streampath);
if (storage.isDirectory("PP97_DUALSTORAGE")) {
qDebug() << "PP97_DUALSTORAGE";
path = "PP97_DUALSTORAGE" + path;
}
POLE::Stream stream(&storage, path);
if (stream.fail()) {
qDebug() << "Unable to construct " << streampath << "stream";
return false;
}
QByteArray array;
array.resize(stream.size());
unsigned long r = stream.read((unsigned char*)array.data(), stream.size());
if (r != stream.size()) {
qDebug() << "Error while reading from " << streampath << "stream";
return false;
}
buffer.setData(array);
buffer.open(QIODevice::ReadOnly);
return true;
}
示例14: start
void RequestEtagJob::start()
{
QNetworkRequest req;
if (path().isEmpty() || path() == QLatin1String("/")) {
/* For the root directory, we need to query the etags of all the sub directories
* because, at the time I am writing this comment (Owncloud 5.0.9), the etag of the
* root directory is not updated when the sub directories changes */
req.setRawHeader("Depth", "1");
} else {
req.setRawHeader("Depth", "0");
}
QByteArray xml("<?xml version=\"1.0\" ?>\n"
"<d:propfind xmlns:d=\"DAV:\">\n"
" <d:prop>\n"
" <d:getetag/>\n"
" </d:prop>\n"
"</d:propfind>\n");
QBuffer *buf = new QBuffer(this);
buf->setData(xml);
buf->open(QIODevice::ReadOnly);
// assumes ownership
setReply(davRequest("PROPFIND", path(), req, buf));
buf->setParent(reply());
setupConnections(reply());
if( reply()->error() != QNetworkReply::NoError ) {
qDebug() << "getting etag: request network error: " << reply()->errorString();
}
AbstractNetworkJob::start();
}
示例15: tst_invalidFrames
void tst_WebSocketFrame::tst_invalidFrames()
{
QFETCH(int, rsv1);
QFETCH(int, rsv2);
QFETCH(int, rsv3);
QFETCH(quint32, mask);
QFETCH(QWebSocketProtocol::OpCode, opCode);
QFETCH(bool, isFinal);
QFETCH(QByteArray, payload);
QFETCH(QWebSocketProtocol::CloseCode, expectedError);
FrameHelper helper;
helper.setRsv1(rsv1);
helper.setRsv2(rsv2);
helper.setRsv3(rsv3);
helper.setMask(mask);
helper.setOpCode(opCode);
helper.setFinalFrame(isFinal);
helper.setPayload(payload);
QByteArray wireRepresentation = helper.wireRepresentation();
QBuffer buffer;
buffer.setData(wireRepresentation);
buffer.open(QIODevice::ReadOnly);
QWebSocketFrame frame = QWebSocketFrame::readFrame(&buffer);
buffer.close();
QVERIFY(!frame.isValid());
QCOMPARE(frame.closeCode(), expectedError);
}