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. Parsing .mdb File in Qt4
Qt 6.11 is out! See what's new in the release blog

Parsing .mdb File in Qt4

Scheduled Pinned Locked Moved General and Desktop
15 Posts 3 Posters 14.3k 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.
  • V Offline
    V Offline
    vezprog
    wrote on last edited by
    #1

    Here's what I am trying to do:
    I have multiple .mdb files on my desktop containing 3 tables in each with specific data that I need. I would like to parse these tables, and get data from them. Is there a way to do this in Qt4/c++ libraries?

    My overall goal:
    I would like to take this data, and plot it in a Qwt plot (which I have already played around with already).

    Thanks in advance.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      Your best bet would be to use ODBC via de QtSql module, and connect to the .mdb files as a database. That approach works quite well, I have used it a lot in my previous job.

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vezprog
        wrote on last edited by
        #3

        Thank you for your quick reply. I thank you for your input and will check it out.

        Do you just connect as a localhost and query the file "or database"?

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          you will use the file as a database (use SQL to query data).

          Here a small code to connect to a mdb file using ODBC

          @QString filePath = "DRIVER={Driver do Microsoft Access (*.mdb)};FIL={CONN_NAME};DBQ=file.mdb";
          QSqlDatabase db = QSqlDatabase::addDatabase("QODBC", "odbc");
          db.setDatabaseName(filePath);
          QSqlQuery query(db)
          query.exec("SELECT * FROM TABLE;")
          ...
          @

          1 Reply Last reply
          0
          • V Offline
            V Offline
            vezprog
            wrote on last edited by
            #5

            Thank you for the helpful sample code, I will take a look and see if I can make some progress.

            Thanks again!

            1 Reply Last reply
            0
            • V Offline
              V Offline
              vezprog
              wrote on last edited by
              #6

              I apologize for the double post, for some reason I cannot get your code snipet to work. I have the odbc driver installed on linux, and i have the QtSql/SqlDatabae, QtSql/QODBCDriver incuded. I get the error when I try to run "sql.h: no such file or directory".

              @

              #include <QtCore>
              #include <QtSql/QSqlDatabase>
              #include <QtSql/QSqlQuery>
              #include <QtSql/QODBCDriver>
              #include <QtSql/qsql.h>
              #include "globals.h"
              #include "graph.h"
              #include "graphscrollbar.h"
              #include "buttonheader.h"
              #include "buttonsidebar.h"
              #include "mainwindow.h"
              #include "ui_mainwindow.h"

              // file prototype
              void connectODBCdatabase(QString selectedfile);

              void connectODBCdatabase(QString selectedfile)
              {
              // build database string
              QString filePath = "DRIVER={Driver do Microsoft Access (*.mdb)};FIL={CONN_NAME};DBQ=";
              filePath.append(selectedfile);

              // create database
              QSqlDatabase db = QSqlDatabase::addDatabase("QODBC", "odbc");
              db.setDatabaseName(filePath);
              
              // get data from .mdb file
              QSqlQuery query(db);
              query.exec("SELECT * FROM TABLE tablename;"&#41;;
              

              }

              @

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #7

                On linux, you are probably out of luck. AFAIK, there is no ODBC driver for mdb on non-windows systems. If you are on linux, I would strongly encourage you to see if there isn't a way to switch to a different database format.

                1 Reply Last reply
                0
                • V Offline
                  V Offline
                  vezprog
                  wrote on last edited by
                  #8

                  Unfortunately there is a separate software suit that creates the .mdb files, which is out of my control at the moment. I thought the unixODBC driver allows the user to communicate to that specific database format, which in turn, should allow me to access the database file correct? I guess my understanding on .mdb files is vague though...

                  I could convert the file to a comma delimited file using tools already available in the Linux world, but lets be real here, that's unacceptable to my standards :) I would like to automate this process.

                  There's gotta be a way to connect using SQL query's to the file.

                  I thank you for your insight, I will keep searching around.

                  1 Reply Last reply
                  0
                  • ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by
                    #9

                    [quote author="Andre" date="1313780603"]On linux, you are probably out of luck. AFAIK, there is no ODBC driver for mdb on non-windows systems.[/quote]
                    yes, does exist, but it is paid http://www.easysoft.com/products/data_access/odbc-access-driver/

                    You can use mdb tools to extract the data into a csv and parse as plain text (http://mdbtools.sourceforge.net/)

                    1 Reply Last reply
                    0
                    • V Offline
                      V Offline
                      vezprog
                      wrote on last edited by
                      #10

                      yeah, that was my "easy way out" using mdb tools. I fooled around with it yesterday, and was satisfied, yet I still would like to not have to convert the file. I will check out easysoft. Thank you.

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        andre
                        wrote on last edited by
                        #11

                        ODBC in and off itself does not allow you to interact with any database. It needs drivers to do the actual work. -AFAIK, there is no ODBC driver for .mdb files on unix, but I may be off there. I never found something that worked.-

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          andre
                          wrote on last edited by
                          #12

                          [quote author="Wagner Reck" date="1313781485"]
                          [quote author="Andre" date="1313780603"]On linux, you are probably out of luck. AFAIK, there is no ODBC driver for mdb on non-windows systems.[/quote]
                          yes, does exist, but it is paid http://www.easysoft.com/products/data_access/odbc-access-driver/

                          You can use mdb tools to extract the data into a csv and parse as plain text (http://mdbtools.sourceforge.net/)

                          [/quote]

                          I stand corrected. Thanks for the information!

                          1 Reply Last reply
                          0
                          • V Offline
                            V Offline
                            vezprog
                            wrote on last edited by
                            #13

                            yeah, that was my "easy way out" using mdb tools. I fooled around with it yesterday, and was satisfied, yet I still would like to not have to convert the file. I will check out easysoft, yet its quite a hefty price unfortunately. Thank you though.

                            1 Reply Last reply
                            0
                            • A Offline
                              A Offline
                              andre
                              wrote on last edited by
                              #14

                              Not sure if this is an option, but...
                              Could you keep the actual files on a windows machine and connect to that machine over the network? If so, than it should be doable to either expose the ODBC data connection to the network, or perhaps create a Qt based server that does the actual data querying for its connected (linux) clients.

                              1 Reply Last reply
                              0
                              • V Offline
                                V Offline
                                vezprog
                                wrote on last edited by
                                #15

                                Now you got my thinkin.

                                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