PDA

View Full Version : QString - no member function called 'find'



pitterb
13th January 2009, 11:23
I wrote a function:



#include<qstring.h>

void Calculator::calculation(QString &operation, QString &text_display)
{
QString a_string = "", b_string = "", result_string = "";
double a, b, result;
int position = 0, i, j;

while(1)
{
if ( ( position = operation.find('*') ) == -1 ) break;

for( i = position; i = 0 ; i-- )
{
if( operation.at( i ) == '*' || operation.at( i ) == '/' || operation.at( i ) == '+' || operation.at( i ) == '-' )
break;
a_string += operation.at( i );
}
for( j = position; j < operation.length() ; j++ )
{
if( operation.at( j ) == '*' || operation.at( j ) == '/' || operation.at( j ) == '+' || operation.at( j ) == '-' )
break;
b_string += operation.at( j );
}
a = a_string.toDouble();
b = b_string.toDouble();
result = a*b;
result_string = result_string.setNum( result, 'f', 10 );
operation.replace( i, i + j + 1, result_string );
}
text_display = result_string;
ui.display->setText( text_display );
}

Compiler says that QString class has no member function called 'find' (line 11), but when I read QString documentation...

http://doc.trolltech.com/3.3/qstring.html#find

...it's right there. Every other function like lenght() or at() works. What's wrong then?

wysota
13th January 2009, 11:31
It's from Qt3 and you are using Qt4. Use QString::indexOf().