Results 1 to 2 of 2

Thread: Runtime crash with Table

  1. #1
    Join Date
    Jul 2017
    Posts
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Runtime crash with Table

    Hi,

    Well, I try to display a part of my SQL Database on a QTableView, simple right ?
    Well the problem is the code compiles silently but whenever the signal that should initiate the QTableView is "launched/activated", the app crashes...
    When looking at the crash log I finally found that there was a "Bad access error":
    Exception Type: EXC_BAD_ACCESS (SIGSEGV)
    Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000008
    Exception Note: EXC_CORPSE_NOTIFY

    Here is the code :

    Qt Code:
    1. void MainWindow::printTableView()
    2. {
    3. QSqlDatabase db = connectionArticle->getDB(); //Here I retrieve the database connection from an other window
    4. QSqlQuery *query = new QSqlQuery();
    5. if (db.open()){
    6. if (db.databaseName()=="article")
    7. {
    8. query->prepare("SELECT name,type FROM article");
    9. }else{
    10. query->prepare("SELECT name,isWorking,currentArticle FROM journalist");
    11. }
    12. query->exec();
    13. model->setQuery(*query); // When using the debugger, I never pass through this line (it stays here for ever)
    14. }
    15.  
    16. ui->tableView->setModel(model);
    To copy to clipboard, switch view to plain text mode 

    Well, if anyone knows where I missed I would be glad to know 1
    Thank you in advance !


    Added after 6 minutes:


    Well I figured the little error in the query declaration...
    Qt Code:
    1. QSqlQuery *query = new QSqlQuery(db);
    To copy to clipboard, switch view to plain text mode 
    But it changes nothing to the problem...
    Last edited by Alex2822; 28th July 2017 at 15:25.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Runtime crash with Table

    Where did you initialize the model?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Replies: 0
    Last Post: 3rd November 2015, 18:58
  2. Creating diagonal table headers
    By kubark42 in forum Qt Programming
    Replies: 1
    Last Post: 11th September 2013, 14:19
  3. Replies: 4
    Last Post: 22nd July 2011, 11:42
  4. delete runtime-created widgets causes crash
    By jonasbalmer in forum Qt Programming
    Replies: 5
    Last Post: 10th February 2010, 22:36
  5. creating table plugin
    By mgurbuz in forum Qt Programming
    Replies: 3
    Last Post: 28th April 2006, 14:50

Tags for this Thread

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.