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

Qt-interest Archive, March 2002
QArray and QString


Message 1 in thread

Hello,

I'm getting seg faults when I try to assign a string
to a QString within a QArray. Is this a bug or a
problem with my code?

QArray<QString> str(10);
str[0] = "a"; // Seg fault
str[1] = "b";
str[0] = str[1];

Thanks
Liming
Qt Non-Commercial 2.3.0
VSC++ SP5

__________________________________________________
Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards®
http://movies.yahoo.com/


Message 2 in thread

Liming Tsai wrote:
> I'm getting seg faults when I try to assign a string
> to a QString within a QArray. Is this a bug or a
> problem with my code?

The documentation for QArray reads:

  QArray stores the array elements directly in the array.
  It can only deal with simple types, i.e. C++ types, structs
  and classes that have no constructors, destructors or virtual
  functions. QArray uses bitwise operations to copy and compare
  array elements.

By this definition, a QString is not a simple type.
You may consider using a QStringList instead.  It is not as
time efficient as an array would be, but it works fairly well.

Rob