[英]Qt C++ initialize a QStringList class member
I have a class member of type QStringList
.我有一个
QStringList
类型的类成员。 I had a guess that when this class is instantiated, nex
instance get such a QStringLsit
with no elements in it.我有一个猜测,当这个类被实例化时,
nex
实例会得到这样一个没有元素的QStringLsit
。
I have a function that should fill in this QStringList
on user interaction.我有一个函数应该在用户交互时填写这个
QStringList
。 However, I see with debugger that class member does not exist at function call.但是,我在调试器中看到函数调用时不存在类成员。 What could it be all about?
这到底是怎么回事? Is there a way to initialize the
QListString
that I may be missing here?有没有办法初始化我可能在这里丢失的
QListString
?
QStringList
should get initialized on the creation of your object automatically (unless it is a pointer). QStringList
应该在创建对象时自动初始化(除非它是指针)。 I see two possible explanations for the debugger's behaviour:对于调试器的行为,我看到了两种可能的解释:
this
pointer is invalid when the function gets entered.this
指针是无效的。 This may be the case if you call the function on an uninitialised pointer to your class.QStringList
member correctly.QStringList
成员。QStringList*
(a pointer), it doesn't get automatically initialised on object creation.QStringList*
类型(指针),则它不会在对象创建时自动初始化。 Then you'd need to do list = new QStringList();
list = new QStringList();
in the constructor.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.