Results 1 to 2 of 2

Thread: Query on MS Access DB cause crash

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2016
    Posts
    8
    Qt products
    Qt5
    Platforms
    Windows Android
    Thanks
    3

    Default Query on MS Access DB cause crash

    Hello guys,
    i'm trying to make a query on an application that is connected with a .mdb file.
    In one of my dialogs i can populate a tableView with no problem and then close the dialog without any problems, let's say i'm reading records from the DB table "PEOPLE".
    In the same dialog i have a form to add rows to PEOPLE table. I can add 1-n° rows but when i close the dialog the application crashes EVERY time.
    Things like this never happened to me when i was using SQLite DB.

    Let me post some of my code, maybe you can help...

    This is the way i'm doing my connection with the ACCESS .mdb file
    Qt Code:
    1. bool connectionOpen(){
    2. static const QString path = PATH;
    3. mydb = QSqlDatabase::addDatabase("QODBC", "Contact");
    4. QString params="Driver={Microsoft Access Driver (*.mdb, *.accdb)};DSN='';DBQ="+ path;
    5. mydb.setDatabaseName(params);
    6.  
    7. if (!mydb.open())
    8. {
    9. qDebug() << "Error: connection with database fail";
    10. qDebug() << mydb.lastError().text();
    11. return false;
    12. }
    13. else
    14. {
    15. qDebug() << "Database: connection ok";
    16. return true;
    17. }
    18. return true;
    To copy to clipboard, switch view to plain text mode 

    This is showing the rows and is working as intended
    Qt Code:
    1. void class::on_pushButton_refreshListP_clicked()
    2. {
    3.  
    4.  
    5. QSqlDatabase db = QSqlDatabase::database("Contact");
    6.  
    7. if (db.isOpen())
    8. {
    9. QSqlTableModel *model = new QSqlTableModel(this,db);
    10. model->setTable("class");
    11. model->setEditStrategy(QSqlTableModel::OnFieldChange);
    12.  
    13. model->setHeaderData(0, Qt::Horizontal, tr("a"));
    14. model->setHeaderData(1, Qt::Horizontal, tr("b"));
    15. model->setHeaderData(2, Qt::Horizontal, tr("c"));
    16. model->select();
    17.  
    18. ui->tableView->setModel(model);
    19. }
    To copy to clipboard, switch view to plain text mode 

    This is the part of code that is working till i close the dialog... Than the application crashes
    Qt Code:
    1. if (db.isOpen())
    2. {
    3. QSqlQuery query(db);
    4. // query.setForwardOnly(true);
    5. query.prepare("INSERT INTO class(a, b, c) "
    6. " VALUES ( :a,:b, :c)");
    7.  
    8.  
    9. query.bindValue(":a", a);
    10. query.bindValue(":b", b);
    11. query.bindValue(":c", c);
    12.  
    13.  
    14. if(query.exec())
    15. {
    16. qDebug() << "exec";
    17. QTimer::singleShot(0, this, SLOT(on_pushButton_refreshListP_clicked()));
    18. }
    To copy to clipboard, switch view to plain text mode 
    someone can tell me what im'm doing wrong? I'm missing some configuration for the MS ACCESS?

    Thank you for your time and answers
    Last edited by Bruschetta; 4th October 2016 at 15:38.

Similar Threads

  1. Replies: 0
    Last Post: 3rd November 2015, 17:58
  2. Replies: 7
    Last Post: 16th April 2015, 17:11
  3. Own widget access causes crash
    By p3t3 in forum Newbie
    Replies: 1
    Last Post: 24th March 2011, 01:13
  4. thread GUI access crash
    By liqxpil in forum Qt Programming
    Replies: 3
    Last Post: 14th December 2010, 15:47
  5. QSqlTableModel submitAll access query
    By patrik08 in forum Qt Programming
    Replies: 4
    Last Post: 27th April 2007, 08:04

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.