本文整理汇总了C++中QByteArray::size方法的典型用法代码示例。如果您正苦于以下问题:C++ QByteArray::size方法的具体用法?C++ QByteArray::size怎么用?C++ QByteArray::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QByteArray
的用法示例。
在下文中一共展示了QByteArray::size方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
bool DataBus::PacketHeader::parse(const QByteArray &packetHeaderData,
const int startIndex,
PacketHeader *packetHeader)
{
// Check input parameters
if ((startIndex < 0) ||
(startIndex >= packetHeaderData.size()))
{
// Error, invalid start index
return false;
}
if ((packetHeaderData.size() - startIndex) < 6)
{
// Error, data is not big enough
return false;
}
if (packetHeader == 0)
{
// Error, null pointer
return false;
}
// Parse header checksum
quint8 headerChecksum = (quint8)packetHeaderData.at(startIndex + 5);
bool ok = false;
quint8 calculatedChecksum = DataBus::calculateChecksum(packetHeaderData, startIndex, 5, &ok);
if ((ok == false) ||
(headerChecksum != calculatedChecksum))
{
// Error, invalid checksum
return false;
}
// Parse source
quint8 source = (quint8)packetHeaderData.at(startIndex + 0);
// Parse destination
quint8 destination = (quint8)packetHeaderData.at(startIndex + 1);
// Parse packet type
quint8 packetTypeValue = (quint8)packetHeaderData.at(startIndex + 2);
if (packetTypeValue > PacketType_ExecuteClientMethodResponse)
{
// Error, invalid packet type value
return false;
}
PacketType packetType = (PacketType)packetTypeValue;
// Parse packet ID
quint8 packetId = (quint8)packetHeaderData.at(startIndex + 3);
// Parse payload size
quint8 payloadSize = (quint8)packetHeaderData.at(startIndex + 4);
// Save values
packetHeader->setSource(source);
packetHeader->setDestination(destination);
packetHeader->setPacketType(packetType);
packetHeader->setPacketId(packetId);
packetHeader->setPayloadSize(payloadSize);
// Success
return true;
}
示例2: macQueryInternal
QList<QNetworkProxy> macQueryInternal(const QNetworkProxyQuery &query)
{
QList<QNetworkProxy> result;
// obtain a dictionary to the proxy settings:
CFDictionaryRef dict = SCDynamicStoreCopyProxies(NULL);
if (!dict) {
qWarning("QNetworkProxyFactory::systemProxyForQuery: SCDynamicStoreCopyProxies returned NULL");
return result; // failed
}
if (isHostExcluded(dict, query.peerHostName())) {
CFRelease(dict);
return result; // no proxy for this host
}
// is there a PAC enabled? If so, use it first.
CFNumberRef pacEnabled;
if ((pacEnabled = (CFNumberRef)CFDictionaryGetValue(dict, kSCPropNetProxiesProxyAutoConfigEnable))) {
int enabled;
if (CFNumberGetValue(pacEnabled, kCFNumberIntType, &enabled) && enabled) {
// PAC is enabled
// kSCPropNetProxiesProxyAutoConfigURLString returns the URL string
// as entered in the system proxy configuration dialog
CFStringRef pacLocationSetting = (CFStringRef)CFDictionaryGetValue(dict, kSCPropNetProxiesProxyAutoConfigURLString);
QCFType<CFStringRef> cfPacLocation = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, pacLocationSetting, NULL, NULL,
kCFStringEncodingUTF8);
if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) {
QCFType<CFDataRef> pacData;
QCFType<CFURLRef> pacUrl = CFURLCreateWithString(kCFAllocatorDefault, cfPacLocation, NULL);
if (!pacUrl) {
qWarning("Invalid PAC URL \"%s\"", qPrintable(QCFString::toQString(cfPacLocation)));
return result;
}
SInt32 errorCode;
if (!CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault, pacUrl, &pacData, NULL, NULL, &errorCode)) {
QString pacLocation = QCFString::toQString(cfPacLocation);
qWarning("Unable to get the PAC script at \"%s\" (%s)", qPrintable(pacLocation), cfurlErrorDescription(errorCode));
return result;
}
if (!pacData) {
qWarning("\"%s\" returned an empty PAC script", qPrintable(QCFString::toQString(cfPacLocation)));
return result;
}
QCFType<CFStringRef> pacScript = CFStringCreateFromExternalRepresentation(kCFAllocatorDefault, pacData, kCFStringEncodingISOLatin1);
if (!pacScript) {
// This should never happen, but the documentation says it may return NULL if there was a problem creating the object.
QString pacLocation = QCFString::toQString(cfPacLocation);
qWarning("Unable to read the PAC script at \"%s\"", qPrintable(pacLocation));
return result;
}
QByteArray encodedURL = query.url().toEncoded(); // converted to UTF-8
if (encodedURL.isEmpty()) {
return result; // Invalid URL, abort
}
QCFType<CFURLRef> targetURL = CFURLCreateWithBytes(kCFAllocatorDefault, (UInt8*)encodedURL.data(), encodedURL.size(), kCFStringEncodingUTF8, NULL);
if (!targetURL) {
return result; // URL creation problem, abort
}
QCFType<CFErrorRef> pacError;
QCFType<CFArrayRef> proxies = CFNetworkCopyProxiesForAutoConfigurationScript(pacScript, targetURL, &pacError);
if (!proxies) {
QString pacLocation = QCFString::toQString(cfPacLocation);
QCFType<CFStringRef> pacErrorDescription = CFErrorCopyDescription(pacError);
qWarning("Execution of PAC script at \"%s\" failed: %s", qPrintable(pacLocation), qPrintable(QCFString::toQString(pacErrorDescription)));
return result;
}
CFIndex size = CFArrayGetCount(proxies);
for (CFIndex i = 0; i < size; ++i) {
CFDictionaryRef proxy = (CFDictionaryRef)CFArrayGetValueAtIndex(proxies, i);
result << proxyFromDictionary(proxy);
}
return result;
} else {
QString pacLocation = QCFString::toQString(cfPacLocation);
qWarning("Mac system proxy: PAC script at \"%s\" not handled", qPrintable(pacLocation));
}
}
}
// no PAC, decide which proxy we're looking for based on the query
bool isHttps = false;
QString protocol = query.protocolTag().toLower();
// try the protocol-specific proxy
QNetworkProxy protocolSpecificProxy;
if (protocol == QLatin1String("ftp")) {
protocolSpecificProxy =
proxyFromDictionary(dict, QNetworkProxy::FtpCachingProxy,
kSCPropNetProxiesFTPEnable,
kSCPropNetProxiesFTPProxy,
kSCPropNetProxiesFTPPort);
} else if (protocol == QLatin1String("http")) {
protocolSpecificProxy =
proxyFromDictionary(dict, QNetworkProxy::HttpProxy,
//.........这里部分代码省略.........
示例3: hasNext
//! [8]
bool ByteArrayClassPropertyIterator::hasNext() const
{
QByteArray *ba = qscriptvalue_cast<QByteArray*>(object().data());
return m_index < ba->size();
}
示例4: toBack
void ByteArrayClassPropertyIterator::toBack()
{
QByteArray *ba = qscriptvalue_cast<QByteArray*>(object().data());
m_index = ba->size();
m_last = -1;
}
示例5: write
qint64 KoStore::write(const QByteArray& data)
{
return write(data.data(), data.size()); // see below
}
示例6: mfile
//*****************************************************************************
mlMainWindow::mlMainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::mlMainWindow),
uniConverter(0) {
ui->setupUi(this);
//-------------------------------------------------------------------------
// Load the mapping file
QByteArray map;
QFile mfile(":/maps/maps/mollana-urdu.tec");
if( mfile.open( QIODevice::ReadOnly ) ) {
qDebug() << "Internal Urdu mapping file loaded...";
map = mfile.readAll();
mfile.close();
qDebug() << "Map size: " << map.size() << "";
} else {
qDebug() << "Unable to open Internal Urdu mapping file for reading...\n";
//raise exception
return;
}
//-------------------------------------------------------------------------
// Create the converter
uniConverter = new TECkitConverter( map );
if( !uniConverter->isValid() ) {
qDebug() << "Unable to create Unicode TECkit converter...";
//raise exception
return;
}
//-------------------------------------------------------------------------
// Toolbars
ui->mainToolBar->addAction( ui->actionNew );
ui->mainToolBar->addAction( ui->actionOpen );
ui->mainToolBar->addAction( ui->actionSave );
ui->mainToolBar->addSeparator();
ui->mainToolBar->addAction( ui->actionUndo );
ui->mainToolBar->addAction( ui->actionRedo );
ui->mainToolBar->addSeparator();
ui->mainToolBar->addAction( ui->actionCopy );
ui->mainToolBar->addAction( ui->actionCut );
ui->mainToolBar->addAction( ui->actionPaste );
ui->mainToolBar->addSeparator();
ui->mainToolBar->addAction( ui->actionUnicodeViewFont );
ui->mainToolBar->addAction( ui->actionWordWrap );
ui->mainToolBar->addSeparator();
//-------------------------------------------------------------------------
// Signal/Slots
connect(ui->actionNew, SIGNAL(triggered()),
this, SLOT(newFile()) );
connect(ui->actionOpen, SIGNAL(triggered()),
this, SLOT(open()) );
connect(ui->actionSave, SIGNAL(triggered()),
this, SLOT(save()) );
connect(ui->actionSaveAs, SIGNAL(triggered()),
this, SLOT(saveAs()) );
connect(ui->actionQuit, SIGNAL(triggered()),
this, SLOT(close()) );
connect(ui->actionSelectAll,SIGNAL(triggered()),
ui->tbxEditor, SLOT(selectAll()) );
connect(ui->actionEditorFont,
SIGNAL(triggered()),
this, SLOT(editorFontChanged()) );
connect(ui->actionUnicodeViewFont,
SIGNAL(triggered()),
this, SLOT(unicodeFontChanged()) );
connect(ui->actionAbout, SIGNAL(triggered()),
this, SLOT(about()) );
connect(ui->tbxEditor->document(),
SIGNAL(contentsChanged()),
this, SLOT(documentModified()) );
// Copy, Cut & Paste
connect(ui->actionCut, SIGNAL(triggered()),
ui->tbxEditor, SLOT(cut()) );
connect(ui->actionCopy, SIGNAL(triggered()),
ui->tbxEditor, SLOT(copy()) );
connect(ui->actionPaste, SIGNAL(triggered()),
ui->tbxEditor, SLOT(paste()) );
connect(ui->tbxEditor, SIGNAL(copyAvailable(bool)),
ui->actionCopy, SLOT(setEnabled(bool)) );
connect(ui->tbxEditor, SIGNAL(copyAvailable(bool)),
ui->actionCut, SLOT(setEnabled(bool)) );
// Undo & Redo
connect(ui->actionUndo, SIGNAL(triggered()),
ui->tbxEditor, SLOT(undo()) );
connect(ui->actionCopy, SIGNAL(triggered()),
ui->tbxEditor, SLOT(redo()) );
connect(ui->tbxEditor, SIGNAL(undoAvailable(bool)),
ui->actionUndo, SLOT(setEnabled(bool)) );
//.........这里部分代码省略.........
示例7: SendSubscribeRequest
int UPNPSubscription::SendSubscribeRequest(const QString &callback,
const QString &usn,
const QUrl &url,
const QString &path,
const QString &uuidin,
QString &uuidout)
{
QString host = url.host();
int port = url.port();
QByteArray sub;
QTextStream data(&sub);
data.setCodec(QTextCodec::codecForName("UTF-8"));
// N.B. Play On needs an extra space between SUBSCRIBE and path...
data << QString("SUBSCRIBE %1 HTTP/1.1\r\n").arg(path);
data << QString("HOST: %1:%2\r\n").arg(host).arg(QString::number(port));
if (uuidin.isEmpty()) // new subscription
{
data << QString("CALLBACK: <%1%2>\r\n")
.arg(callback).arg(usn);
data << "NT: upnp:event\r\n";
}
else // renewal
data << QString("SID: uuid:%1\r\n").arg(uuidin);
data << QString("TIMEOUT: Second-%1\r\n").arg(SUBSCRIPTION_TIME);
data << "\r\n";
data.flush();
LOG(VB_UPNP, LOG_DEBUG, "\n\n" + sub);
MSocketDevice *sockdev = new MSocketDevice(MSocketDevice::Stream);
BufferedSocketDevice *sock = new BufferedSocketDevice(sockdev);
sockdev->setBlocking(true);
QString uuid;
QString timeout;
uint result = 0;
if (sock->Connect(QHostAddress(host), port))
{
if (sock->WriteBlockDirect(sub.constData(), sub.size()) != -1)
{
bool ok = false;
QString line = sock->ReadLine(MAX_WAIT);
while (!line.isEmpty())
{
LOG(VB_UPNP, LOG_DEBUG, line);
if (line.contains("HTTP/1.1 200 OK", Qt::CaseInsensitive))
ok = true;
if (line.startsWith("SID:", Qt::CaseInsensitive))
uuid = line.mid(4).trimmed().mid(5).trimmed();
if (line.startsWith("TIMEOUT:", Qt::CaseInsensitive))
timeout = line.mid(8).trimmed().mid(7).trimmed();
if (ok && !uuid.isEmpty() && !timeout.isEmpty())
break;
line = sock->ReadLine(MAX_WAIT);
}
if (ok && !uuid.isEmpty() && !timeout.isEmpty())
{
uuidout = uuid;
result = timeout.toUInt();
}
else
{
LOG(VB_GENERAL, LOG_ERR,
QString("Failed to subscribe to %1").arg(usn));
}
}
else
{
LOG(VB_GENERAL, LOG_ERR, QString("Socket write error for %1:%2")
.arg(host).arg(port));
}
sock->Close();
}
else
{
LOG(VB_GENERAL, LOG_ERR, QString("Failed to open socket for %1:%2")
.arg(host).arg(port));
}
delete sock;
delete sockdev;
return result;
}
示例8: readStandardOutput
void ExecuteFilter::readStandardOutput()
{
QByteArray data = m_process->readAllStandardOutput();
MessageManager::write(QTextCodec::codecForLocale()->toUnicode(data.constData(), data.size(),
&m_stdoutState));
}
示例9: getFullConfig
QByteArray GameCFGWidget::getFullConfig() const
{
QList<QByteArray> bcfg;
int mapgen = pMapContainer->get_mapgen();
if (Scripts->currentIndex() > 0)
{
bcfg << QString("escript Scripts/Multiplayer/%1.lua").arg(Scripts->itemData(Scripts->currentIndex(), GameStyleModel::ScriptRole).toString()).toUtf8();
}
QString currentMap = pMapContainer->getCurrentMap();
if (currentMap.size() > 0)
{
bcfg << QString("emap " + currentMap).toUtf8();
// engine should figure it out on its own
// if(pMapContainer->getCurrentIsMission())
// bcfg << QString("escript Maps/%1/map.lua").arg(currentMap).toUtf8();
}
bcfg << QString("etheme " + pMapContainer->getCurrentTheme()).toUtf8();
bcfg << QString("eseed " + pMapContainer->getCurrentSeed()).toUtf8();
bcfg << QString("e$gmflags %1").arg(getGameFlags()).toUtf8();
bcfg << QString("e$damagepct %1").arg(schemeData(26).toInt()).toUtf8();
bcfg << QString("e$turntime %1").arg(schemeData(27).toInt() * 1000).toUtf8();
bcfg << QString("e$sd_turns %1").arg(schemeData(29).toInt()).toUtf8();
bcfg << QString("e$casefreq %1").arg(schemeData(30).toInt()).toUtf8();
bcfg << QString("e$minestime %1").arg(schemeData(31).toInt() * 1000).toUtf8();
bcfg << QString("e$minesnum %1").arg(schemeData(32).toInt()).toUtf8();
bcfg << QString("e$minedudpct %1").arg(schemeData(33).toInt()).toUtf8();
bcfg << QString("e$explosives %1").arg(schemeData(34).toInt()).toUtf8();
bcfg << QString("e$airmines %1").arg(schemeData(35).toInt()).toUtf8();
bcfg << QString("e$healthprob %1").arg(schemeData(36).toInt()).toUtf8();
bcfg << QString("e$hcaseamount %1").arg(schemeData(37).toInt()).toUtf8();
bcfg << QString("e$waterrise %1").arg(schemeData(38).toInt()).toUtf8();
bcfg << QString("e$healthdec %1").arg(schemeData(39).toInt()).toUtf8();
bcfg << QString("e$ropepct %1").arg(schemeData(40).toInt()).toUtf8();
bcfg << QString("e$getawaytime %1").arg(schemeData(41).toInt()).toUtf8();
bcfg << QString("e$worldedge %1").arg(schemeData(42).toInt()).toUtf8();
bcfg << QString("e$template_filter %1").arg(pMapContainer->getTemplateFilter()).toUtf8();
bcfg << QString("e$feature_size %1").arg(pMapContainer->getFeatureSize()).toUtf8();
bcfg << QString("e$mapgen %1").arg(mapgen).toUtf8();
if(!schemeData(43).isNull())
bcfg << QString("e$scriptparam %1").arg(schemeData(43).toString()).toUtf8();
switch (mapgen)
{
case MAPGEN_MAZE:
case MAPGEN_PERLIN:
bcfg << QString("e$maze_size %1").arg(pMapContainer->getMazeSize()).toUtf8();
break;
case MAPGEN_DRAWN:
{
QByteArray data = pMapContainer->getDrawnMapData();
while(data.size() > 0)
{
QByteArray tmp = data;
tmp.truncate(200);
tmp.prepend("edraw ");
bcfg << tmp;
data.remove(0, 200);
}
break;
}
default:
;
}
QByteArray result;
foreach(QByteArray ba, bcfg)
HWProto::addByteArrayToBuffer(result, ba);
return result;
}
示例10: wcsLayerFromUrl
QgsRasterLayer* QgsRemoteOWSBuilder::wcsLayerFromUrl( const QString &url,
const QString &layerName,
QList<QTemporaryFile*> &filesToRemove,
QList<QgsMapLayer*> &layersToRemove,
bool allowCaching ) const
{
Q_UNUSED( layerName );
Q_UNUSED( allowCaching );
QgsDebugMsg( "Entering" );
//write server url and coverage name to a temporary file
QString fileName = createTempFile();
if ( fileName.isEmpty() )
{
return 0;
}
QFile tempFile( fileName );
QTemporaryFile* tmpFile = new QTemporaryFile();
if ( !tmpFile->open() )
{
delete tmpFile;
return 0;
}
filesToRemove.push_back( tmpFile ); //make sure the temporary file gets deleted after each request
QgsDebugMsg( "opening successful" );
QgsDebugMsg( "url: " + url );
//extract server url and coverage name from string
QStringList serverSplit = url.split( "?" );
if ( serverSplit.size() < 2 )
{
QgsDebugMsg( "error, no '?' contained in url" );
return 0;
}
QString serverUrl = serverSplit.at( 0 );
QString request = serverSplit.at( 1 );
QStringList parameterSplit = request.split( "&" );
QString coverageName;
QString format;
for ( int i = 0; i < parameterSplit.size(); ++i )
{
if ( parameterSplit.at( i ).startsWith( "COVERAGE", Qt::CaseInsensitive ) )
{
coverageName = parameterSplit.at( i ).split( "=" ).at( 1 );
}
else if ( parameterSplit.at( i ).startsWith( "FORMAT", Qt::CaseInsensitive ) )
{
format = parameterSplit.at( i ).split( "=" ).at( 1 );
}
}
if ( coverageName.isEmpty() )
{
QgsDebugMsg( "coverage name is empty" );
return 0;
}
if ( format.isEmpty() )
{
format = "GeoTIFF"; //use geotiff as default
}
QgsDebugMsg( "wcs server url: " + serverUrl );
QgsDebugMsg( "coverage name: " + coverageName );
//fetch WCS layer in the current resolution as geotiff
QString wcsRequest = serverUrl + "?SERVICE=WCS&VERSION=1.0.0&REQUEST=GetCoverage&COVERAGE=" + coverageName + "&FORMAT=" + format;
//CRS (or SRS)
std::map<QString, QString>::const_iterator crsIt = mParameterMap.find( "CRS" );
if ( crsIt == mParameterMap.end() )
{
crsIt = mParameterMap.find( "SRS" );
if ( crsIt == mParameterMap.end() )
{
QgsDebugMsg( "No CRS or SRS parameter found for wcs layer, returning 0" );
return 0;
}
}
wcsRequest += "&CRS=";
wcsRequest += crsIt->second;
//width
std::map<QString, QString>::const_iterator widthIt = mParameterMap.find( "WIDTH" );
if ( widthIt == mParameterMap.end() )
{
QgsDebugMsg( "No WIDTH parameter found for wcs layer, returning 0" );
return 0;
}
wcsRequest += "&WIDTH=";
wcsRequest += widthIt->second;
//height
std::map<QString, QString>::const_iterator heightIt = mParameterMap.find( "HEIGHT" );
if ( heightIt == mParameterMap.end() )
{
QgsDebugMsg( "No HEIGHT parameter found for wcs layer, returning 0" );
//.........这里部分代码省略.........
示例11: encodeMessage
bool BaseTransport::encodeMessage( const SyncMLMessage& aMessage, QByteArray& aData )
{
FUNCTION_CALL_TRACE;
bool success = false;
if( useWbXml() )
{
LibWbXML2Encoder encoder;
if( encoder.encodeToWbXML( aMessage,
aMessage.getProtocolVersion(),
aData ) )
{
LOG_DEBUG( "WbXML encoding successful" );
#ifndef QT_NO_DEBUG
QByteArray xml;
if( encoder.encodeToXML( aMessage,
aMessage.getProtocolVersion(),
xml, true ) )
{
LOG_PROTOCOL( "\nSending message:\n=========\n" << xml << "\n=========size:"<<xml.size());
}
else
{
LOG_PROTOCOL( "Failed to print request" );
}
#endif // QT_NO_DEBUG
success = true;
}
else
{
LOG_CRITICAL( "WbXML encoding failed!" );
}
}
else
{
QtEncoder encoder;
if( encoder.encodeToXML( aMessage, aData, false ) )
{
LOG_DEBUG( "XML encoding successful" );
#ifndef QT_NO_DEBUG
QByteArray xml;
if( encoder.encodeToXML( aMessage, xml, true ) ) {
LOG_PROTOCOL( "\nSending message:\n=========\n" << xml << "\n=========");
} else {
LOG_PROTOCOL( "Failed to print request" );
}
#endif // QT_NO_DEBUG
success = true;
}
else
{
LOG_CRITICAL( "XML encoding failed!" );
}
}
return success;
}
示例12: addASSEvent
void libASS::addASSEvent( const QByteArray &event )
{
if ( !ass_sub_track || !ass_sub_renderer || event.isEmpty() )
return;
ass_process_data( ass_sub_track, ( char * )event.data(), event.size() );
}
示例13: addFont
void libASS::addFont( const QByteArray &name, const QByteArray &data )
{
ass_add_font( ass, ( char * )name.data(), ( char * )data.data(), data.size() );
}