本文整理汇总了C++中QByteArray::toLong方法的典型用法代码示例。如果您正苦于以下问题:C++ QByteArray::toLong方法的具体用法?C++ QByteArray::toLong怎么用?C++ QByteArray::toLong使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QByteArray
的用法示例。
在下文中一共展示了QByteArray::toLong方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readyRead
void Connection::readyRead()
{
while (m_socket && m_socket->bytesAvailable()) {
long length;
{
QByteArray data;
char c;
while(m_socket->getChar(&c)) {
if(c==0) break;
data.append(c);
}
length = data.toLong();
}
QByteArray data;
while (data.length() <= length) {
if (!data.isEmpty() && !m_socket->waitForReadyRead()) {
return;
}
data += m_socket->read(length - data.length() + 1);
}
//kDebug() << data;
QDomDocument doc;
doc.setContent(data);
if (doc.documentElement().tagName() == "init") {
processInit(doc);
} else if (doc.documentElement().tagName() == "response") {
processResponse(doc);
} else if (doc.documentElement().tagName() == "stream") {
processStream(doc);
} else {
//kWarning() << "unknown element" << xml->name();
}
}
}
示例2: onDataPosted
void tstMainWindow::onDataPosted(const QByteArray& data)
{
qDebug() << DTK_PRETTY_FUNCTION << "data posted";
bool ok = false;
long result = data.toLong(&ok);
if (ok)
QMessageBox::information(this,"dtkDistributedTutorial6 ",QString("result is: %1").arg(result));
else
qDebug() << "can't convert result to long";
}
示例3: QVariant
bool
Field::setDefaultValue(const QByteArray& def)
{
if (def.isNull()) {
m_defaultValue = QVariant();
return true;
}
bool ok;
switch (type()) {
case Byte: {
unsigned int v = def.toUInt(&ok);
if (!ok || v > 255)
m_defaultValue = QVariant();
else
m_defaultValue = QVariant(v);
break;
}
case ShortInteger: {
int v = def.toInt(&ok);
if (!ok || (!(m_options & Unsigned) && (v < -32768 || v > 32767)) || ((m_options & Unsigned) && (v < 0 || v > 65535)))
m_defaultValue = QVariant();
else
m_defaultValue = QVariant(v);
break;
}
case Integer: {//4 bytes
long v = def.toLong(&ok);
//js: FIXME if (!ok || (!(m_options & Unsigned) && (-v > 0x080000000 || v > (0x080000000-1))) || ((m_options & Unsigned) && (v < 0 || v > 0x100000000)))
if (!ok || (!(m_options & Unsigned) && (-v > (int)0x07FFFFFFF || v > (int)(0x080000000 - 1))))
m_defaultValue = QVariant();
else
m_defaultValue = QVariant((qint64)v);
break;
}
case BigInteger: {//8 bytes
//! @todo BigInteger support
/*
qint64 long v = def.toLongLong(&ok);
//TODO: 2-part decoding
if (!ok || (!(m_options & Unsigned) && (-v > 0x080000000 || v > (0x080000000-1))))
m_defaultValue = QVariant();
else
if (m_options & Unsigned)
m_defaultValue=QVariant((quint64) v);
else
m_defaultValue = QVariant((qint64)v);*/
break;
}
case Boolean: {
unsigned short v = def.toUShort(&ok);
if (!ok || v > 1)
m_defaultValue = QVariant();
else
m_defaultValue = QVariant((bool)v);
break;
}
case Date: {//YYYY-MM-DD
QDate date = QDate::fromString(def, Qt::ISODate);
if (!date.isValid())
m_defaultValue = QVariant();
else
m_defaultValue = QVariant(date);
break;
}
case DateTime: {//YYYY-MM-DDTHH:MM:SS
QDateTime dt = QDateTime::fromString(def, Qt::ISODate);
if (!dt.isValid())
m_defaultValue = QVariant();
else
m_defaultValue = QVariant(dt);
break;
}
case Time: {//HH:MM:SS
QTime time = QTime::fromString(def, Qt::ISODate);
if (!time.isValid())
m_defaultValue = QVariant();
else
m_defaultValue = QVariant(time);
break;
}
case Float: {
float v = def.toFloat(&ok);
if (!ok || ((m_options & Unsigned) && (v < 0.0)))
m_defaultValue = QVariant();
else
m_defaultValue = QVariant(v);
break;
}
case Double: {
double v = def.toDouble(&ok);
if (!ok || ((m_options & Unsigned) && (v < 0.0)))
m_defaultValue = QVariant();
else
m_defaultValue = QVariant(v);
break;
}
case Text: {
if (def.isNull() || (uint(def.length()) > maxLength()))
m_defaultValue = QVariant();
//.........这里部分代码省略.........