Results 1 to 20 of 24

Thread: Segmentation fault

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Segmentation fault

    Yes, but I was referring to the internal QSqlDatabase pointer. The one from MySqlConnect.

  2. #2
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Segmentation fault

    Ok, just a second. Did you mean this chunk of code:
    Qt Code:
    1. MySQLConnect::MySQLConnect(QString db_user, QString db_pass, QString db_name, QString host, QString type) {
    2.  
    3. //connect to database
    4. QSqlDatabase db = QSqlDatabase::addDatabase(type);
    5. db.setHostName(host);
    6. db.setDatabaseName(db_name);
    7. db.setUserName(db_user);
    8. db.setPassword(db_pass);
    9.  
    10. //get a pointer to a database connection
    11. m_pDatabase = &QSqlDatabase::database();
    12. Q_CHECK_PTR(m_pDatabase);
    13.  
    14. //sql table model == read/write model --> navigate and modify individual sql tables
    15. m_pModel = new QSqlRelationalTableModel(this);
    16. Q_CHECK_PTR(m_pModel);
    17.  
    18. //model->setTable(db_table);
    19. //all changes will be cached in the model until either submitAll() or revertAll() is called
    20. m_pModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
    21.  
    22. //populates the model with data from the table, using the specified filter and sort conditions
    23. //model->select();
    24. }
    25.  
    26. //QSqlDatabase* MySQLConnect::m_pDatabase=0;
    27.  
    28. /*
    29. //this function is called if a refresh button is clicked
    30. void MySQLConnect::refresh_everything() {
    31.   model->select();
    32. }
    33.  
    34. void MySQLConnect::change_mysql() {
    35.   //submits all pending changes to the mysql database
    36.   model->submitAll();
    37. }
    38. */
    To copy to clipboard, switch view to plain text mode 
    Qt 5.3 Opensource & Creator 3.1.2

  3. #3
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Segmentation fault

    Rewrite it like this:
    Qt Code:
    1. MySQLConnect::MySQLConnect(QString db_user, QString db_pass, QString db_name, QString host, QString type) {
    2. //connect to database
    3. m_Database = QSqlDatabase::addDatabase(type);
    4. m_Database.setHostName(host);
    5. m_Database.setDatabaseName(db_name);
    6. m_Database.setUserName(db_user);
    7. m_Database.setPassword(db_pass);
    8. bool openedOK = m_Database.open();
    9.  
    10. m_pModel = new QSqlRelationalTableModel(this);
    11. Q_CHECK_PTR(m_pModel);
    12. m_pModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
    13. ...
    14. }
    To copy to clipboard, switch view to plain text mode 

    replace m_pDatabase with m_Database (not a pointer).

Similar Threads

  1. Strange segmentation fault
    By Lykurg in forum Qt Programming
    Replies: 3
    Last Post: 4th January 2009, 19:50
  2. Segmentation Fault
    By Krish_ng in forum Qt Programming
    Replies: 8
    Last Post: 7th August 2007, 10:49
  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.