本文整理汇总了C++中QStringRef::toInt方法的典型用法代码示例。如果您正苦于以下问题:C++ QStringRef::toInt方法的具体用法?C++ QStringRef::toInt怎么用?C++ QStringRef::toInt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QStringRef
的用法示例。
在下文中一共展示了QStringRef::toInt方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: get_value_with_default
size_t get_value_with_default (const QStringRef &val, size_t def)
{
QString s = val.toString();
if (! s.isEmpty())
return (size_t) val.toInt();
else
return def;
}
示例2: searchFreeNumber
QString MainWindow::searchFreeNumber(QList<QString> sl, QString word)
{
int number = 0;
QStringList::iterator elem = sl.begin();
while (elem != sl.end()) {
QStringRef l = elem->leftRef(word.size());
if (l == word) {
QStringRef r = elem->rightRef(elem->size() - word.size());
number = r.toInt();
}
elem++;
}
return QString::number(number + 1);
}
示例3: parseBuildTargetOption
void CMakeCbpParser::parseBuildTargetOption()
{
if (attributes().hasAttribute(QLatin1String("output"))) {
m_buildTarget.executable = attributes().value(QLatin1String("output")).toString();
CMakeTool *tool = CMakeKitInformation::cmakeTool(m_kit);
if (tool)
m_buildTarget.executable = tool->mapAllPaths(m_kit, m_buildTarget.executable);
} else if (attributes().hasAttribute(QLatin1String("type"))) {
const QStringRef value = attributes().value(QLatin1String("type"));
if (value == QLatin1String("2") || value == QLatin1String("3"))
m_buildTarget.targetType = TargetType(value.toInt());
} else if (attributes().hasAttribute(QLatin1String("working_dir"))) {
m_buildTarget.workingDirectory = attributes().value(QLatin1String("working_dir")).toString();
QFile cmakeSourceInfoFile(m_buildTarget.workingDirectory
+ QStringLiteral("/CMakeFiles/CMakeDirectoryInformation.cmake"));
if (cmakeSourceInfoFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
QTextStream stream(&cmakeSourceInfoFile);
const QLatin1String searchSource("SET(CMAKE_RELATIVE_PATH_TOP_SOURCE \"");
while (!stream.atEnd()) {
const QString lineTopSource = stream.readLine().trimmed();
if (lineTopSource.startsWith(searchSource)) {
m_buildTarget.sourceDirectory = lineTopSource.mid(searchSource.size());
m_buildTarget.sourceDirectory.chop(2); // cut off ")
break;
}
}
}
if (m_buildTarget.sourceDirectory.isEmpty()) {
QDir dir(m_buildDirectory);
const QString relative = dir.relativeFilePath(m_buildTarget.workingDirectory);
m_buildTarget.sourceDirectory
= FileName::fromString(m_sourceDirectory).appendPath(relative).toString();
}
}
while (!atEnd()) {
readNext();
if (isEndElement())
return;
else if (isStartElement())
parseUnknownElement();
}
}
示例4: parseIntOption
bool parseIntOption(const QString ¶meter,const QLatin1String &option,
IntType minimumValue, IntType maximumValue, IntType *target)
{
const int valueLength = parameter.size() - option.size() - 1;
if (valueLength < 1 || !parameter.startsWith(option) || parameter.at(option.size()) != QLatin1Char('='))
return false;
bool ok;
const QStringRef valueRef = parameter.rightRef(valueLength);
const int value = valueRef.toInt(&ok);
if (ok) {
if (value >= minimumValue && value <= maximumValue)
*target = static_cast<IntType>(value);
else {
qWarning() << "Value" << value << "for option" << option << "out of range"
<< minimumValue << ".." << maximumValue;
}
} else {
qWarning() << "Invalid value" << valueRef << "for option" << option;
}
return true;
}
示例5: setAttr
void Inst_Cond::setAttr(QString NomAttr, QStringRef Valeur)
{
if(NomAttr == "nIdSuivant")
{
unsigned int nValeur (Valeur.toInt()) ;
if( this->nIdSuivant[0] == 0)
{
this->nIdSuivant[0] = nValeur ;
}
}
if(NomAttr == "TCondition")
{
int nValeur (Valeur.toInt()) ;
TypeCondition tValeur (static_cast<TypeCondition>(nValeur));
this->TCondition = tValeur;
}
if(NomAttr == "nIndiceVar")
{
unsigned int nValeur (Valeur.toInt()) ;
this->nIndiceVar = nValeur ;
}
if(NomAttr == "TypeComp")
{
int nValeur (Valeur.toInt()) ;
TypeComparaison tValeur (static_cast<TypeComparaison>(nValeur));
this->TypeComp = tValeur ;
}
if(NomAttr == "nValeur")
{
unsigned short nValeur (Valeur.toUShort()) ;
this->nValeur = nValeur ;
}
if(NomAttr == "TestMat")
{
TestArduino NouveauTest;
NouveauTest.sNomTest = "";
NouveauTest.sCommande = "";
NouveauTest.bActive = false ;
this->TestMat = NouveauTest;
}
if(NomAttr == "sNomTest")
{
QString sValeur (Valeur.toString());
this->TestMat.sNomTest = sValeur ;
}
if(NomAttr == "sCommande")
{
QString sValeur (Valeur.toString());
this->TestMat.sCommande = sValeur ;
}
if(NomAttr == "bActive")
{
QString sValeur (Valeur.toString());
bool bValeur (false);
if(sValeur == "true")
{
bValeur = true;
}
this->TestMat.bActive = bValeur ;
}
Instruction::setAttr(NomAttr, Valeur);
}
示例6: loadMOJ
bool Document::loadMOJ(QString fileName)
{
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly))
{
return false;
}
QXmlStreamReader reader;
// check if it is a gzipped moj
QByteArray s = file.read(2);
if (s.size() == 2)
{
if (s.at(0) == static_cast<char>(0x1f) && s.at(1) == static_cast<char>(0x8b))
{
// this is a gzipped file
file.reset();
QByteArray compressedData = file.readAll();
QByteArray uncompressedData;
if (!QCompressor::gzipDecompress(compressedData, uncompressedData))
{
return false;
}
reader.addData(uncompressedData);
}
else
{
file.reset();
reader.setDevice(&file);
}
}
else
{
return false;
}
pages.clear();
int strokeCount = 0;
while (!reader.atEnd())
{
reader.readNext();
if (reader.name() == "MrWriter" && reader.tokenType() == QXmlStreamReader::StartElement)
{
QXmlStreamAttributes attributes = reader.attributes();
QStringRef docversion = attributes.value("document-version");
if (docversion.toInt() > DOC_VERSION)
{
// TODO warn about newer document version
}
}
if (reader.name() == "page" && reader.tokenType() == QXmlStreamReader::StartElement)
{
QXmlStreamAttributes attributes = reader.attributes();
QStringRef width = attributes.value("", "width");
QStringRef height = attributes.value("", "height");
Page newPage;
newPage.setWidth(width.toDouble());
newPage.setHeight(height.toDouble());
pages.append(newPage);
}
if (reader.name() == "background" && reader.tokenType() == QXmlStreamReader::StartElement)
{
QXmlStreamAttributes attributes = reader.attributes();
QStringRef color = attributes.value("", "color");
QColor newColor = stringToColor(color.toString());
pages.last().setBackgroundColor(newColor);
}
if (reader.name() == "stroke" && reader.tokenType() == QXmlStreamReader::StartElement)
{
QXmlStreamAttributes attributes = reader.attributes();
QStringRef tool = attributes.value("", "tool");
if (tool == "pen")
{
Stroke newStroke;
newStroke.pattern = MrDoc::solidLinePattern;
QStringRef color = attributes.value("", "color");
newStroke.color = stringToColor(color.toString());
QStringRef style = attributes.value("", "style");
if (style.toString().compare("solid") == 0)
{
newStroke.pattern = MrDoc::solidLinePattern;
}
else if (style.toString().compare("dash") == 0)
{
newStroke.pattern = MrDoc::dashLinePattern;
}
else if (style.toString().compare("dashdot") == 0)
{
newStroke.pattern = MrDoc::dashDotLinePattern;
}
else if (style.toString().compare("dot") == 0)
{
newStroke.pattern = MrDoc::dotLinePattern;
}
else
{
//.........这里部分代码省略.........
示例7: file
std::tuple<bool, const char*> loadStressedSyllableDictionaryXml(boost::wstring_ref dictFilePath, std::unordered_map<std::wstring, int>& wordToStressedSyllableInd)
{
QFile file(QString::fromWCharArray(dictFilePath.begin(), dictFilePath.size()));
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return std::make_tuple(false, "Can't open file");
QXmlStreamReader xmlReader(&file);
std::wstring wordName;
while (!xmlReader.atEnd())
{
xmlReader.readNext();
if (xmlReader.isStartElement() && xmlReader.name() == SressDictWordTag)
{
wordName.clear();
int wordStressedSyllableInd = -1;
const QXmlStreamAttributes& attrs = xmlReader.attributes();
if (attrs.hasAttribute(SressDictWordName))
{
QStringRef nameStr = attrs.value(SressDictWordName);
QString nameQ = QString::fromRawData(nameStr.constData(), nameStr.size());
wordName = nameQ.toStdWString();
}
if (attrs.hasAttribute(SressDictWordSyllable))
{
QStringRef stressStr = attrs.value(SressDictWordSyllable);
int sepInd = stressStr.indexOf(' ');
if (sepInd != -1)
stressStr = stressStr.left(sepInd);
bool convOp = false;
wordStressedSyllableInd = stressStr.toInt(&convOp);
if (!convOp)
return std::make_tuple(false, "Can't parse stressed syllable definition");
wordStressedSyllableInd -= 1; // dict has 1-based index
}
if (wordName.empty() || wordStressedSyllableInd == -1)
return std::make_tuple(false, "The word stress definition is incomplete");
auto checkSyllableInd = [](const std::wstring& word, int syllabInd)
{
if (syllabInd < 0)
return false;
int vowelsCount = vowelsCountUk(word);
if (syllabInd >= vowelsCount)
return false;
return true;
};
if (!checkSyllableInd(wordName, wordStressedSyllableInd))
std::make_tuple(false, "Syllable index is out of range");
wordToStressedSyllableInd[wordName] = wordStressedSyllableInd;
}
}
if (xmlReader.hasError())
return std::make_tuple(false, "Error reading XML stressed syllables definitions");
return std::make_tuple(true, nullptr);
}
示例8: parse
bool MmRendererMetaData::parse(const QString &contextName)
{
clear();
QString fileName =
QString("/pps/services/multimedia/renderer/context/%1/metadata").arg(contextName);
// In newer OS versions, the filename is "metadata0", not metadata, so try both.
if (!QFile::exists(fileName))
fileName += '0';
QFile metaDataFile(fileName);
if (!metaDataFile.open(QFile::ReadOnly)) {
qWarning() << "Unable to open media metadata file" << fileName << ":"
<< metaDataFile.errorString();
return false;
}
const QString separator("::");
QTextStream stream(&metaDataFile);
Q_FOREVER {
const QString line = stream.readLine();
if (line.isNull())
break;
const int separatorPos = line.indexOf(separator);
if (separatorPos != -1) {
const QStringRef key = line.leftRef(separatorPos);
const QStringRef value = line.midRef(separatorPos + separator.length());
if (key == durationKey)
m_duration = value.toLongLong();
else if (key == widthKey)
m_width = value.toInt();
else if (key == heightKey)
m_height = value.toInt();
else if (key == mediaTypeKey)
m_mediaType = value.toInt();
else if (key == pixelWidthKey)
m_pixelWidth = value.toFloat();
else if (key == pixelHeightKey)
m_pixelHeight = value.toFloat();
else if (key == titleKey)
m_title = value.toString();
else if (key == seekableKey)
m_seekable = !(value == QLatin1String("0"));
else if (key == artistKey)
m_artist = value.toString();
else if (key == commentKey)
m_comment = value.toString();
else if (key == genreKey)
m_genre = value.toString();
else if (key == yearKey)
m_year = value.toInt();
else if (key == bitRateKey)
m_audioBitRate = value.toInt();
else if (key == sampleKey)
m_sampleRate = value.toInt();
else if (key == albumKey)
m_album = value.toString();
else if (key == trackKey)
m_track = value.toInt();
}
}
return true;
}
示例9: setAttr
/**
* Méthode servant au parseur XML pour recharger les configuration des éléments
* @brief Inst_Boucle::setAttr
* @param NomAttr Le nom de l'attribut visé
* @param Valeur Sa valeur
*/
void Inst_Boucle::setAttr(QString NomAttr, QStringRef Valeur)
{
//On affecte des valeurs au attributs en fonction du Nom et de la valeur donnée
//Modifie le type de boucle
if(NomAttr == "TypeDeBoucle")
{
int nValeur (Valeur.toInt()) ;
TypeBoucle tValeur (static_cast<TypeBoucle>(nValeur));
this->TypeDeBoucle = tValeur ;
}
//Déclare la condition avec des valeurs par défaut
if(NomAttr == "DescriptionCondition")
{
DescCondition tValeur;
tValeur.TCondition = LOG;
tValeur.nIndiceVar = 0;
tValeur.TypeComp = EGUAL;
tValeur.nValeur = 0;
tValeur.TestMat.sNomTest = "";
tValeur.TestMat.sCommande = "";
tValeur.TestMat.bActive = false;
this->DescriptionCondition = tValeur;
}
// === REMPLISSAGE DE LA CONDITION ===
if(NomAttr == "TCondition")
{
int nValeur (Valeur.toInt()) ;
TypeCondition tValeur (static_cast<TypeCondition>(nValeur));
this->DescriptionCondition.TCondition = tValeur;
}
if(NomAttr == "nIndiceVar")
{
unsigned int nValeur (Valeur.toInt()) ;
this->DescriptionCondition.nIndiceVar = nValeur ;
}
if(NomAttr == "TypeComp")
{
int nValeur (Valeur.toInt()) ;
TypeComparaison tValeur (static_cast<TypeComparaison>(nValeur));
this->DescriptionCondition.TypeComp = tValeur ;
}
if(NomAttr == "nValeur")
{
unsigned short nValeur (Valeur.toUShort()) ;
this->DescriptionCondition.nValeur = nValeur ;
}
if(NomAttr == "TestMat")
{
TestArduino NouveauTest;
NouveauTest.sNomTest = "";
NouveauTest.sCommande = "";
NouveauTest.bActive = false ;
this->DescriptionCondition.TestMat = NouveauTest;
}
if(NomAttr == "sNomTest")
{
QString sValeur (Valeur.toString());
this->DescriptionCondition.TestMat.sNomTest = sValeur ;
}
if(NomAttr == "sCommande")
{
QString sValeur (Valeur.toString());
this->DescriptionCondition.TestMat.sCommande = sValeur ;
}
if(NomAttr == "bActive")
{
QString sValeur (Valeur.toString());
bool bValeur (false);
if(sValeur == "true")
{
bValeur = true;
//.........这里部分代码省略.........
示例10: read_xml
bool TagIO::read_xml(
QIODevice* in,
const QString& relative_dir,
QHash< QString, QList<TagItem::Elements> >& elts
)
{
if( !in ) {
return false;
}
QDir dir;
if( !relative_dir.isEmpty() ) {
dir = QDir( relative_dir ).absolutePath();
}
QXmlStreamReader xml;
xml.setDevice( in );
if( xml.readNext() == QXmlStreamReader::StartDocument && !xml.isStartDocument() ) {
return false;
}
if( !xml.readNextStartElement() ) {
return false;
}
if( xml.name() != DATASET ) {
return false;
}
// skip info for user
while( xml.readNextStartElement() && ( xml.name() != IMAGES && xml.name() != TAGS ) ) {
xml.skipCurrentElement();
}
QHash<QString, QColor> tag_color_dict;
if( xml.name() == TAGS ) {
while( xml.readNextStartElement() && xml.name() == SINGLE_TAG ) {
tag_color_dict[ xml.attributes().value( NAME ).toString() ] = QColor( xml.attributes().value( COLOR ).toString() );
// empty elements are directly followed by endElement
// so readNext must be called
xml.readNextStartElement();
}
}
// within the "images" element
while( !xml.atEnd() ) {
if( xml.name() == SINGLE_IMAGE ) {
QString fullpath = xml.attributes().value( PATH ).toString();
if( fullpath.isEmpty() ) {
xml.skipCurrentElement();
continue;
}
if( !relative_dir.isEmpty() && dir.exists() ) {
fullpath = dir.absoluteFilePath( fullpath );
}
if( !xml.readNextStartElement() ) {
xml.skipCurrentElement();
continue;
}
while( xml.name() == BOX ) {
QXmlStreamAttributes att = xml.attributes();
QStringRef top = att.value( TOP );
QStringRef left = att.value( LEFT );
QStringRef width = att.value( WIDTH );
QStringRef height = att.value( HEIGHT );
bool skip = ( top.isEmpty() || left.isEmpty() || width.isEmpty() || height.isEmpty() );
xml.readNextStartElement();
skip = skip || ( xml.name() != LABEL );
QString label = xml.readElementText();
skip = skip || ( label.isEmpty() );
if( skip ) {
xml.skipCurrentElement();
xml.readNextStartElement();
continue;
}
TagItem::Elements elt;
elt._fullpath = fullpath;
elt._label = label;
elt._color = tag_color_dict.value( label );
elt._bbox.append( QRect( left.toInt(), top.toInt(), width.toInt(), height.toInt() ) );
elts[ fullpath ].append( elt );
xml.readNextStartElement();
while( xml.isEndElement() ) {
xml.readNextStartElement();
}
}
} else {
xml.readNextStartElement();
}
}
return true;
//.........这里部分代码省略.........