PDA

View Full Version : A doubt about initialization of variables



vcp
10th December 2009, 18:52
Hi,

When I initialize a variable of this way:

QString str=QString() or
QStringList lst=QStringList() what exactly accours? What value is assigned to the variable?

Thanks in advanced

spirit
10th December 2009, 19:45
in the first example an empty string in the second an empty list. :)

vcp
10th December 2009, 20:18
Thanks spirit.

squidge
10th December 2009, 21:00
You'll also notice this in the documentation.

QString::QString ()
Constructs a null string. Null strings are also empty.

QStringList::QStringList ()
Constructs an empty string list.

JohannesMunk
11th December 2009, 02:18
and those default constructors are called here as well, without any superficial assignment operation...



QString str;
QStringList sl;


You can call some other constructor than the default constructor like this:



QString str("yep");
QStringList sl(str);


HIH

Johannes

vcp
11th December 2009, 11:42
Hi people,

Thanks by all answers.