本文整理汇总了C++中QByteArray::toDouble方法的典型用法代码示例。如果您正苦于以下问题:C++ QByteArray::toDouble方法的具体用法?C++ QByteArray::toDouble怎么用?C++ QByteArray::toDouble使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QByteArray
的用法示例。
在下文中一共展示了QByteArray::toDouble方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: read_from
/* ========================================================================== */
QVariant LispPlugin::read_from(QVariantList& tokenz) {
if (tokenz.isEmpty())
throw runtime_error("unexpected EOF while reading");
QByteArray token = tokenz.takeFirst().toByteArray();
if (token == "(") {
//auto L = QVariant(QVariant::List);
QVariantList L;
while (tokenz[0] != ")")
L.append(read_from(tokenz));
tokenz.takeFirst(); // pop off )
return L;
} else if (token == ")") {
throw std::runtime_error("enexcepted )");
} else {
bool successCast;
auto i = token.toInt(&successCast);
if (successCast) return i;
auto d = token.toDouble(&successCast);
if (successCast) return d;
return QString(token);
}
}
示例2: readOther
QVariant StelJsonParserInstance::readOther()
{
QByteArray str;
char c;
while (getChar(&c))
{
if (c==' ' || c==',' || c=='\n' || c=='\r' || c==']' || c=='\t' || c=='}')
{
ungetChar(c);
break;
}
str+=c;
}
bool ok;
const int i = str.toInt(&ok);
if (ok)
return i;
const double d = str.toDouble(&ok);
if (ok)
return d;
if (str=="true")
return QVariant(true);
if (str=="false")
return QVariant(false);
if (str=="null")
return QVariant();
QDateTime dt = QDateTime::fromString(str, Qt::ISODate);
if (dt.isValid())
return QVariant(dt);
throw std::runtime_error(qPrintable(QString("Invalid JSON value: \"")+str+"\""));
}
示例3: getDouble
static double getDouble( const QByteArray& numStr ) {
bool ok = false;
double ret = numStr.toDouble( &ok );
if( ok ) {
return ret;
}
throw QString( GTest_UHMM3SearchCompare::tr( "Internal error (cannot parse float number from string '%1')" ).arg( QString( numStr ) ) );
}
示例4: qwhereaboutsupdate_getUpdateCoordinate
static void qwhereaboutsupdate_getUpdateCoordinate(QWhereaboutsCoordinate *coord, const QByteArray &latStr, const QByteArray &latHmsph, const QByteArray &lngStr, const QByteArray &lngHmsph, const QByteArray &altStr = QByteArray())
{
bool hasLat = false;
bool hasLong = false;
double lat = qwhereaboutsupdate_nmeaDegreesToDecimal(latStr.toDouble(&hasLat));
double lng = qwhereaboutsupdate_nmeaDegreesToDecimal(lngStr.toDouble(&hasLong));
if (hasLat && hasLong) {
if (latHmsph == "S")
lat *= -1;
if (lngHmsph == "W")
lng *= -1;
bool hasAlt = false;
double altitude = altStr.toDouble(&hasAlt);
if (hasAlt)
*coord = QWhereaboutsCoordinate(lat, lng, altitude);
else
*coord = QWhereaboutsCoordinate(lat, lng);
}
}
示例5: parse_time
static bool parse_time(const QByteArray &ba, int &secs, int &msecs)
{
bool ok;
if(ba.indexOf('.') > 0) {
double d = ba.toDouble(&ok);
secs = (int)d;
msecs = static_cast<int>(d * 1000) % 1000;
}
else {
secs = ba.toInt(&ok);
if(secs < 0)
secs = siut::SICard::INVALID_SI_TIME;
msecs = 0;
}
return ok;
}
示例6: tr
double donationDialog::EUR2BTC()
{
QNetworkReply *rep = ((MainWindow*)parent())->mgr->get(QNetworkRequest(QUrl("https://blockchain.info/de/tobtc?currency=EUR&value=1")));
QByteArray raw;
rep->ignoreSslErrors();
lineEdit_payment2->setText(tr("getting current exchange rate..."));
comboBox->setEnabled(false);
horizontalSlider->setEnabled(false);
pushButton->setEnabled(false);
((MainWindow*)parent())->timeout.start();
while(rep->isRunning())
{
QCoreApplication::processEvents();
if(((MainWindow*)parent())->timeout.hasExpired(3000))
{
rep->abort();
}
}
comboBox->setEnabled(true);
horizontalSlider->setEnabled(true);
pushButton->setEnabled(true);
if(rep->error())
{
QMessageBox::warning(this, APPNAME, tr("Current exchange rate could not be determined!\n\nPlease specify the desired amount manually..."));
return 0.0;
}
raw = rep->readAll();
rep->deleteLater();
return raw.toDouble();
}
示例7: if
static QList<qreal> parseNumbersList(QByteArray::const_iterator &itr)
{
QList<qreal> points;
QByteArray temp;
while ((*itr) == ' ')
++itr;
while (((*itr) >= '0' && (*itr) <= '9') ||
(*itr) == '-' || (*itr) == '+') {
temp = QByteArray();
if ((*itr) == '-')
temp += *itr++;
else if ((*itr) == '+')
temp += *itr++;
while ((*itr) >= '0' && (*itr) <= '9')
temp += *itr++;
if ((*itr) == '.')
temp += *itr++;
while ((*itr) >= '0' && (*itr) <= '9')
temp += *itr++;
if (( *itr) == 'e') {
temp += *itr++;
if ((*itr) == '-' ||
(*itr) == '+')
temp += *itr++;
}
while ((*itr) >= '0' && (*itr) <= '9')
temp += *itr++;
while ((*itr) == ' ')
++itr;
if ((*itr) == ',')
++itr;
points.append(temp.toDouble());
//eat the rest of space
while ((*itr) == ' ')
++itr;
}
return points;
}
示例8: MGH_LM_Parse_Para
void BabyMEGInfo::MGH_LM_Parse_Para(QByteArray cmdstr)
{
QByteArray CMD = cmdstr.left(4);
if (CMD == "INFO")
{
//remove INFO
cmdstr.remove(0,4);
//ACQ the number of channels
QByteArray T = MGH_LM_Get_Field(cmdstr);
cmdstr.remove(0,T.size());
T.remove(0,1);
chnNum = T.toInt();
//ACQ the length of data package
T = MGH_LM_Get_Field(cmdstr);
cmdstr.remove(0,T.size());
T.remove(0,1);
dataLength = T.toInt();
// ACQ sampling rate
T = MGH_LM_Get_Field(cmdstr);
cmdstr.remove(0,T.size());
T.remove(0,1);
sfreq = T.toDouble();
qDebug()<<"[babyMEGinfo] chnNum:" << chnNum << "Data Length" <<dataLength<<"sampling rate"<<sfreq;
//qDebug()<<"cmdstr"<<cmdstr;
// Start to acquire the channel's name and channel's scale
MGH_LM_Get_Channel_Info(cmdstr);
}
else
{
chnNum = 464;
dataLength = 5000;
sfreq = 10000;
}
// Parameters
m_FiffInfo.file_id.version = 0; //ToDo
m_FiffInfo.meas_date[0] = 0;
m_FiffInfo.meas_date[1] = 0;
m_FiffInfo.sfreq = sfreq;
m_FiffInfo.highpass = 0;
m_FiffInfo.lowpass = m_FiffInfo.sfreq/2;
m_FiffInfo.acq_pars = QString("BabyMEG");
m_FiffInfo.acq_stim = QString("");
m_FiffInfo.filename = QString("");
m_FiffInfo.meas_id.version = 1;
m_FiffInfo.nchan = chnNum; //464;
//MEG
for(qint32 i = 0; i < chnNum; i++)
{
FiffChInfo t_ch;
t_ch.ch_name = lm_ch_names.at(i); //QString("MEG%1").arg(i);
//qDebug()<<t_ch.ch_name;
t_ch.scanno = i;
t_ch.logno = i+1;
t_ch.cal = 1;
t_ch.range = 1;
t_ch.loc.setZero(12,1);
QString type = t_ch.ch_name.left(3);
int ntype = 0;
if (type == "MEG")
ntype = 1;
else if (type == "EEG")
ntype = 2;
switch (ntype)
{
case 1:
t_ch.kind = FIFFV_MEG_CH;
t_ch.unit = FIFF_UNIT_T;
t_ch.unit_mul = FIFF_UNITM_NONE;
t_ch.coil_type = FIFFV_COIL_BABY_MAG;// ToDo FIFFV_COIL_BABY_REF_MAG
break;
case 2:
t_ch.kind = FIFFV_EEG_CH;
t_ch.unit = FIFF_UNIT_V;
t_ch.unit_mul = FIFF_UNITM_NONE;
t_ch.coil_type = FIFFV_COIL_EEG;
break;
default:
t_ch.kind = FIFFV_MEG_CH;
t_ch.unit = FIFF_UNIT_T;
t_ch.unit_mul = FIFF_UNITM_NONE;
t_ch.coil_type = FIFFV_COIL_BABY_MAG;// ToDo FIFFV_COIL_BABY_REF_MAG
break;
}
m_FiffInfo.chs.append(t_ch);
m_FiffInfo.ch_names.append(t_ch.ch_name);
}
emit fiffInfoAvailable(m_FiffInfo);
return;
}
示例9: fetchNumber
bool Lexer::fetchNumber( double &d)
{
char ch;
d_source.peek( &ch, 1 );
QByteArray number;
enum State { Vorkomma, Nachkomma, Exponent2, Exponent1 };
State state = Vorkomma;
// Erstes Zeichen
if( ch == '.' )
{
state = Nachkomma;
}else if( !::isdigit( ch ) )
{
d_source.rewind();
return false;
}
char ch2;
d_source.peek( &ch2, 1 );
if( state == Nachkomma && !::isdigit(ch2) )
{
d_source.rewind();
return false; // wir haben einen Punkt gefunden, der aber nicht von einer Zahl gefolgt wird
}
bool ok;
if( ch2 == 'x' )
{
if( ch != '0')
return error("invalid number format");
// Parse Hex
while( true )
{
d_source.peek( &ch2, 1 );
if( ::isdigit( ch2 ) || _isHexChar( ch2 ) )
number += ch2;
else
{
// Zahl ist fertig
d = number.toUInt( &ok, 16 );
if( !ok )
return error("invalid hex format");
else
{
d_source.eat( number.size() + 2 );
return true;
}
}
}
}else
{
// Parse Decimal
number += ch;
int anzNachkomma = 0;
while( true )
{
switch( state )
{
case Vorkomma:
if( ch2 == '.' )
{
state = Nachkomma;
}else if( ::isdigit( ch2 ) )
;
else if( ch2 == 'e' || ch2 == 'E' )
{
state = Exponent1;
ch2 = 'e';
}else
{
d = number.toUInt( &ok );
if( !ok )
return error("invalid integer");
else
{
d_source.eat( number.size() );
return true;
}
}
number += ch2;
break;
case Nachkomma:
if( ::isdigit( ch2 ) )
;
else if( ch2 == 'e' || ch2 == 'E' )
{
if( anzNachkomma == 0 )
return error("invalid number format");
state = Exponent1;
ch2 = 'e';
}else
{
// Zahl ist fertig
if( anzNachkomma == 0 )
return error("invalid number format");
d = number.toDouble( &ok );
if( !ok )
return error("invalid decimal format");
else
//.........这里部分代码省略.........
示例10: record
QDbfRecord QDbfTablePrivate::record() const
{
if (m_bufered) {
return m_currentRecord;
}
m_currentRecord = m_record;
m_bufered = true;
if (m_currentIndex < QDbfTablePrivate::FirstRow) {
return m_currentRecord;
}
if (!isOpen()) {
qWarning("QDbfTablePrivate::record(): IODevice is not open");
return m_currentRecord;
}
if (!m_file.isReadable()) {
m_error = QDbfTable::ReadError;
return m_currentRecord;
}
const qint64 position = m_headerLength + m_recordLength * m_currentIndex;
if (!m_file.seek(position)) {
m_error = QDbfTable::ReadError;
return m_currentRecord;
}
m_currentRecord.setRecordIndex(m_currentIndex);
const QByteArray recordData = m_file.read(m_recordLength);
if (recordData.count() == 0) {
m_error = QDbfTable::UnspecifiedError;
return m_currentRecord;
}
m_currentRecord.setDeleted(recordData.at(0) == '*' ? true : false);
for (int i = 0; i < m_currentRecord.count(); ++i) {
const QByteArray byteArray = recordData.mid(m_currentRecord.field(i).offset(),
m_currentRecord.field(i).length());
QVariant value;
switch (m_currentRecord.field(i).type()) {
case QVariant::String:
value = m_textCodec->toUnicode(byteArray);
break;
case QVariant::Date:
value = QVariant(QDate(byteArray.mid(0, 4).toInt(),
byteArray.mid(4, 2).toInt(),
byteArray.mid(6, 2).toInt()));
break;
case QVariant::Double:
value = byteArray.toDouble();
break;
case QVariant::Bool: {
QString val = QString::fromLatin1(byteArray.toUpper());
if (val == QLatin1String("T") ||
val == QLatin1String("Y")) {
value = true;
} else {
value = false;
}
break; }
default:
value = QVariant::Invalid;
}
m_currentRecord.setValue(i, value);
}
m_error = QDbfTable::NoError;
return m_currentRecord;
}
示例11: receivedMsg
void thermocouplePort::receivedMsg( QByteArray msg )
{
if( msg.isNull() )
{
return;
}
msg.replace( 0x0A, "" ).replace( 0x0B, "" ).replace( 0x0D, "" )
.replace( 0x11, "" ).replace( 0x13, "" )
.replace( 0x3C, "" ).replace( 0x3E, "" ); // < and > - dont know why this is sent ...
if( msg.isEmpty() )
{
return;
}
if( _expectedAnswer.size() == 0 )
{
if( _sendCounter != 0 )
{
return;
}
emit portError( "Unexpected answer!" );
return;
}
_answerPending = 0;
if( _expectedAnswer[0] == CMD_ID )
{
if( _idStringSet )
{
bool conversionSuccessful = false;
int version = msg.toInt( &conversionSuccessful );
if( conversionSuccessful && version > 90615 )
{
_probeTemperatureOnly = false;
}
_initValueCounter++;
emit initSuccessful( _idString );
}
else
{
_idStringSet = true;
_idString = msg;
_initValueCounter++;
}
}
else if( _expectedAnswer[0] == CMD_PROBE_TEMPERATURE )
{
bool conversionSuccessful = false;
double probeTemperatureCelsius = msg.toDouble( &conversionSuccessful );
if( conversionSuccessful )
{
if( _emitProbeTemperature )
{
if( probeTemperatureCelsius > MAX_TEMPERATURE
|| probeTemperatureCelsius < -MAX_TEMPERATURE )
{
emit portError( "Out of range!" );
}
else
{
emit newProbeTemperature( probeTemperatureCelsius );
}
}
}
else
{
emit portError( "Could not get temperature from answer!" );
}
}
else if( _expectedAnswer[0] == CMD_BOTH_TEMPERATURES )
{
bool conversion1Successful = false;
bool conversion2Successful = false;
double probeTemperatureFahrenheit = msg.left( msg.indexOf( "," ) )
.toDouble( &conversion1Successful );
double ambientTemperatureFahrenheit = msg.mid( msg.indexOf( "," ) + 1 )
.toDouble( &conversion2Successful );
if( conversion1Successful && conversion2Successful )
{
int tProbeCelsius = fahrenheitToCelsius(
probeTemperatureFahrenheit );
int tAmbientCelsius = fahrenheitToCelsius(
ambientTemperatureFahrenheit );
if( _emitProbeTemperature )
{
if( tProbeCelsius > MAX_TEMPERATURE
|| tProbeCelsius < -MAX_TEMPERATURE )
{
emit portError( "Out of range!" );
}
else
{
emit newProbeTemperature( tProbeCelsius );
}
}
if( _emitAmbientTemperature )
//.........这里部分代码省略.........
示例12: 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();
//.........这里部分代码省略.........
示例13: _parse
//.........这里部分代码省略.........
case '{':
{
if(!varDat.isEmpty()) {
device->seek(device->pos()-1);
breakLoop = true;
break;
}
QVariantMap map;
try {
while(true) {
try {
QString key = _parse(device, false).toString();
QVariant val;
try {
val = _parse(device, false);
} catch(QByteArray error) {
val = error;
} catch(const char* error) {
map.insert(key, QByteArray("Unexpected ") + error);
throw error;
} catch(...) {
val = QByteArray("Error");
}
map.insert(key, val);
} catch(QByteArray) {}
}
} catch(const char* error) {}
return map;
}
break;
case '}':
case ']':
if(!varDat.isEmpty()) {
device->seek(device->pos()-1);
breakLoop = true;
break;
}
throw "End of Loop";
case ',':
case '=':
case ':':
case '(':
case ')':
if(!varDat.isEmpty())
breakLoop = true;
break;
case '"':
case '\'':
{
quoted = true;
char nDat;
while(device->read(&nDat, 1)) {
if(nDat == c)
break;
if(nDat == '\\') { //TODO: Better Escape Parsing
if(device->read(&nDat, 1))
varDat.append(nDat);
continue;
} else
varDat.append(nDat);
}
breakLoop = true;
}
break;
default:
varDat.append(dat);
break;
}
if(breakLoop)
break;
}
if(varDat.isEmpty())
return QVariant();
bool ok;
double number = varDat.toDouble(&ok);
if(ok)
return QVariant(number);
if(validString.exactMatch(varDat)) {
if(!quoted) {
if(varDat == "true")
return QVariant(true);
else if(varDat == "false")
return QVariant(false);
}
return QVariant(QString(varDat));
}
return QVariant(varDat);
}