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. Problem when trying to connect to 2 databases
QtWS25 Last Chance

Problem when trying to connect to 2 databases

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 1.5k 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.
  • M Offline
    M Offline
    meepo1
    wrote on 26 May 2017, 23:04 last edited by
    #1

    I have 2 connections ("conexion1" and "conexion2"), however, only "conexion1" works. I get the following message when i run it. Message Box: Driver not loaded Driver not loaded
    qDebug:
    Driver not loaded Driver not loaded
    QSqlQuery::value: unknown field name ''
    QSqlQuery::value: unknown field name ''
    QSqlQuery::value: unknown field name ''
    QSqlQuery::value: unknown field name ''
    QSqlQuery::value: unknown field name ''
    QSqlQuery::value: unknown field name ''

        nDatabase.QSqlDatabase::addDatabase("QMYSQL", "Conexion2");
        nDatabase.setHostName("127.0.0.1");
        nDatabase.setDatabaseName("inventary1");
        nDatabase.setPort(3306);
        nDatabase.setUserName("root");
        nDatabase.open();
        mDatabase = QSqlDatabase::addDatabase("QMYSQL", "Conexion1");
        mDatabase.setHostName("localhost");
        mDatabase.setDatabaseName("Inventary2");
        mDatabase.setPort(3306);
        mDatabase.setUserName("root");
        mDatabase.open();
    
        if(!mDatabase.open()){
            QMessageBox::information(this,"conexion1",mDatabase.lastError().text());
        }else if(!nDatabase.open()){
            QMessageBox::information(this,"conexion2",nDatabase.lastError().text());
            qDebug()<<"error"<<nDatabase.lastError().text();
        }
    
    1 Reply Last reply
    0
    • F Offline
      F Offline
      Fuel
      wrote on 27 May 2017, 02:45 last edited by
      #2

      i dont think that both Connections are working, because the Driver is not loaded. In most cases the used Driver is to old in QT and you use a newer Version of MySQL Server. So you need to compile your own Driver with QT and your MySQL Libs you are using.
      Download the Sources from QT and search for the MySQL Driver Files. At the Moment i dont know where they are, but you need to run the qmake Command in this folder.

      M 1 Reply Last reply 27 May 2017, 21:47
      1
      • X Offline
        X Offline
        xhallix
        wrote on 27 May 2017, 08:21 last edited by
        #3

        as @Fuel said, your connection does not work, because you do not have the correct mysql driver (libs) for your system.
        I had a similar problem on osx -> https://forum.qt.io/topic/79588/use-qmysql-driver-on-without-having-mysql-installed/3

        What os are you actually on?

        Depending on that your libraries will have a different file ending (.dylib, .so, .dll)

        I would to following steps

        1. navigate to your Qt folder into the plugins/sqldriver directory
        2. Now it depends on your OS, check if all dependencies are met.
          osx: use $ otool -L libqsqlmysql.dylib ,
          linux: $ ldd libqsqlmysql.so,
          windows: there is a tool called Depends.exe

        Now you see the dependencies

        libqsqlmysql.dylib (compatibility version 0.0.0, current version 0.0.0)
        	@rpath/QtSql.framework/Versions/5/QtSql (compatibility version 5.8.0, current version 5.8.0)
        	@rpath/QtCore.framework/Versions/5/QtCore (compatibility version 5.8.0, current version 5.8.0)
        	/System/Library/Frameworks/DiskArbitration.framework/Versions/A/DiskArbitration (compatibility version 1.0.0, current version 1.0.0)
        	/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)
        	/opt/local/lib/mysql55/mysql/libmysqlclient.18.dylib (compatibility version 18.0.0, current version 18.0.0)
        	/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
        	/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.1.0)
        	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)
        
        1. Check if libmysqlclient.XX.FILE-ENDING is existing in the named path.
        2. I guess it will be not, so copy the library file from your mysql folder in here, so that QT is able to use the driver by looking up the lib.

        Maybe this saves you some time

        1 Reply Last reply
        3
        • F Fuel
          27 May 2017, 02:45

          i dont think that both Connections are working, because the Driver is not loaded. In most cases the used Driver is to old in QT and you use a newer Version of MySQL Server. So you need to compile your own Driver with QT and your MySQL Libs you are using.
          Download the Sources from QT and search for the MySQL Driver Files. At the Moment i dont know where they are, but you need to run the qmake Command in this folder.

          M Offline
          M Offline
          meepo1
          wrote on 27 May 2017, 21:47 last edited by
          #4

          @Fuel @xhallix Sorry :S How silly of me. I forgot to use equal(=) instead of dot(.) Now i dont get error messages

           nDatabase=QSqlDatabase::addDatabase("QMYSQL", "Conexion2");
          
          1 Reply Last reply
          0

          3/4

          27 May 2017, 08:21

          • Login

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