Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved]How to use M.S access in Qt?
Forum Updated to NodeBB v4.3 + New Features

[Solved]How to use M.S access in Qt?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 3.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    whitesong
    wrote on last edited by
    #1

    I want use access database in my project, this is my code:
    @#include <QCoreApplication>
    #include <QtSql/QSqlDatabase>
    #include <QDebug>
    #include <QStringList>

    int main(int argc, char argv[])
    {
    QCoreApplication a(argc, argv);
    QSqlDatabase m_db = QSqlDatabase::addDatabase("QODBC");
    m_db.setDatabaseName("DRIVER={Microsoft Access Driver (
    .mdb)};FIL={MS Access};DBQ=c:\db.mdb;");
    bool ok = m_db.open();
    if(ok)
    qDebug()<<"ok";
    else
    qDebug()<<"not ok";
    return a.exec();
    }@
    When I run it it shows mt 'not ok' I think I use wrong connection because QODBC driver in available,
    another question is where 'db.mdb' file must be located? in debug folder or it must be attached to the project and how the connection string should change ?

    1 Reply Last reply
    0
    • W Offline
      W Offline
      whitesong
      wrote on last edited by
      #2

      It Works with this connection string:
      @ m_db.setDatabaseName("Driver={Microsoft Access Driver (*.mdb, *.accdb)};DSN='';DBQ=" + QCoreApplication::applicationDirPath() + "/db.mdb");
      @

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved