本文整理汇总了C++中QByteArray::indexOf方法的典型用法代码示例。如果您正苦于以下问题:C++ QByteArray::indexOf方法的具体用法?C++ QByteArray::indexOf怎么用?C++ QByteArray::indexOf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QByteArray
的用法示例。
在下文中一共展示了QByteArray::indexOf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: tcpProcessData
void Widget::tcpProcessData(QByteArray data, QTcpSocket* socket)
{
QByteArray* recvBuffer=nullptr;
for (auto pair : tcpClientsList)
{
if (pair.first == socket)
{
recvBuffer = pair.second;
break;
}
}
if (recvBuffer == nullptr)
{
logError(tr("TCP: Error fetching the socket's associated recv buffer"));
return;
}
#if DEBUG_LOG
logMessage("tcpProcessData received : "+data);
#endif
// Login request (forwarded)
if (useRemoteLogin && recvBuffer->contains("commfunction=login&") && recvBuffer->contains("&version="))
{
logError(tr("TCP: Remote login not implemented yet."));
// We need to add the client with his IP/port/passhash to tcpPlayers if he isn't already there
Player newPlayer;
newPlayer.IP = socket->peerAddress().toIPv4Address();
newPlayer.port = socket->peerPort();
QString passhash = QString(*recvBuffer);
passhash = passhash.mid(passhash.indexOf("passhash=")+9);
passhash.truncate(passhash.indexOf('&'));
newPlayer.passhash = passhash;
logMessage(tr("IP:","IP address")+newPlayer.IP
+tr(", passhash:","A cryptographic hash of a password")+newPlayer.passhash);
// Then connect to the remote and forward the client's requests
if (!remoteLoginSock.isOpen())
{
remoteLoginSock.connectToHost(remoteLoginIP, remoteLoginPort);
remoteLoginSock.waitForConnected(remoteLoginTimeout);
if (!remoteLoginSock.isOpen())
{
logError(tr("TCP: Can't connect to remote login server : timed out"));
return;
}
}
// We just blindly send everything that we're going to remove from recvBuffer at the end of tcpProcessData
QByteArray toSend = *recvBuffer;
toSend.left(toSend.indexOf(data) + data.size());
remoteLoginSock.write(toSend);
}
else if (useRemoteLogin && recvBuffer->contains("Server:")) // Login reply (forwarded)
{
logError(tr("TCP: Remote login not implemented yet."));
// First we need to find a player matching the received passhash in tcpPlayers
// Use the player's IP/port to find a matching socket in tcpClientsList
// The login headers are all the same, so we can just use loginHeader.bin and send back data
}
else if (recvBuffer->contains("commfunction=login&") && recvBuffer->contains("&version=")) // Login request
{
QString postData = QString(*recvBuffer);
*recvBuffer = recvBuffer->right(postData.size()-postData.indexOf("version=")-8-4); // 4 : size of version number (ie:version=1344)
logMessage(tr("TCP: Login request received :"));
QFile file(QString(NETDATAPATH)+"/loginHeader.bin");
QFile fileServersList(SERVERSLISTFILEPATH);
QFile fileBadPassword(QString(NETDATAPATH)+"/loginWrongPassword.bin");
QFile fileMaxRegistration(QString(NETDATAPATH)+"/loginMaxRegistered.bin");
if (!file.open(QIODevice::ReadOnly) || !fileBadPassword.open(QIODevice::ReadOnly)
|| !fileMaxRegistration.open(QIODevice::ReadOnly) || !fileServersList.open(QIODevice::ReadOnly))
{
logError(tr("TCP: Error reading data files"));
stopServer();
}
else
{
logMessage(tr("Version : ","Version of the client software")
+postData.mid(postData.indexOf("version=")+8));
bool ok=true;
postData = postData.right(postData.size()-postData.indexOf("username=")-9);
QString username = postData;
username.truncate(postData.indexOf('&'));
postData = postData.right(postData.size()-postData.indexOf("passhash=")-9);
QString passhash = postData;
passhash.truncate(postData.indexOf('&'));
logMessage(tr("IP : ","An IP address")+socket->peerAddress().toString());
logMessage(tr("Username : ")+username);
logMessage(tr("Passhash : ","A cryptographic hash of a password")+passhash);
// Add player to the players list
Player* player = Player::findPlayer(Player::tcpPlayers, username);
if (player->name != username) // Not found, create a new player
{
// Check max registered number
if (Player::tcpPlayers.size() >= maxRegistered)
{
logError(tr("TCP: Registration failed, too many players registered"));
socket->write(fileMaxRegistration.readAll());
ok = false;
}
//.........这里部分代码省略.........
示例2: parser
void Message_Handler::parser(QByteArray data){
QByteArray tmp;
int digit = 1;
int i=0;
int sign=0;
if(data.startsWith('{')){
while(data.count() > 0){
data.remove(0,data.indexOf('"')+1);
tmp = data.left(data.indexOf('"'));
data.remove(0,data.indexOf('"')+1);
if(QString(tmp)=="MessageType"){
data.remove(0,data.indexOf(':')+2);
tmp = data.left(data.indexOf('"'));
data.remove(0,data.indexOf(',')+1);
if(QString(tmp)=="GetState")
msg.MessageType = 1;
else if(QString(tmp)=="GetPID")
msg.MessageType = 2;
else if(QString(tmp)=="SetPID")
msg.MessageType = 3;
else if(QString(tmp)=="SetMainPower")
msg.MessageType = 4;
else
msg.MessageType = 0;
}
else if(QString(tmp)=="KalmanXangle"){
data.remove(0,data.indexOf(':')+1);
msg.KalmanX = 0;
sign = data.indexOf(',');
if(sign == -1) sign = data.indexOf('}');
digit = 1;
for(i= sign;i>=0;i--)
{
if(data[i]=='-') msg.KalmanX*=-1;
if(data[i] <='9' && data[i] >= '0')
{
msg.KalmanX += digit * (data[i]-0x30);
digit *= 10;
}
}
msg.KalmanX /= 1000;
data.remove(0,sign+1);
}
else if(QString(tmp)=="KalmanYangle"){
data.remove(0,data.indexOf(':')+1);
msg.KalmanY = 0;
sign = data.indexOf(',');
if(sign == -1) sign = data.indexOf('}');
digit = 1;
for(i= sign;i>=0;i--)
{
if(data[i]=='-') msg.KalmanY*=-1;
if(data[i] <='9' && data[i] >= '0')
{
msg.KalmanY += digit * (data[i]-0x30);
digit *= 10;
}
}
msg.KalmanY /= 1000;
data.remove(0,sign+1);
}
else if(QString(tmp)=="Altitude"){
data.remove(0,data.indexOf(':')+1);
msg.Altitude = 0;
sign = data.indexOf(',');
if(sign == -1) sign = data.indexOf('}');
digit = 1;
for(i= sign;i>=0;i--)
{
if(data[i]=='-') msg.Altitude*=-1;
if(data[i] <='9' && data[i] >= '0')
{
msg.Altitude += digit * (data[i]-0x30);
digit *= 10;
}
}
msg.Altitude /= 1000;
data.remove(0,sign+1);
}
else if(QString(tmp)=="Ki"){
data.remove(0,data.indexOf(':')+1);
msg.Ki = 0;
sign = data.indexOf(',');
if(sign == -1) sign = data.indexOf('}');
digit = 1;
for(i= sign;i>=0;i--)
{
if(data[i]=='-') msg.Ki*=-1;
if(data[i] <='9' && data[i] >= '0')
{
msg.Ki += digit * (data[i]-0x30);
digit *= 10;
}
}
data.remove(0,sign+1);
//.........这里部分代码省略.........
示例3: skipWhitespace
/*!
Parses the MIME header \a header and returns the map of those headers.
This function is for internal use only.
*/
QMap<QByteArray, QByteArray> TMimeHeader::parseHeaderParameter(const QByteArray &header)
{
QMap<QByteArray, QByteArray> result;
int pos = 0;
for (;;) {
pos = skipWhitespace(header, pos);
if (pos >= header.length())
return result;
int semicol = header.indexOf(';', pos);
if (semicol < 0)
semicol = header.length();
QByteArray key;
int equal = header.indexOf('=', pos);
if (equal < 0 || equal > semicol) {
key = header.mid(pos, semicol - pos).trimmed();
if (!key.isEmpty()) {
result.insert(key, QByteArray());
}
pos = semicol + 1;
continue;
}
key = header.mid(pos, equal - pos).trimmed();
pos = equal + 1;
pos = skipWhitespace(header, pos);
if (pos >= header.length())
return result;
QByteArray value;
if (header[pos] == '"') {
++pos;
while (pos < header.length()) {
char c = header.at(pos);
if (c == '"') {
// end of quoted text
break;
} else if (c == '\\') {
++pos;
if (pos >= header.length()) {
// broken header
return result;
}
c = header[pos];
}
value += c;
++pos;
}
} else {
while (pos < header.length()) {
char c = header.at(pos);
if (c == ' ' || c == '\t' || c == '\r'
|| c == '\n' || c == ';') {
break;
}
value += c;
++pos;
}
}
result.insert(key, value);
}
return result;
}
示例4: wrapInFunction
void wrapInFunction()
{
//! [0]
QByteArray ba("Hello");
//! [0]
//! [1]
QByteArray ba;
ba.resize(5);
ba[0] = 0x3c;
ba[1] = 0xb8;
ba[2] = 0x64;
ba[3] = 0x18;
ba[4] = 0xca;
//! [1]
//! [2]
for (int i = 0; i < ba.size(); ++i) {
if (ba.at(i) >= 'a' && ba.at(i) <= 'f')
cout << "Found character in range [a-f]" << endl;
}
//! [2]
//! [3]
QByteArray x("and");
x.prepend("rock "); // x == "rock and"
x.append(" roll"); // x == "rock and roll"
x.replace(5, 3, "&"); // x == "rock & roll"
//! [3]
//! [4]
QByteArray ba("We must be <b>bold</b>, very <b>bold</b>");
int j = 0;
while ((j = ba.indexOf("<b>", j)) != -1) {
cout << "Found <b> tag at index position " << j << endl;
++j;
}
//! [4]
//! [5]
QByteArray().isNull(); // returns true
QByteArray().isEmpty(); // returns true
QByteArray("").isNull(); // returns false
QByteArray("").isEmpty(); // returns true
QByteArray("abc").isNull(); // returns false
QByteArray("abc").isEmpty(); // returns false
//! [5]
//! [6]
QByteArray ba("Hello");
int n = ba.size(); // n == 5
ba.data()[0]; // returns 'H'
ba.data()[4]; // returns 'o'
ba.data()[5]; // returns '\0'
//! [6]
//! [7]
QByteArray().isEmpty(); // returns true
QByteArray("").isEmpty(); // returns true
QByteArray("abc").isEmpty(); // returns false
//! [7]
//! [8]
QByteArray ba("Hello world");
char *data = ba.data();
while (*data) {
cout << "[" << *data << "]" << endl;
++data;
}
//! [8]
//! [9]
QByteArray ba;
for (int i = 0; i < 10; ++i)
ba[i] = 'A' + i;
// ba == "ABCDEFGHIJ"
//! [9]
//! [10]
QByteArray ba("Stockholm");
ba.truncate(5); // ba == "Stock"
//! [10]
//! [11]
QByteArray ba("STARTTLS\r\n");
ba.chop(2); // ba == "STARTTLS"
//.........这里部分代码省略.........
示例5: parseVCards
VCard::List VCardParser::parseVCards( const QByteArray &text )
{
VCard currentVCard;
VCard::List vCardList;
QByteArray currentLine;
QList<QByteArray> lines = text.split( '\n' );
bool inVCard = false;
QList<QByteArray>::Iterator it( lines.begin() );
QList<QByteArray>::Iterator linesEnd( lines.end() );
for ( ; it != linesEnd; ++it ) {
// remove the trailing \r, left from \r\n
if ( ( *it ).endsWith( '\r' ) ) {
( *it ).chop( 1 );
}
if ( ( *it ).startsWith( ' ' ) ||
( *it ).startsWith( '\t' ) ) { //folded line => append to previous
currentLine.append( ( *it ).mid( 1 ) );
continue;
} else {
if ( ( *it ).trimmed().isEmpty() ) { // empty line
continue;
}
if ( inVCard && !currentLine.isEmpty() ) { // now parse the line
int colon = currentLine.indexOf( ':' );
if ( colon == -1 ) { // invalid line
currentLine = ( *it );
continue;
}
VCardLine vCardLine;
const QByteArray key = currentLine.left( colon ).trimmed();
QByteArray value = currentLine.mid( colon + 1 );
QList<QByteArray> params = key.split( ';' );
// check for group
int groupPos = params[ 0 ].indexOf( '.' );
if ( groupPos != -1 ) {
vCardLine.setGroup( QString::fromLatin1( params[ 0 ].left( groupPos ) ) );
vCardLine.setIdentifier( QString::fromLatin1( params[ 0 ].mid( groupPos + 1 ) ) );
} else {
vCardLine.setIdentifier( QString::fromLatin1( params[ 0 ] ) );
}
if ( params.count() > 1 ) { // find all parameters
QList<QByteArray>::ConstIterator paramIt( params.constBegin() );
for ( ++paramIt; paramIt != params.constEnd(); ++paramIt ) {
QList<QByteArray> pair = ( *paramIt ).split( '=' );
if ( pair.count() == 1 ) {
// correct the fucking 2.1 'standard'
if ( pair[ 0 ].toLower() == "quoted-printable" ) {
pair[ 0 ] = "encoding";
pair.append( "quoted-printable" );
} else if ( pair[ 0 ].toLower() == "base64" ) {
pair[ 0 ] = "encoding";
pair.append( "base64" );
} else {
pair.prepend( "type" );
}
}
if ( pair[ 1 ].indexOf( ',' ) != -1 ) { // parameter in type=x,y,z format
const QList<QByteArray> args = pair[ 1 ].split( ',' );
QList<QByteArray>::ConstIterator argIt;
QList<QByteArray>::ConstIterator argEnd( args.constEnd() );
for ( argIt = args.constBegin(); argIt != argEnd; ++argIt ) {
vCardLine.addParameter( QString::fromLatin1( pair[ 0 ].toLower() ),
QString::fromLatin1( *argIt ) );
}
} else {
vCardLine.addParameter( QString::fromLatin1( pair[ 0 ].toLower() ),
QString::fromLatin1( pair[ 1 ] ) );
}
}
}
removeEscapes( value );
QByteArray output;
bool wasBase64Encoded = false;
if ( vCardLine.parameterList().contains( QLatin1String( "encoding" ) ) ) {
const QString encoding = vCardLine.parameter( QLatin1String( "encoding" ) ).toLower();
// have to decode the data
if ( encoding == QLatin1String( "b" ) || encoding == QLatin1String( "base64" ) ) {
output = QByteArray::fromBase64( value );
wasBase64Encoded = true;
}
else if ( encoding == QLatin1String( "quoted-printable" ) ) {
// join any qp-folded lines
while ( value.endsWith( '=' ) && it != linesEnd ) {
value.chop( 1 ); // remove the '='
value.append( *it );
++it;
}
KCodecs::quotedPrintableDecode( value, output );
} else if ( encoding == QLatin1String( "8bit" ) ) {
//.........这里部分代码省略.........
示例6: canParseRequest
/*!
* \reimp
*/
bool QxtHttpServerConnector::canParseRequest(const QByteArray& buffer)
{
if (buffer.indexOf("\r\n\r\n") >= 0) return true; // 1.0+
if (buffer.indexOf("\r\n") >= 0 && buffer.indexOf("HTTP/") == -1) return true; // 0.9
return false;
}
示例7: parseHttpOptionHeader
// ### merge with nextField in cookiejar.cpp
static QHash<QByteArray, QByteArray> parseHttpOptionHeader(const QByteArray &header)
{
// The HTTP header is of the form:
// header = #1(directives)
// directives = token | value-directive
// value-directive = token "=" (token | quoted-string)
QHash<QByteArray, QByteArray> result;
int pos = 0;
while (true) {
// skip spaces
pos = nextNonWhitespace(header, pos);
if (pos == header.length())
return result; // end of parsing
// pos points to a non-whitespace
int comma = header.indexOf(',', pos);
int equal = header.indexOf('=', pos);
if (comma == pos || equal == pos)
// huh? Broken header.
return result;
// The key name is delimited by either a comma, an equal sign or the end
// of the header, whichever comes first
int end = comma;
if (end == -1)
end = header.length();
if (equal != -1 && end > equal)
end = equal; // equal sign comes before comma/end
QByteArray key = QByteArray(header.constData() + pos, end - pos).trimmed().toLower();
pos = end + 1;
if (equal != -1) {
// case: token "=" (token | quoted-string)
// skip spaces
pos = nextNonWhitespace(header, pos);
if (pos == header.length())
// huh? Broken header
return result;
QByteArray value;
value.reserve(header.length() - pos);
if (header.at(pos) == '"') {
// case: quoted-string
// quoted-string = ( <"> *(qdtext | quoted-pair ) <"> )
// qdtext = <any TEXT except <">>
// quoted-pair = "\" CHAR
++pos;
while (pos < header.length()) {
register char c = header.at(pos);
if (c == '"') {
// end of quoted text
break;
} else if (c == '\\') {
++pos;
if (pos >= header.length())
// broken header
return result;
c = header.at(pos);
}
value += c;
++pos;
}
} else {
// case: token
while (pos < header.length()) {
register char c = header.at(pos);
if (isSeparator(c))
break;
value += c;
++pos;
}
}
result.insert(key, value);
// find the comma now:
comma = header.indexOf(',', pos);
if (comma == -1)
return result; // end of parsing
pos = comma + 1;
} else {
// case: token
// key is already set
result.insert(key, QByteArray());
}
}
}
示例8: localDomainName
QString QHostInfo::localDomainName()
{
#if !defined(Q_OS_VXWORKS)
resolveLibrary();
if (local_res_ninit) {
// using thread-safe version
res_state_ptr state = res_state_ptr(qMalloc(sizeof(*state)));
Q_CHECK_PTR(state);
memset(state, 0, sizeof(*state));
local_res_ninit(state);
QString domainName = QUrl::fromAce(state->defdname);
if (domainName.isEmpty())
domainName = QUrl::fromAce(state->dnsrch[0]);
local_res_nclose(state);
qFree(state);
return domainName;
}
if (local_res_init && local_res) {
// using thread-unsafe version
#if defined(QT_NO_GETADDRINFO)
// We have to call res_init to be sure that _res was initialized
// So, for systems without getaddrinfo (which is thread-safe), we lock the mutex too
QMutexLocker locker(::getHostByNameMutex());
#endif
local_res_init();
QString domainName = QUrl::fromAce(local_res->defdname);
if (domainName.isEmpty())
domainName = QUrl::fromAce(local_res->dnsrch[0]);
return domainName;
}
#endif
// nothing worked, try doing it by ourselves:
QFile resolvconf;
#if defined(_PATH_RESCONF)
resolvconf.setFileName(QFile::decodeName(_PATH_RESCONF));
#else
resolvconf.setFileName(QLatin1String("/etc/resolv.conf"));
#endif
if (!resolvconf.open(QIODevice::ReadOnly))
return QString(); // failure
QString domainName;
while (!resolvconf.atEnd()) {
QByteArray line = resolvconf.readLine().trimmed();
if (line.startsWith("domain "))
return QUrl::fromAce(line.mid(sizeof "domain " - 1).trimmed());
// in case there's no "domain" line, fall back to the first "search" entry
if (domainName.isEmpty() && line.startsWith("search ")) {
QByteArray searchDomain = line.mid(sizeof "search " - 1).trimmed();
int pos = searchDomain.indexOf(' ');
if (pos != -1)
searchDomain.truncate(pos);
domainName = QUrl::fromAce(searchDomain);
}
}
// return the fallen-back-to searched domain
return domainName;
}
示例9: main
QT_USE_NAMESPACE
int main(int argc, char **argv)
{
if (FAILED(CoInitialize(0))) {
qErrnoWarning("CoInitialize() failed.");
return -1;
}
enum State {
Default = 0,
OutOption
} state;
state = Default;
QByteArray outname;
QByteArray object;
for (int a = 1; a < argc; ++a) {
QByteArray arg(argv[a]);
const char first = arg[0];
switch(state) {
case Default:
if (first == '-' || first == '/') {
arg = arg.mid(1).toLower();
if (arg == "o")
state = OutOption;
else if (arg == "v") {
qWarning("dumpdoc: Version 1.0");
return 0;
} else if (arg == "h") {
qWarning("dumpdoc Usage:\n\tdumpdoc object [-o <file>]"
" \n\tobject : object[/subobject]*"
" \n\tsubobject: property\n"
" \nexample:\n\tdumpdoc Outlook.Application/Session/CurrentUser -o outlook.html");
return 0;
}
} else {
object = arg;
}
break;
case OutOption:
outname = arg;
state = Default;
break;
default:
break;
}
}
if (object.isEmpty()) {
qWarning("dumpdoc: No object name provided.\n"
" Use -h for help.");
return -1;
}
QFile outfile;
if (!outname.isEmpty()) {
outfile.setFileName(QString::fromLatin1(outname.constData()));
if (!outfile.open(QIODevice::WriteOnly | QIODevice::Text)) {
qWarning("dumpdoc: Could not open output file '%s'", outname.data());
}
} else {
outfile.open(stdout, QIODevice::WriteOnly);
}
QTextStream out(&outfile);
QByteArray subobject = object;
int index = subobject.indexOf('/');
if (index != -1)
subobject.truncate(index);
QAxObject topobject(QString::fromLatin1(subobject.constData()));
if (topobject.isNull()) {
qWarning("dumpdoc: Could not instantiate COM object '%s'", subobject.data());
return -2;
}
QAxObject *axobject = &topobject;
while (index != -1 && axobject) {
index++;
subobject = object.mid(index);
if (object.indexOf('/', index) != -1) {
int oldindex = index;
index = object.indexOf('/', index);
subobject = object.mid(oldindex, index-oldindex);
} else {
index = -1;
}
axobject = axobject->querySubObject(subobject);
}
if (!axobject || axobject->isNull()) {
qWarning("dumpdoc: Subobject '%s' does not exist in '%s'", subobject.data(), object.data());
return -3;
}
QString docu = axobject->generateDocumentation();
out << docu;
//.........这里部分代码省略.........
示例10: onSocketReadyRead
void HttpProxy::onSocketReadyRead()
{
QTcpSocket *socket = qobject_cast<QTcpSocket *>(sender());
QTcpSocket *proxySocket = nullptr;
QByteArray reqData = socket->readAll();
int pos = reqData.indexOf("\r\n");
QByteArray reqLine = reqData.left(pos);
reqData.remove(0, pos + 2);
QList<QByteArray> entries = reqLine.split(' ');
QByteArray method = entries.value(0);
QByteArray address = entries.value(1);
QByteArray version = entries.value(2);
QString host;
quint16 port;
QString key;
if (method != "CONNECT") {
QUrl url = QUrl::fromEncoded(address);
if (!url.isValid()) {
emit error("Invalid URL: " + url.toString());
socket->disconnectFromHost();
return;
}
host = url.host();
port = url.port(80);
QString req = url.path();
if (url.hasQuery()) {
req.append('?').append(url.query());
}
reqLine = method + " " + req.toUtf8() + " " + version + "\r\n";
reqData.prepend(reqLine);
key = host + ':' + QString::number(port);
proxySocket = socket->findChild<QTcpSocket *>(key);
if (proxySocket) {
proxySocket->write(reqData);
return;//if we find an existing socket, then use it and return
}
} else {//CONNECT method
/*
* according to http://tools.ietf.org/html/draft-luotonen-ssl-tunneling-03
* the first line would CONNECT HOST:PORT VERSION
*/
QList<QByteArray> host_port_list = address.split(':');
host = QString(host_port_list.first());
port = host_port_list.last().toUShort();
}
proxySocket = new QTcpSocket(socket);
proxySocket->setProxy(upstreamProxy);
if (method != "CONNECT") {
proxySocket->setObjectName(key);
proxySocket->setProperty("reqData", reqData);
connect (proxySocket, &QTcpSocket::connected, this, &HttpProxy::onProxySocketConnected);
connect (proxySocket, &QTcpSocket::readyRead, this, &HttpProxy::onProxySocketReadyRead);
} else {
connect (proxySocket, &QTcpSocket::connected, this, &HttpProxy::onProxySocketConnectedHttps);
}
connect (proxySocket, &QTcpSocket::disconnected, proxySocket, &QTcpSocket::deleteLater);
connect (proxySocket, static_cast<void (QTcpSocket::*)(QAbstractSocket::SocketError)>(&QTcpSocket::error), this, &HttpProxy::onSocketError);
proxySocket->connectToHost(host, port);
}
示例11: fontmap
static QFontEngine::FaceId fontFile(const QByteArray &_xname, QFreetypeFace **freetype, int *synth)
{
*freetype = 0;
*synth = 0;
QByteArray xname = _xname.toLower();
int pos = 0;
int minus = 0;
while (minus < 5 && (pos = xname.indexOf('-', pos + 1)))
++minus;
QByteArray searchname = xname.left(pos);
while (minus < 12 && (pos = xname.indexOf('-', pos + 1)))
++minus;
QByteArray encoding = xname.mid(pos + 1);
//qDebug("xname='%s', searchname='%s', encoding='%s'", xname.data(), searchname.data(), encoding.data());
QStringList fontpath = fontPath();
QFontEngine::FaceId face_id;
face_id.index = 0;
QByteArray best_mapping;
for (QStringList::ConstIterator it = fontpath.constBegin(); it != fontpath.constEnd(); ++it) {
if (!(*it).startsWith(QLatin1Char('/')))
continue; // not a path name, a font server
QString fontmapname;
int num = 0;
// search font.dir and font.scale for the right file
while (num < 2) {
if (num == 0)
fontmapname = (*it) + QLatin1String("/fonts.scale");
else
fontmapname = (*it) + QLatin1String("/fonts.dir");
++num;
//qWarning(fontmapname);
QFile fontmap(fontmapname);
if (!fontmap.open(QIODevice::ReadOnly))
continue;
while (!fontmap.atEnd()) {
QByteArray mapping = fontmap.readLine();
QByteArray lmapping = mapping.toLower();
//qWarning(xfontname);
//qWarning(mapping);
if (!lmapping.contains(searchname))
continue;
int index = mapping.indexOf(' ');
QByteArray ffn = mapping.mid(0,index);
// remove bitmap formats freetype can't handle
if (ffn.contains(".spd") || ffn.contains(".phont"))
continue;
bool best_match = false;
if (!best_mapping.isEmpty()) {
if (lmapping.contains("-0-0-0-0-")) { // scalable font
best_match = true;
goto found;
}
if (lmapping.contains(encoding) && !best_mapping.toLower().contains(encoding))
goto found;
continue;
}
found:
int colon = ffn.lastIndexOf(':');
if (colon != -1) {
QByteArray s = ffn.left(colon);
ffn = ffn.mid(colon + 1);
if (s.contains("ds="))
*synth |= QFontEngine::SynthesizedBold;
if (s.contains("ai="))
*synth |= QFontEngine::SynthesizedItalic;
}
face_id.filename = (*it).toLocal8Bit() + '/' + ffn;
best_mapping = mapping;
if (best_match)
goto end;
}
}
}
end:
// qDebug("fontfile for %s is from '%s'\n got %s synth=%d", xname.data(),
// best_mapping.data(), face_id.filename.data(), *synth);
*freetype = QFreetypeFace::getFace(face_id);
if (!*freetype) {
face_id.index = 0;
face_id.filename = QByteArray();
}
return face_id;
}
示例12: getWordSizeOfOS
static int getWordSizeOfOS()
{
#if defined(Q_OS_WIN64)
return 64; // 64-bit process running on 64-bit windows
#elif defined(Q_OS_WIN32)
// determine if 32-bit process running on 64-bit windows in WOW64 emulation
// or 32-bit process running on 32-bit windows
// default bIsWow64 to false for 32-bit process on 32-bit windows
BOOL bIsWow64 = false; // must default to false
typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress(
GetModuleHandle("kernel32"), "IsWow64Process");
if (NULL != fnIsWow64Process) {
if (!fnIsWow64Process(GetCurrentProcess(), &bIsWow64)) {
assert(false); // something went majorly wrong
}
}
return bIsWow64 ? 64 : 32;
#elif defined (Q_OS_LINUX)
// http://stackoverflow.com/questions/246007/how-to-determine-whether-a-given-linux-is-32-bit-or-64-bit
QString exe(QLatin1String("getconf"));
QStringList args;
args << QLatin1String("LONG_BIT");
QProcess proc;
proc.setEnvironment(QProcess::systemEnvironment());
proc.start(exe, args);
if (proc.waitForStarted() && proc.waitForFinished()) {
QByteArray info = proc.readAll();
info.replace('\n',"");
return info.toInt();
}
return 0; // failed
#elif defined (Q_OS_UNIX) || defined (Q_OS_MAC)
QString exe(QLatin1String("uname"));
QStringList args;
args << QLatin1String("-m");
QProcess proc;
proc.setEnvironment(QProcess::systemEnvironment());
proc.start(exe, args);
if (proc.waitForStarted() && proc.waitForFinished()) {
QByteArray info = proc.readAll();
info.replace('\n',"");
if (info.indexOf("x86_64") >= 0)
return 64;
else if (info.indexOf("amd64") >= 0)
return 64;
else if (info.indexOf("ia64") >= 0)
return 64;
else if (info.indexOf("ppc64") >= 0)
return 64;
else if (info.indexOf("i386") >= 0)
return 32;
else if (info.indexOf("i686") >= 0)
return 32;
else if (info.indexOf("x86") >= 0)
return 32;
}
return 0; // failed
#else
return 0; // unknown
#endif
}
示例13: threadIdFromTcdfId
unsigned RunControlContext::threadIdFromTcdfId(const QByteArray &id)
{
const int tPos = id.indexOf(".t");
return tPos != -1 ? id.mid(tPos + 2).toUInt() : uint(0);
}
示例14: fileControl
void UmlPackage::fileControl(bool ci)
{
UmlPackage * prj = getProject();
QByteArray prjfile = prj->supportFile();
BooL rec;
BooL reload;
QByteArray cmd;
if (! prj->propertyValue((ci) ? "check-in-cmd" : "check-out-cmd", cmd))
cmd = "specify the command containing %file and %dir or %dironly";
Dialog dialog(ci, cmd, rec, reload); // the dialog execution set 'cmd' and 'rec'
if (dialog.exec() == QDialog::Accepted) {
// save the command for a future usage
prj->set_PropertyValue((ci) ? "check-in-cmd" : "check-out-cmd", cmd);
if (reload)
saveProject();
// get files list
QHash<QString,void*> files;
getFiles(files, (rec) ? ~0u : 1);
if (this == prj)
getAuxFiles(files);
// apply the command on each file
QHashIterator<QString,void*> it(files);
QFileInfo prjpath(prjfile);
QString dir = prjpath.path();
QString dironly = dir;
int index;
if ((dironly.length() > 3) &&
(dironly[1] == ':') &&
(dironly[2] == '/'))
dironly = dironly.mid(2);
while ((index = cmd.indexOf("%dironly")) != -1)
cmd.replace(index, 8, dironly.toLatin1());
while ((index = cmd.indexOf("%dir")) != -1)
cmd.replace(index, 4, dir.toLatin1());
while (it.hasNext()) {
it.next();
QString s = cmd;
while ((index = s.indexOf("%file")) != -1)
s.replace(index, 5, it.key().toLatin1());
system((const char *) s.toLatin1().constData());
//++it;
}
UmlCom::trace("Done.");
if (reload)
loadProject(prjfile);
}
}
示例15: main
int main(int argc, char *argv[])
{
QProcess* algepapcheck = new QProcess(NULL);
QByteArray* algepapcheckreturn = new QByteArray(NULL);
int *j = new int(0);
int *countofalgepapruned = new int(0);
algepapcheck->start("/bin/ps -e");
while(algepapcheck->waitForReadyRead()) {
algepapcheckreturn->append(algepapcheck->readAll());
}
while ((*j = algepapcheckreturn->indexOf("algepap", *j)) != -1) {
(*countofalgepapruned)++;
++(*j);
}
delete algepapcheck;
delete algepapcheckreturn;
delete j;
//Q_INIT_RESOURCE(algepap);
QApplication a(argc, argv);
if(*countofalgepapruned > 1) {
QMessageBox::information(0, QObject::tr("AlgePap"),
QObject::tr("Algepap is already runing ..... "));
return 0;
}
delete countofalgepapruned;
//checking user data status
QDir* DATADIR = new QDir(QDir::home().path()+"/.algepap");
if(!DATADIR->exists())
{
DATADIR->mkdir(DATADIR->path());
if(!DATADIR->exists("/usr/share/algepap/DATA"))
return 0;
system(QString("cp -r /usr/share/algepap/DATA "+DATADIR->path()).toAscii().data());
DATADIR->mkdir(DATADIR->path()+"/TMP");
}
QString* browse = new QString(DATADIR->path()+"/DATA/bin/browse");
QString* downloadnews = new QString(DATADIR->path()+"/DATA/bin/downloadnewspapers");
QString* desktop = new QString(DATADIR->path()+"/DATA/bin/desktop");
chmod(browse->toLatin1().constData(),0755);
chmod(downloadnews->toLatin1().constData(),0755);
chmod(desktop->toLatin1().constData(),0755);
delete browse;
delete downloadnews;
delete desktop;
delete DATADIR;
a.setApplicationVersion("1.0");
a.setApplicationName("algepap");
if (!QSystemTrayIcon::isSystemTrayAvailable()) {
QMessageBox::critical(0, QObject::tr("AlgePap"),
QObject::tr("AlgePap couldn't detect any system tray "
"on this system."));
return 1;
}
QApplication::setQuitOnLastWindowClosed(false);
AlgePapMain *w = new AlgePapMain(NULL,QDir::home().path()+"/.algepap");
w->show();
return a.exec();
}