Results 1 to 7 of 7

Thread: why qstringlist *ps "Segmentation fault"?

  1. #1
    Join Date
    Aug 2009
    Posts
    28
    Thanks
    5
    Thanked 1 Time in 1 Post

    Unhappy why qstringlist *ps "Segmentation fault"?

    i want to init QStringList through a function,
    my code:

    Qt Code:
    1. initqstringlist(&qs);
    2.  
    3. the func is:
    4. int void initqstringlist(QStringList *qs)
    5. {
    6. qs->append("1"); //Segmentation fault
    7. qs->append("2");
    8. }
    To copy to clipboard, switch view to plain text mode 
    why it report "Segmentation fault"? do i misunderstand the class?

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: why qstringlist *ps "Segmentation fault"?

    probably QStringList qs; is out of scope and since qs is created on stack, it automatically is deleted.
    Last edited by spirit; 22nd September 2009 at 15:58.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Dec 2008
    Location
    TaganrogNativelandChehov,Russia
    Posts
    64
    Thanks
    1
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: why qstringlist *ps "Segmentation fault"?

    you mast transmit to your initqstringlist valid pointer
    Qt Code:
    1. void initqstringlist(lst);
    To copy to clipboard, switch view to plain text mode 
    and what is this declaration meant:
    int void initqstringlist()
    ???
    Last edited by kwisp; 22nd September 2009 at 15:58.
    east or west home is best

  4. #4
    Join Date
    Apr 2008
    Location
    Russia, Moscow
    Posts
    86
    Thanks
    2
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4

    Default Re: why qstringlist *ps "Segmentation fault"?

    Attach minimal compilable example please.

  5. #5
    Join Date
    Aug 2009
    Posts
    28
    Thanks
    5
    Thanked 1 Time in 1 Post

    Question Re: why qstringlist *ps "Segmentation fault"?

    Quote Originally Posted by kwisp View Post
    you mast transmit to your initqstringlist valid pointer
    Qt Code:
    1. void initqstringlist(lst);
    To copy to clipboard, switch view to plain text mode 
    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?

  6. #6
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: why qstringlist *ps "Segmentation fault"?

    no, it should work fine.
    can you show as compilable example?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  7. #7
    Join Date
    Aug 2009
    Posts
    28
    Thanks
    5
    Thanked 1 Time in 1 Post

    Smile Re: why qstringlist *ps "Segmentation fault"?

    i figured it out .
    i use memset() before.
    thank everyone.

Similar Threads

  1. why is there so strange "Segmentation fault" ?
    By lanmanck in forum Qt Programming
    Replies: 9
    Last Post: 2nd March 2010, 12:55
  2. QStringList
    By jaca in forum Qt Programming
    Replies: 5
    Last Post: 17th May 2008, 10:12
  3. QStringList in QObject::connect
    By DPinLV in forum Qt Programming
    Replies: 6
    Last Post: 6th September 2006, 17:01
  4. Cannot queue arguments of type 'QStringList'
    By vfernandez in forum Qt Programming
    Replies: 2
    Last Post: 19th April 2006, 20:48
  5. need help to classify some QStringList
    By patcito in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2006, 21:24

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.