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

Qt-interest Archive, March 2007
Re: Difference between QString::ref and QString::operator[]


Message 1 in thread

Hi,

> The Qt 4.2 documentation says to use operator[] in place of the Qt3
> compatibility function QString::ref(uint).
> However, as this example shows, they are not equivalent:

Mmmh... This looks disturbing. The following code shows s2 is always 
shorter than s1 (exactly one character):
	#include <QString>
	#include <QtDebug>
	int main() {
	   QString s1, s2;
	   for(int i = 0; i < 5; ++i) {
	      s1[i] = 'x';
	      s2.ref(i) = 'x';
	      qDebug() << s1.size() << "-" << s2.size();
	   }
	}

I would suggest sending a bug report to Trolltech:
	http://www.trolltech.com/bugreport-form
Maybe I'm missing something, but in any case this could indeed be 
documented.

--
 [ signature omitted ]