PDA

View Full Version : why qstringlist *ps "Segmentation fault"?



lanmanck
22nd September 2009, 16:39
i want to init QStringList through a function,
my code:



QStringList qs;
initqstringlist(&qs);

the func is:
int void initqstringlist(QStringList *qs)
{
qs->append("1"); //Segmentation fault
qs->append("2");
}

why it report "Segmentation fault"? do i misunderstand the class?

spirit
22nd September 2009, 16:49
probably QStringList qs; is out of scope and since qs is created on stack, it automatically is deleted.

kwisp
22nd September 2009, 16:50
you mast transmit to your initqstringlist valid pointer


QStringList* lst = new QStringList;
void initqstringlist(lst);

and what is this declaration meant:
int void initqstringlist()
???

SABROG
22nd September 2009, 16:52
Attach minimal compilable example please.

lanmanck
22nd September 2009, 17:24
you mast transmit to your initqstringlist valid pointer


QStringList* lst = new QStringList;
void initqstringlist(lst);

and what is this declaration meant:
int void initqstringlist()
???

sorry,i make a mistake,it is:
inline void initqstringlist(QStringList *qs);

but ,the variable “qs” is a member,declared in xxx.h:
public:
QStingList qs;
does it have be a pointer?

spirit
22nd September 2009, 17:26
no, it should work fine.
can you show as compilable example?

lanmanck
23rd September 2009, 08:46
i figured it out .
i use memset() before.
thank everyone.