I'm trying to use QSqlDatabase::addDatabase() to access an already-open MySQL connection: http://doc.qt.nokia.com/latest/qsqld...#addDatabase-2

Documentation says to include driver's source file, which I don't want. It requires choosing a single version of Qt and may be acceptable for binary applications, but not for source distribution.

I tried including only the header file (QtSql/qsql_mysql.h) and linking the binary against plugins/sqldrivers/libqsqlmysql.so library (cmake):
Qt Code:
  1. [...]
  2.  
  3. find_library (QT_QSQLMYSQL_LIBRARY qsqlmysql)
  4. if (QT_QSQLMYSQL_LIBRARY)
  5. message (STATUS "Found QMYSQLDriver library: ${QT_QSQLMYSQL_LIBRARY}")
  6. else (QT_QSQLMYSQL_LIBRARY)
  7. message (FATAL_ERROR "Could not find QMYSQLDriver library")
  8. endif (QT_QSQLMYSQL_LIBRARY)
  9.  
  10. target_link_libraries (sql_history ${QT_QTSQL_LIBRARIES} ${MYSQL_LIBRARIES} ${QT_QSQLMYSQL_LIBRARY})
To copy to clipboard, switch view to plain text mode 
but I still get linking error:
Qt Code:
  1. symbol lookup error: /.../libsql_history.so: undefined symbol: _ZN12QMYSQLDriverC1EP8st_mysqlP7QObject
To copy to clipboard, switch view to plain text mode 

Adding
Qt Code:
  1. #include <QtPlugin>
  2. Q_IMPORT_PLUGIN(qsqlmysql)
To copy to clipboard, switch view to plain text mode 
results in another error:
Qt Code:
  1. undefined symbol: _Z28qt_plugin_instance_qsqlmysqlv)
To copy to clipboard, switch view to plain text mode 

Am I doing something wrong? How should this be done?