Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. Creating odbc plugin
QtWS25 Last Chance

Creating odbc plugin

Scheduled Pinned Locked Moved Installation and Deployment
10 Posts 2 Posters 4.9k Views
  • 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.
  • G Offline
    G Offline
    gwall780
    wrote on last edited by
    #1

    Hi, I am trying to connect a MS Sql server to my application using the ODBC driver. The problem I have is I do not know what I am doing!

    Could you please tell me step by step, what I need to do to connect. I have read the documentation but it is not exactly clear. Please forgive my ignorance :)

    thanks

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

      The ODBC driver is build by default, so there is nothing special you need to do to get it to work. Do you already have ODBC itself setup correctly? Did you setup an ODBC data source (you do that in the OS, not using Qt) for your database?

      1 Reply Last reply
      0
      • G Offline
        G Offline
        gwall780
        wrote on last edited by
        #3

        Hi Thanks for replying....

        I am using a host for my database and I have set an ODBC connection. The problem is how to get connected to the database. I have very little experience with QT and have read the docs about creating a plugin etc. If this is enabled by default, what do I need to do in my application to connect. When I use the addDatabase function, I get an error 'collect2: Id returned 1 exit status. I was assuming this was because the ODBC driver is not installed. What header files should I be using etc?

        Thanks agian

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

          You should add this to your .pro file, to start with:
          @
          QT += sql
          @

          That should take care of the linking error.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            gwall780
            wrote on last edited by
            #5

            Hi Again,

            Thank you, this seems to have solved the linking error. Is there anything else I need to do, or should that be it? Do I need to include the Sqlt header file and the one for odbc?

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

              You only need to include the header files for the classes that you use directly at the place where you use it. That is, you will probably need to include these at some point (not necessarily all at the same place):

              @
              #include <QSqlDatabase>
              #include <QSqlQuery>
              #include <QSqlError>
              //and perhaps also:
              #include <QSqlRecord>
              #include <QSqlField>
              @

              1 Reply Last reply
              0
              • G Offline
                G Offline
                gwall780
                wrote on last edited by
                #7

                thanks for your help Andre. If I run into any more probs I will be back :)

                Thanks again.

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  gwall780
                  wrote on last edited by
                  #8

                  Ok, still got problems.....lol

                  If I create an odbc on a remote host, how do I connect my app to it? Any help appreciated.

                  Regards,

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

                    How is having problems something to 'lol' about?

                    Anyway, you need to set the odbc connectionstring as the database name.

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      gwall780
                      wrote on last edited by
                      #10

                      Where can I find info about the connection string format. All I have found at the moment is a little about using the DNS connection and setting the following:

                      @
                      QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
                      db.setHostName( <What goes here? > );
                      db.setDatabaseName( < what goes here?> );
                      db.setUserName("xxxx");
                      db.setPassword("xxx");
                      @

                      Is this the right way to connect? Can I use a DNS-less connection string instead and if so how?

                      I have set up a ODBC source on my remote server but have no idea how to connect to it....

                      I wont lol again, not yet anyway!

                      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