本文整理汇总了C++中QByteArray::startsWith方法的典型用法代码示例。如果您正苦于以下问题:C++ QByteArray::startsWith方法的具体用法?C++ QByteArray::startsWith怎么用?C++ QByteArray::startsWith使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QByteArray
的用法示例。
在下文中一共展示了QByteArray::startsWith方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onClientRead
void HWNetUdpServer::onClientRead()
{
while (pUdpSocket->hasPendingDatagrams())
{
QByteArray datagram;
datagram.resize(pUdpSocket->pendingDatagramSize());
QHostAddress clientAddr;
quint16 clientPort;
pUdpSocket->readDatagram(datagram.data(), datagram.size(), &clientAddr, &clientPort);
if(datagram.startsWith("hedgewars client"))
{
// send answer to client
pUdpSocket->writeDatagram(QString("hedgewars server\n%1").arg(m_descr).toUtf8(), clientAddr, clientPort);
}
}
}
示例2: unpack
Message PUMProtocol::unpack(QByteArray packed)
{
Message msg;
if(packed.startsWith(START_SYMBOL) && packed.endsWith(END_SYMBOL))
{
msg.address = (DeviceAddress)packed.at(1);
msg.command = (CommandType) packed.at(2);
msg.params = QString(packed.mid(3,packed.length()-4));
}
else
throw InvalidPackage;
return msg;
}
示例3: parseContent
/*!
Reads MIME contents from the I/O device \a dev and parses it.
*/
QByteArray TMultipartFormData::parseContent(QIODevice *dev) const
{
if (!dev->isOpen()) {
return QByteArray();
}
QByteArray content;
while (!dev->atEnd()) {
QByteArray line = dev->readLine();
if (line.startsWith(dataBoundary)) {
break;
}
content += line;
}
return content.trimmed();
}
示例4: respond
bool QXmppSaslClientScram::respond(const QByteArray &challenge, QByteArray &response)
{
Q_UNUSED(challenge);
if (m_step == 0) {
m_gs2Header = "n,,";
m_clientFirstMessageBare = "n=" + username().toUtf8() + ",r=" + m_nonce;
response = m_gs2Header + m_clientFirstMessageBare;
m_step++;
return true;
} else if (m_step == 1) {
// validate input
const QMap<char, QByteArray> input = parseGS2(challenge);
const QByteArray nonce = input.value('r');
const QByteArray salt = QByteArray::fromBase64(input.value('s'));
const int iterations = input.value('i').toInt();
if (!nonce.startsWith(m_nonce) || salt.isEmpty() || iterations < 1) {
return false;
}
// calculate proofs
const QByteArray clientFinalMessageBare = "c=" + m_gs2Header.toBase64() + ",r=" + nonce;
const QByteArray saltedPassword = deriveKeyPbkdf2(m_algorithm, password().toUtf8(), salt,
iterations, m_dklen);
const QByteArray clientKey = QMessageAuthenticationCode::hash("Client Key", saltedPassword, m_algorithm);
const QByteArray storedKey = QCryptographicHash::hash(clientKey, m_algorithm);
const QByteArray authMessage = m_clientFirstMessageBare + "," + challenge + "," + clientFinalMessageBare;
QByteArray clientProof = QMessageAuthenticationCode::hash(authMessage, storedKey, m_algorithm);
std::transform(clientProof.cbegin(), clientProof.cend(), clientKey.cbegin(),
clientProof.begin(), std::bit_xor<char>());
const QByteArray serverKey = QMessageAuthenticationCode::hash("Server Key", saltedPassword, m_algorithm);
m_serverSignature = QMessageAuthenticationCode::hash(authMessage, serverKey, m_algorithm);
response = clientFinalMessageBare + ",p=" + clientProof.toBase64();
m_step++;
return true;
} else if (m_step == 2) {
const QMap<char, QByteArray> input = parseGS2(challenge);
response = QByteArray();
m_step++;
return QByteArray::fromBase64(input.value('v')) == m_serverSignature;
} else {
warning("QXmppSaslClientPlain : Invalid step");
return false;
}
}
示例5: moveDownCustomCommand
void DlgCustomToolbarsImp::moveDownCustomCommand(const QString& name, const QByteArray& userdata)
{
QVariant data = workbenchBox->itemData(workbenchBox->currentIndex(), Qt::UserRole);
Workbench* w = WorkbenchManager::instance()->active();
if (w && w->name() == std::string((const char*)data.toByteArray())) {
QList<QToolBar*> bars = getMainWindow()->findChildren<QToolBar*>(name);
if (bars.size() != 1)
return;
QByteArray cmd = userdata;
int numSep = 0, indexSep = 0;
if (cmd.startsWith("Separator")) {
numSep = cmd.mid(9).toInt();
cmd = "Separator";
}
QList<QAction*> actions = bars.front()->actions();
for (QList<QAction*>::ConstIterator it = actions.begin(); it != actions.end(); ++it) {
if ((*it)->data().toByteArray() == cmd) {
// if we move a separator then make sure to pick up the right one
if (numSep > 0) {
if (++indexSep < numSep)
continue;
}
QAction* act = *it;
if (*it == actions.back())
break; // we're already on the last element
++it;
// second last item
if (*it == actions.back()) {
QList<QAction*> group = getActionGroup(act);
bars.front()->removeAction(act);
bars.front()->addAction(act);
if (!group.isEmpty())
setActionGroup(act, group);
break;
}
++it;
QList<QAction*> group = getActionGroup(act);
bars.front()->removeAction(act);
bars.front()->insertAction(*it, act);
if (!group.isEmpty())
setActionGroup(act, group);
break;
}
}
}
}
示例6: getResponse
void HttpThread::getResponse()
{
QHttp::ConnectionMode mode = (m_url.scheme().toLower() == "https") ?
QHttp::ConnectionModeHttps : QHttp::ConnectionModeHttp;
m_http->setHost(m_url.host(), mode, m_url.port() == -1 ? 0 : m_url.port());
QByteArray path = QUrl::toPercentEncoding(m_url.path(), "/?&=");
qDebug() << "Attempting to get" << path;
if (path.isEmpty()) path = "/";
if (!path.startsWith("/")) path.prepend("/");
qDebug() << "Attempting to get" << path;
m_buffer = new QBuffer();
m_buffer->open(QBuffer::ReadWrite);
m_httpGetId = m_http->get(path, m_buffer);
}
示例7: getPrivateKey
QCA::PrivateKey EncryptioNgSimliteDecryptor::getPrivateKey(const Key &key)
{
QByteArray keyData = key.key().toByteArray().trimmed();
if (!keyData.startsWith(BEGIN_RSA_PRIVATE_KEY) || !keyData.endsWith(END_RSA_PRIVATE_KEY))
{
Valid = false;
return QCA::PrivateKey();
}
keyData = keyData.mid(BEGIN_RSA_PRIVATE_KEY_LENGTH, keyData.length() - BEGIN_RSA_PRIVATE_KEY_LENGTH - END_RSA_PRIVATE_KEY_LENGTH).replace('\r', "").trimmed();
QCA::SecureArray certificate;
QCA::Base64 decoder;
decoder.setLineBreaksEnabled(true);
certificate = decoder.decode(keyData);
// just some fake security added
keyData.fill(' ', keyData.size());
keyData.clear();
if (!decoder.ok())
{
Valid = false;
return QCA::PrivateKey();
}
PKCS1Certificate::ConversionStatus status;
PKCS1Certificate pkcs1;
QCA::PrivateKey privateKey = pkcs1.privateKeyFromDER(certificate, status);
if (PKCS1Certificate::OK != status)
{
Valid = false;
return QCA::PrivateKey();
}
if (!privateKey.canDecrypt())
{
Valid = false;
return QCA::PrivateKey();
}
Valid = true;
return privateKey;
}
示例8: currentLocation
/**
* for now our data is just the MAC address of the default gateway
*/
NetworkLocation NetworkLocation::currentLocation()
{
QProcess ip;
ip.start("/sbin/ip", QStringList() << "route");
if (!ip.waitForStarted())
return NetworkLocation();
if (!ip.waitForFinished())
return NetworkLocation();
QByteArray gwIp;
while (ip.canReadLine()) {
QByteArray line = ip.readLine();
if (line.startsWith("default")) {
QList<QByteArray> parts = line.split(' ');
gwIp = parts[2];
break;
}
}
if (gwIp.isEmpty())
return NetworkLocation();
QProcess arp;
arp.start("/sbin/arp", QStringList() << "-a");
if (!arp.waitForStarted())
return NetworkLocation();
if (!arp.waitForFinished())
return NetworkLocation();
QByteArray gwMAC;
while (arp.canReadLine()) {
QByteArray line = arp.readLine();
if (line.contains(gwIp)) {
QList<QByteArray> parts = line.split(' ');
gwMAC = parts[3];
break;
}
}
if (gwMAC.isEmpty())
return NetworkLocation();
return NetworkLocation(gwMAC);
}
示例9: loadLogFile
/*
tokens:
0 = timestamp
1 = Transmission direction
2 = Channel
3 = ID
4 = Type (s = standard, I believe x = extended)
5 = Data byte length
6-x = The data bytes
Sample chunk of a busmaster log:
***BUSMASTER Ver 2.4.0***
***PROTOCOL CAN***
***NOTE: PLEASE DO NOT EDIT THIS DOCUMENT***
***[START LOGGING SESSION]***
***START DATE AND TIME 8:8:2014 11:49:7:965***
***HEX***
***SYSTEM MODE***
***START CHANNEL BAUD RATE***
***CHANNEL 1 - Kvaser - Kvaser Leaf Light HS #0 (Channel 0), Serial Number- 0, Firmware- 0x00000037 0x00020000 - 500000 bps***
***END CHANNEL BAUD RATE***
***START DATABASE FILES (DBF/DBC)***
***END OF DATABASE FILES (DBF/DBC)***
***<Time><Tx/Rx><Channel><CAN ID><Type><DLC><DataBytes>***
11:49:12:9420 Rx 1 0x023 s 1 40
11:49:12:9440 Rx 1 0x460 s 8 03 E0 00 00 C0 00 00 00
11:49:12:9530 Rx 1 0x023 s 1 40
11:49:12:9680 Rx 1 0x408 s 8 0F 02 00 30 00 00 7F 00
11:49:12:9680 Rx 1 0x40B s 8 00 00 00 00 00 10 60 00
11:49:12:9690 Rx 1 0x045 s 8 40 00 00 00 00 00 00 00
*/
bool FrameFileIO::loadLogFile(QString filename, QVector<CANFrame>* frames)
{
QFile *inFile = new QFile(filename);
CANFrame thisFrame;
QByteArray line;
uint64_t timeStamp = Utility::GetTimeMS();
int lineCounter = 0;
if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text))
{
delete inFile;
return false;
}
line = inFile->readLine(); //read out the header first and discard it.
while (!inFile->atEnd()) {
lineCounter++;
if (lineCounter > 100)
{
qApp->processEvents();
lineCounter = 0;
}
line = inFile->readLine();
if (line.startsWith("***")) continue;
if (line.length() > 1)
{
QList<QByteArray> tokens = line.split(' ');
QList<QByteArray> timeToks = tokens[0].split(':');
timeStamp = (timeToks[0].toInt() * (1000ul * 1000ul * 60ul * 60ul)) + (timeToks[1].toInt() * (1000ul * 1000ul * 60ul))
+ (timeToks[2].toInt() * (1000ul * 1000ul)) + (timeToks[3].toInt() * 100ul);
thisFrame.timestamp = timeStamp;
thisFrame.ID = tokens[3].right(tokens[3].length() - 2).toInt(NULL, 16);
if (tokens[4] == "s") thisFrame.extended = false;
else thisFrame.extended = true;
thisFrame.bus = tokens[2].toInt() - 1;
thisFrame.len = tokens[5].toInt();
for (int d = 0; d < thisFrame.len; d++) thisFrame.data[d] = tokens[d + 6].toInt(NULL, 16);
}
frames->append(thisFrame);
}
inFile->close();
delete inFile;
return true;
}
示例10: checkCondition
static bool checkCondition(const QByteArray &condition)
{
static const QSet<QByteArray> matchedConditions = activeConditions();
QList<QByteArray> conds = condition.split(' ');
for (int i = 0; i < conds.size(); ++i) {
QByteArray c = conds.at(i);
bool result = c.startsWith('!');
if (result)
c = c.mid(1);
result ^= matchedConditions.contains(c);
if (!result)
return false;
}
return true;
}
示例11: canRead
bool QSvgIOHandler::canRead() const
{
if (!device())
return false;
if (d->loaded && !d->readDone)
return true; // Will happen if we have been asked for the size
QByteArray buf = device()->peek(8);
if (buf.startsWith("\x1f\x8b")) {
setFormat("svgz");
return true;
} else if (buf.contains("<?xml") || buf.contains("<svg")) {
setFormat("svg");
return true;
}
return false;
}
示例12: isOSSDevice
bool UdevAudioInterfacePrivate::isOSSDevice(const QByteArray& lastElement, const char* lastElementAscii)
{
m_driver = Solid::AudioInterface::UnknownAudioDriver;
m_type = Solid::AudioInterface::UnknownAudioInterfaceType;
m_cardnum = 0;
m_deviceFile = m_device->property("DEVNAME").toString();
if (lastElement.startsWith("dsp")) {
m_driver = Solid::AudioInterface::OpenSoundSystem;
sscanf (lastElementAscii, "dsp%d", &m_cardnum);
}
if (lastElement.startsWith("adsp")) {
m_driver = Solid::AudioInterface::OpenSoundSystem;
sscanf (lastElementAscii, "adsp%d", &m_cardnum);
}
if (lastElement.startsWith("midi")) {
m_driver = Solid::AudioInterface::OpenSoundSystem;
sscanf (lastElementAscii, "midi%d", &m_cardnum);
}
if (lastElement.startsWith("amidi")) {
m_driver = Solid::AudioInterface::OpenSoundSystem;
sscanf (lastElementAscii, "amidi%d", &m_cardnum);
}
if (lastElement.startsWith("audio")) {
m_driver = Solid::AudioInterface::OpenSoundSystem;
sscanf (lastElementAscii, "audio%d", &m_cardnum);
}
if (lastElement.startsWith("mixer")) {
m_driver = Solid::AudioInterface::OpenSoundSystem;
m_type = Solid::AudioInterface::AudioControl;
sscanf (lastElementAscii, "mixer%d", &m_cardnum);
}
if (m_driver != Solid::AudioInterface::UnknownAudioDriver) {
m_name = cardNumberToName();
QString path;
path.sprintf("/proc/asound/card%d/pcm0p/info", m_cardnum);
QByteArray cardName = grepHelper(path, "name: ");
if (!cardName.isEmpty()) {
m_name.append(QLatin1String(" (") + cardName + ')');
} else {
m_name.append(QLatin1String(" (OSS Device)"));
}
return true;
}
return false;
}
示例13: params
bool Napisy24DownloadEngine::lookForSubtitles(QString lang) {
if (lang != "pl") return false;
const QUrl url = QUrl("http://napisy24.pl/run/CheckSubAgent.php");
auto credentials = getCredentials();
QUrlQuery params(url);
params.addQueryItem("postAction", "CheckSub");
params.addQueryItem("ua", credentials.first);
params.addQueryItem("ap", credentials.second);
params.addQueryItem("fh", checkSum);
params.addQueryItem("fs", QString::number(fileSize));
params.addQueryItem("fn", QFileInfo(movie).fileName());
// API N24 ignoruje ten parametr; jeśli nie ma napisów w żądanym języku, to i
// tak zwraca napisy w jęz. polskim params.addQueryItem("nl", lang);
QByteArray data = params.query().toUtf8();
SyncHTTP http;
QNetworkRequest req(url);
req.setHeader(QNetworkRequest::ContentTypeHeader,
"application/x-www-form-urlencoded");
QNetworkReply *reply = http.syncPost(req, data);
if (reply->error() != QNetworkReply::NoError) return false;
QByteArray respData = reply->readAll();
if (!respData.startsWith("OK-2")) return false;
QString tmpPackedFile = generateTmpPath();
QFile file(tmpPackedFile);
if (file.exists()) file.remove();
if (!file.open(QIODevice::WriteOnly)) return false;
long r = file.write(respData.mid(respData.indexOf("||") + 2));
file.close();
if (!r) return false;
subtitlesList << SubtitleInfo(lang, meta().name(), tmpPackedFile,
QFileInfo(movie).completeBaseName(), "", "txt",
SUBTITLE_UNKNOWN);
return true;
}
示例14: service
void brain_stroke_web::service(HttpRequest &request, HttpResponse &response){
QLOG_ERROR() << "debug thread" << QThread::currentThread();
QByteArray path = request.getPath();
if(path =="/getallversion"){
get_version_controller_ins.service(request,response);
return;
}
else if (path == "/getfile") {
download_version_controller_ins.service(request,response);
return;
}
else if (path == "/rename"){
//POST
if(request.getMethod() != "POST"){
netutil::write(response, 401, "wrong method");
return;
}
rename_version_controller_ins.service(request,response);
return;
}
else if(path == "/delete"){
//POST
if(request.getMethod() != "POST"){
netutil::write(response, 401, "wrong method");
return;
}
delete_version_controller_ins.service(request,response);
return;
}
else if(path.startsWith("/data")){
QString key = request.getParameter("key");
if(key != QString(inner_data_trans_key)){
response.setStatus(401,"key error");
response.write("key error");
}
else{
StaticFileController_ins->service(request,response);
return;
}
}
else{
response.setStatus(401,"no matched request");
response.write("no matched request", false);
}
}
示例15: load
void ViewerWidget::load(const QByteArray &data)
{
scene->clear();
QList<QGraphicsItem *> items;
QPixmap pixmap;
if (pixmap.loadFromData(data)) {
items << new QGraphicsPixmapItem(pixmap);
}
else if (data.startsWith("%PDF")) {
fz_stream *stream = fz_open_memory(context, (unsigned char *)data.constData(), data.length());
fz_document *doc = fz_open_document_with_stream(context, ".pdf", stream);
fz_close(stream);
int pagecount = fz_count_pages(doc);
for (int i = 0; i < pagecount; i++) {
fz_page *page = fz_load_page(doc, i);
fz_rect bounds;
fz_bound_page(doc, page, &bounds);
fz_display_list *list = fz_new_display_list(context);
fz_device *dev = fz_new_list_device(context, list);
fz_run_page(doc, page, dev, &fz_identity, NULL);
fz_free_device(dev);
fz_free_page(doc, page);
PageItem *item = new PageItem(context, list, bounds.x1 - bounds.x0, bounds.y1 - bounds.y0);
item->setCacheMode(QGraphicsItem::DeviceCoordinateCache);
items << item;
}
fz_close_document(doc);
} else {
scene->setSceneRect(0, 0, 0, 0);
return;
}
int top = 0;
QPen outline(Qt::lightGray, 2, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin);
outline.setCosmetic(true);
foreach (QGraphicsItem *item, items) {
QGraphicsRectItem *rim = new QGraphicsRectItem(item->boundingRect());
item->setPos(0, top);
rim->setPos(0, top);
rim->setPen(outline);
rim->setBrush(Qt::NoBrush);
scene->addItem(rim);
scene->addItem(item);
top += item->boundingRect().height() + SPACING;
}