Code doesnt work
-
Hellow, plaease, tell me why my code doesnt work?
@bool isClass = false;
for(int a=0;a<=needNext.count();a++)
{
if (QString(needNext[a])!=QString(" "))
if (QString(needNext[a])==QString("}"))
{
qDebug() <<"1"+ QString(needNext[a]);
isClass=true;
a=needNext.count();
}
else
{
a=needNext.count();
qDebug() <<"2"+ QString(needNext[a]);
}
}@
It is must find last symbol in text unequal " "(space) and if last symbol equal "{" should happen assignment
It is always display "2 (without second qoute)
As the text is supplied text
@QPushButton{
background-color: #123123;
}@
for example -
There is an ambiguous 'else' here. put contents of every if in {} always. also you don't need to convert QChar s to QString . they are themselves comparable.
I assume needNext is a QString (is not?)
try tis code:@ for(int a=0; a<=needNext.count(); a++)
{
if (needNext[a]!=QChar(' '))
{
if (needNext[a]==QChar('}'))
{
qDebug() <<"1"+ needNext[a];
isClass=true;
// a=needNext.count();
// probably you mean:
break;
}
else
{
//a=needNext.count();
break;
qDebug() <<"2"+ needNext[a];
}
}
}@
If you want to iterate over all characters of a QString, you may want to use a bit more elegant way using iterators:
@
QString::ConstIterator i = needNext.begin();
while(i != needNext.end())
{
if ( *i !=QChar(' '))
{
if ( *i ==QChar('}'))
{
// ...
i++;
}
@