Question

I have a class member of type QStringList. I had a guess that when this class is instantiated, nex instance get such a QStringLsit with no elements in it. I have a function that should fill in this QStringList on user interaction. 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?

thanks and regards.

Was it helpful?

Solution

QStringList should get initialized on the creation of your object automatically (unless it is a pointer). I see two possible explanations for the debugger's behaviour:

  • Your object (of which you call the function) doesn't get created before the function call; that means that the this pointer is invalid when the function gets entered. This may be the case if you call the function on an uninitialised pointer to your class.
  • The debugger just doesn't show the QStringList member correctly.
  • If your member is of type QStringList* (a pointer), it doesn't get automatically initialised on object creation. Then you'd need to do list = new QStringList(); in the constructor. But I doubt that you need a pointer to a string list here.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top