July 25, 2011

goocreations goocreations
Lab Rat
174 posts

QMYSQL and CMAKE

 

Hi,

I’m trying to compile an application with Qt’s MYSQL driver and cmake. Everything compiles correctly, but when I start the application, I’m getting the following error:

  1. QSqlDatabase: QMYSQL driver not loaded
  2. QSqlDatabase: available drivers: QSQLITE

Since my compilation works, I think it has something to do with the linking. I’m using Ubuntu and have installed the driver via apt-get: libqt4-sql-mysql.

Must I recompile Qt from source to include the driver, or should installing the library like I did work?
I’ve added the the necessary cmake code:

  1. SET(QT_USE_QTSQL TRUE)
  2. FIND_PACKAGE(Qt4 COMPONENTS QtCore QtGui QtSql REQUIRED)
  3. IF(QT_FOUND)
  4.  INCLUDE(${QT_USE_FILE})
  5.  IF(QT_QTSQL_FOUND)
  6.   INCLUDE_DIRECTORIES(${QT_QTSQL_INCLUDE_DIR})
  7.  ELSE(QT_QTSQL_FOUND)
  8.   MESSAGE(FATAL ERROR "Qt SQL libraries missing.")
  9.  ENDIF(QT_QTSQL_FOUND)
  10. ELSE(QT_FOUND)
  11.  MESSAGE(FATAL ERROR "Qt4 not found.")
  12. ENDIF(QT_FOUND)
  13.  
  14. ADD_EXECUTABLE(BCluster
  15.  ${BC_SOURCES}
  16.  ${BC_WRAP_HEADERS}
  17.  ${BC_WRAP_RESOURCES}
  18.  ${BC_WRAP_UI}
  19. )
  20.  
  21. TARGET_LINK_LIBRARIES(BCluster
  22.  ${QT_LIBRARIES}
  23.  ${QT_QTSQL_LIBRARIES}
  24. )

2 replies

July 25, 2011

alexisdm alexisdm
Lab Rat
141 posts

You don’t have to recompile Qt, just the plugin if it comes to that…

Did you install Qt via apt-get too ?

July 25, 2011

goocreations goocreations
Lab Rat
174 posts

Yes, I’ve installed Qt via apt-get too

 
  ‹‹ #include <stddef.h> compiler error      Have some problem with QSQLiteDriver in Ubuntu ››

You must log in to post a reply. Not a member yet? Register here!