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. Using text databases in Qt
Forum Updated to NodeBB v4.3 + New Features

Using text databases in Qt

Scheduled Pinned Locked Moved General and Desktop
13 Posts 4 Posters 8.0k 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.
  • S Offline
    S Offline
    soroush
    wrote on last edited by
    #1

    Hi there

    I need to use a CSV database with Qt. I read documentation but there is nothing about connection strings, defining provider etc. In fact
    the program should be something like this: "http://support.microsoft.com/kb/210073":http://support.microsoft.com/kb/210073

    It read records stored in a text file, search between them and add records to it. there should be a file named Schema.ini like as described in above link.

    note: I'm writing my homework. My TA send me some C# examples but I don't have Windows installed on my laptop.

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      ZapB
      wrote on last edited by
      #2

      That example from the link uses MS DAO which is not cross-platform so Qt will not have any direct support for it.

      The supported drivers can be found in your Qt source directory under src/sql/drivers. These include odbc so maybe you can access your csv "database" by using odbc with a suitable connection string to hok up to the DAO stuff. Not something I have ever tried.

      I would instead simply import your csv file into a proper SQL database table(s) or maybe write a custom QAbstractTableModel sub-class that provides access to your data via Qt's modelview architecture.

      Nokia Certified Qt Specialist
      Interested in hearing about Qt related work

      1 Reply Last reply
      0
      • S Offline
        S Offline
        soroush
        wrote on last edited by
        #3

        Hmmm,
        How do I import a csv into SQL with Qt?

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DenisKormalev
          wrote on last edited by
          #4

          To import csv into SQLite (for example) you should create new sqlite database, create table there, read your csv file line by line, parse each line and insert it into sqlite database. Nothing extra hard here.
          But I think that another ZapB's solution is better (about sub-classing QAbstractItemModel)

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

            What's more: I know somebody has already "done that subclassing":http://libqxt.bitbucket.org/doc/0.6/qxtcsvmodel.html for you, and created a QAbstractItemModel that reads CSV files.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              DenisKormalev
              wrote on last edited by
              #6

              Andre, that's great. I think it will help OP to solve his problem.

              1 Reply Last reply
              0
              • Z Offline
                Z Offline
                ZapB
                wrote on last edited by
                #7

                Unles the whole point of the homework assignment was to use SQL of course ;-)

                Nokia Certified Qt Specialist
                Interested in hearing about Qt related work

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  DenisKormalev
                  wrote on last edited by
                  #8

                  ZapB, for me it looks a bit strange to use sql for csv :)

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    soroush
                    wrote on last edited by
                    #9

                    I think I can't describe what I really need. In this project there are various text database in CSV format with a single Schema.ini file. The .ini file includes description about records stored in each database. something like this:
                    @
                    [customers.txt]
                    customerID/name/last/
                    delimiter=';'

                    [sales.txt]
                    customerID/stuffID/count/fee/date
                    delimiter=';'
                    @

                    then we should use a SQL command object to interact with data. like this:
                    @
                    "select * from customers.txt where ..."
                    @

                    which returns an array of System.Object. libqxt (what Andre says) is great for working with CSV's but I can't find a way to use sql with that model.

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      DenisKormalev
                      wrote on last edited by
                      #10

                      So sql is required? In this case I think the best approach is firstly convert csv to sqlite and after it use sqlite databases.

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        soroush
                        wrote on last edited by
                        #11

                        ok thank you, I'll try and come back...

                        1 Reply Last reply
                        0
                        • Z Offline
                          Z Offline
                          ZapB
                          wrote on last edited by
                          #12

                          Agreed, import them into sqlite would be the simplest approach to this somewhat artificial assignment.

                          Nokia Certified Qt Specialist
                          Interested in hearing about Qt related work

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

                            Agreed, though that approach will not give you System.Object's, whatever those may be exactly. It will give you a QSqlQuery with records containing a QVariant for each field in the record.

                            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