Page 2 of 2 FirstFirst 12
Results 21 to 28 of 28

Thread: (Another) segmentation fault

  1. #21
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: (Another) segmentation fault

    Notice also the sentence in docs:
    If connectionName does not exist in the list of databases, 0 is returned.
    So add a check for null pointer:
    Qt Code:
    1. void GlavnoO::pushButton3_clicked()
    2. {
    3. bool ok = FALSE;
    4. QSqlDatabase *baza = QSqlDatabase::database();
    5. if (baza)
    6. {
    7. ok = baza->isOpen();
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  2. The following user says thank you to jpn for this useful post:

    Lebowski (6th April 2006)

  3. #22
    Join Date
    Apr 2006
    Location
    Slovenia
    Posts
    33
    Thanks
    5
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: (Another) segmentation fault

    Yep, that solves the segmentation fault. But I would still like to know how to acces databse connection which I opened in another form.

  4. #23
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: (Another) segmentation fault

    Quote Originally Posted by Lebowski
    And I have to use pointers
    Sure, you're using Qt3 and I was looking at Qt4 docs.

    But I would still like to know how to acces databse connection which I opened in another form.
    First check if addDatabase returns a valid database handle.

  5. #24
    Join Date
    Apr 2006
    Location
    Slovenia
    Posts
    33
    Thanks
    5
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: (Another) segmentation fault

    I did check with this code in form povezava (povezava.ui.h):
    Qt Code:
    1. bool ok = baza->open();
    2. if (!ok) {QMessageBox::warning (this, "Pozor!!!!!!!!!!!", "not working",1,0,0);}
    3. else {
    4. QMessageBox::information ( this, "Uspeh!!!!!!!!!", "working",1,0,0 );
    5. close();
    6. };
    To copy to clipboard, switch view to plain text mode 
    And it certainly works.

    But now I need to access it from a different form, from file glavnoo.ui.h.

  6. #25
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: (Another) segmentation fault

    So why don't you use QSqlDatabase::database()?

  7. #26
    Join Date
    Apr 2006
    Location
    Slovenia
    Posts
    33
    Thanks
    5
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: (Another) segmentation fault

    I am using that.
    Qt Code:
    1. void GlavnoO::test_clicked()
    2. {
    3. bool ok = FALSE;
    4. QSqlDatabase *baza = QSqlDatabase::database();
    5. if (baza) {
    6. ok = baza->isOpen();
    7. };
    To copy to clipboard, switch view to plain text mode 
    Originally it was without 'if (baza) ...' statement.

  8. #27
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: (Another) segmentation fault

    So what's wrong with that? The form you use it in doesn't matter. You can use QSqlDatabase::database() from anywhere. Just makesure addDatabase() has been invoked earlier.

  9. The following user says thank you to wysota for this useful post:

    Lebowski (6th April 2006)

  10. #28
    Join Date
    Apr 2006
    Location
    Slovenia
    Posts
    33
    Thanks
    5
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: (Another) segmentation fault

    Yep, it does work now!! Thanx all.

    Seems I was missing QSqlDatabase::database() statement so my 'baza' pointer had a random value.

Similar Threads

  1. segmentation fault for no apparent reason
    By rishiraj in forum Newbie
    Replies: 1
    Last Post: 12th February 2009, 11:13
  2. segmentation fault
    By uchennaanyanwu in forum Newbie
    Replies: 3
    Last Post: 31st July 2008, 16:52
  3. Process aborted. Segmentation fault
    By Pragya in forum Qt Programming
    Replies: 3
    Last Post: 30th May 2007, 08:12
  4. Segmentation fault running any QT4 executables
    By jellis in forum Installation and Deployment
    Replies: 7
    Last Post: 19th May 2007, 16:35
  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.