Results 1 to 5 of 5

Thread: Seg fault QSqlRecord

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2008
    Posts
    276
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Seg fault QSqlRecord

    It seems that if I declare

    Qt Code:
    1. model = new QSqlQueryModel(this);
    To copy to clipboard, switch view to plain text mode 

    all works.
    Which is the difference?

  2. #2
    Join Date
    Aug 2006
    Posts
    221
    Thanks
    3
    Thanked 29 Times in 19 Posts

    Default Re: Seg fault QSqlRecord

    Quote Originally Posted by giusepped View Post
    It seems that if I declare

    Qt Code:
    1. model = new QSqlQueryModel(this);
    To copy to clipboard, switch view to plain text mode 

    all works.
    Which is the difference?
    Outch, this happens when only a part of the code is posted. But what I do not understand is why your code compiles at all.

    You do a
    Qt Code:
    1. QSqlQueryModel *model = new QSqlQueryModel(this);
    To copy to clipboard, switch view to plain text mode 
    in your constuctor? Don't know, this part is missing. However, your *model is a local variable, which has absolutely nothing to do with the model in updateDetails(...). Wonder what 'model' the compiler finds in updateDetails(...) at all. Or you have a model pointer as member variable. However, this is not the one you initialize in your constructor.

  3. #3
    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: Seg fault QSqlRecord

    because you have a class member variable model and it was not initilazed.
    in constructor you create a variable with the same name
    Qt Code:
    1. ...
    2. QSqlQueryModel *model = new QSqlQueryModel(this);
    3. ...
    To copy to clipboard, switch view to plain text mode 

    and when you try to access to methods in a model (it is still isn't initilazed) you get seg fault, because model variable has wrong pointer.

  4. #4
    Join Date
    May 2008
    Posts
    276
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Seg fault QSqlRecord

    Solved.Thank you.
    In fact, in the header I defined
    Qt Code:
    1. QSqlRecord *model;
    To copy to clipboard, switch view to plain text mode 
    That was the error.
    step by step I am going to get accustomed to C++.
    Bye

Similar Threads

  1. Replies: 3
    Last Post: 1st September 2008, 23:57
  2. Using qsqlrecord?
    By triperzonak in forum Qt Programming
    Replies: 2
    Last Post: 23rd July 2008, 11:04
  3. Segmentation fault running any QT4 executables
    By jellis in forum Installation and Deployment
    Replies: 7
    Last Post: 19th May 2007, 16:35
  4. QSqlRecord problem
    By stevey in forum Qt Programming
    Replies: 2
    Last Post: 24th September 2006, 22:32
  5. Icons missing => segmentation fault
    By antonio.r.tome in forum Qt Programming
    Replies: 4
    Last Post: 8th March 2006, 16:30

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
  •  
Qt is a trademark of The Qt Company.