Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 4

Qt-interest Archive, July 2007
QString modification.


Message 1 in thread

Hi All,

I am facing a problem.

I want to change a character in a QString at position i

for example,

func(QChar& a)
{
  this function updates QChar a;
}

QString str="Some String"
for(int i = 0 ;i < str.length; i++)
{
  func(str[i]);  //this is cannot do.
}
This throws an error: error: invalid initialization of non-const reference
of type 'QChar&' from a temporary of type 'QCharRef'

Can Any one help me???


Thanks in Advance..
Manjunatha

Message 2 in thread

Manjunatha M (ààààààà àà) schrieb:
> func(QChar& a)
> {
>   this function updates QChar a;
> }
> 
> QString str="Some String"
> for(int i = 0 ;i < str.length; i++)
> {
>   func(str[i]);  //this is cannot do.
> }
> This throws an error: error: invalid initialization of non-const 
> reference of type 'QChar&' from a temporary of type 'QCharRef'
> 
> Can Any one help me???

Simply use QCharRef as parameter type in func(). See the docs for 
QString::operator[](int) for details.

Martin

-- 
 [ signature omitted ]