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. How to connect to MySQL using QODBC
Forum Updated to NodeBB v4.3 + New Features

How to connect to MySQL using QODBC

Scheduled Pinned Locked Moved General and Desktop
8 Posts 6 Posters 6.5k 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.
  • G Offline
    G Offline
    gor kogalo
    wrote on last edited by
    #1

    hello every one. I am new in Qt. I am trying to connect to Mysql using QODBC. her is the code.

    QSqlDatabase db = QSqldatabase::addDatabase("QODBC");

    db.setDatabaseName("Driver={MySQL ODBC 5.1 Driver}; DATABASE=localhost;");

    db.setUserName("root");

    db.setPAssword("gordo");

    if(!db.open())

    {

    ......

    }

    the error which i am getting is undefined reference to '_imp__ZN12QSqlDatabase17defaultConnectionE'.
    where can the problem be?

    Gor

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      Have you added the sql module to your .pro file?
      @
      QT += sql
      @
      If yes, re-run qmake.

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

        Thanks very much for your contribution. I have added the module and it runs smoothly.

        Gor

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

          Note that Qt also supports connecting to MySQL using native drivers. If possible for your use case, then I would prefer that over going through ODBC.

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

            How do i use the native driver instead? Should I add it to the make file of the project like like I did to sql module?

            Gor

            1 Reply Last reply
            0
            • O Offline
              O Offline
              octal
              wrote on last edited by
              #6

              You should begin by reading "this":http://doc.qt.nokia.com/4.7/sql-driver.html#qmysql

              1 Reply Last reply
              0
              • U Offline
                U Offline
                U7Development
                wrote on last edited by
                #7

                My apologies to get this post alive again...
                Just curious about this line:

                db.setDatabaseName("Driver={MySQL ODBC 5.1 Driver}; DATABASE=localhost;");
                

                What is the string to make connection with MariaDB?
                Thanks

                JonBJ 1 Reply Last reply
                -1
                • U U7Development

                  My apologies to get this post alive again...
                  Just curious about this line:

                  db.setDatabaseName("Driver={MySQL ODBC 5.1 Driver}; DATABASE=localhost;");
                  

                  What is the string to make connection with MariaDB?
                  Thanks

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #8

                  @U7Development Raise a brand new topic if you wish to ask this.

                  1 Reply Last reply
                  2

                  • Login

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