Important: Please read the Qt Code of Conduct -

How to create a MS access mdb file by QT

  • really appreciate!

  • Hi,
    In general you can't. You can use windows-only facilities like MS ADO components and glue your code with your Qt application but this won't be portable across OSes, i.e. would be done against the Qt principles. While still legal that's not what I decided to do for "supporting" MDB files. I, within the Kexi Project (, used and a bit extended the MDB Tools open source project in order to get read only access to the MS Access files. This just enables an escape scenario so your data is eventually yours (but not your forms or even queries, handling them is only planned but possible after massive reverse engineering).

    So I recommend to review your requirements; it may be that you can stick with SQLite (which is used by Kexi by default) or even server database like MySQL or PostgreSQL - then you can use any of them directly with Qt (its QtSQL module).

    Just please note that creating new databases is not supported by the QtSQL API. You have to know how to do it (call single "open" function in SQLite or do some more calls in case of MySQL or PostgreSQL). If you expect to have all this done for you automagically, I've created special library extending Qt exactly for this, Predicate ( It was a part of Kexi, now it's not technically dependent on KDE or Kexi. If you think it's all nice and shiny, now the bad news: it should be available for general use by the end of 2011.

    PS: I do not think using ODBC would help you. You have to get access (pun not intended ;)) to a working Access instance anyway.

  • If MS Access is installed in parallel your Qt application can use COM to connect to MS Access and call its methods.

  • What I do, is use ODBC to access MS Access files. That works well, although speed (especially for writing) could be better.

    For creating an empty MDB file, there are two approaches. First of all, you can create one using a little bit of ActiveX. What you can also do, and that gives you the opportunity to prepare your data structure ahead of time if your app allows for that, is just to compile an empty .mdb file into your application as a resource, and copy that out to disk when you need it. I do that in my application, and that works just fine.

    jstaniek is right that Qt's API for manipulating databases is a bit lacking here and there. I have created an extension to this API to fix this where possible, but in the end his new Predicate framework is probably the better approach. However, seeing that that will still take time to mature, perhaps you can use it to build something that works now. The Access driver (building on ODBC) is actually the most mature and tested one.

Log in to reply