Results 1 to 8 of 8

Thread: How to load Mysql driver?

  1. #1
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default How to load Mysql driver?

    I am sorry for posting this question but can someone explain me how can I load the QMYSQL driver into my application?
    Qt Code:
    1. QSqlDatabase db =QSqlDatabase::addDatabase("QMYSQL")
    To copy to clipboard, switch view to plain text mode 
    gives me the following errors:

    Qt Code:
    1. QSqlDatabase: QMYSQL driver not loaded
    2. QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to load Mysql driver?

    Please post a minimal compilable example reproducing the problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: How to load Mysql driver?

    I used a simple structure just to test if it is working with QMainWindow.
    Added menu items on menu, and on "triggered" open the database connection

    Qt Code:
    1. #include "default.h"
    2. #include "ui_default.h"
    3. #include <QtSql/QSql>
    4. #include <QtSql/QSqlDatabase>
    5. #include <QtSql/QSqlDriver>
    6. #include <QtSql/QSqlQuery>
    7. #include <QLayout>
    8.  
    9. default::default(QWidget *parent) :
    10. QMainWindow(parent),
    11. ui(new Ui::default)
    12. {
    13. ui->setupUi(this);
    14. }
    15.  
    16. default::~default()
    17. {
    18. delete ui;
    19. }
    20. void default::on_actionSetari_Baza_de_Date_triggered()
    21. {
    22. QSqlDatabase db =QSqlDatabase::addDatabase("QMYSQL");
    23. db.setHostName("localhost");
    24. db.setDatabaseName("db");
    25. db.setUserName("user");
    26. db.setPassword("password");
    27. db.open();
    28. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to load Mysql driver?

    This is not a compilable example. Please post a minimal compilable example reproducing the problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: How to load Mysql driver?

    I am sorry but what do you want?Project,Header,source files and UI-form?

    untitled.pro file:
    Qt Code:
    1. QT += core gui\
    2. sql
    3.  
    4. greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    5.  
    6. TARGET = untitled
    7. TEMPLATE = app
    8.  
    9.  
    10. SOURCES += main.cpp\
    11. mainwindow.cpp
    12.  
    13. HEADERS += mainwindow.h
    14.  
    15. FORMS += mainwindow.ui
    To copy to clipboard, switch view to plain text mode 

    mainwindow.h
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5.  
    6. namespace Ui {
    7. class MainWindow;
    8. }
    9.  
    10. class MainWindow : public QMainWindow
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. explicit MainWindow(QWidget *parent = 0);
    16. ~MainWindow();
    17.  
    18. private:
    19. Ui::MainWindow *ui;
    20. };
    21.  
    22. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include <QApplication>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. MainWindow w;
    8. w.show();
    9.  
    10. return a.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 

    mainwindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include <QtSql/QSql>
    4. #include <QtSql/QSqlDatabase>
    5.  
    6. MainWindow::MainWindow(QWidget *parent) :
    7. QMainWindow(parent),
    8. ui(new Ui::MainWindow)
    9. {
    10. ui->setupUi(this);
    11. QSqlDatabase db =QSqlDatabase::addDatabase("QMYSQL");
    12. db.setHostName("localhost");
    13. db.setDatabaseName("papadopoulos");
    14. db.setUserName("root");
    15. db.setPassword("");
    16. db.open();
    17. }
    18.  
    19. MainWindow::~MainWindow()
    20. {
    21. delete ui;
    22. }
    To copy to clipboard, switch view to plain text mode 

    form xml version
    Qt Code:
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <ui version="4.0">
    3. <class>MainWindow</class>
    4. <widget class="QMainWindow" name="MainWindow">
    5. <property name="geometry">
    6. <rect>
    7. <x>0</x>
    8. <y>0</y>
    9. <width>400</width>
    10. <height>300</height>
    11. </rect>
    12. </property>
    13. <property name="windowTitle">
    14. <string>MainWindow</string>
    15. </property>
    16. <widget class="QWidget" name="centralWidget"/>
    17. <widget class="QMenuBar" name="menuBar">
    18. <property name="geometry">
    19. <rect>
    20. <x>0</x>
    21. <y>0</y>
    22. <width>400</width>
    23. <height>20</height>
    24. </rect>
    25. </property>
    26. </widget>
    27. <widget class="QToolBar" name="mainToolBar">
    28. <attribute name="toolBarArea">
    29. <enum>TopToolBarArea</enum>
    30. </attribute>
    31. <attribute name="toolBarBreak">
    32. <bool>false</bool>
    33. </attribute>
    34. </widget>
    35. <widget class="QStatusBar" name="statusBar"/>
    36. </widget>
    37. <layoutdefault spacing="6" margin="11"/>
    38. <resources/>
    39. <connections/>
    40. </ui>
    To copy to clipboard, switch view to plain text mode 
    Last edited by adutzu89; 16th December 2013 at 20:22.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to load Mysql driver?

    Are the dependencies of the qmysql driver met? In particular do you have mysqlclient library available where your dynamic linker can find it?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. The following user says thank you to wysota for this useful post:

    adutzu89 (19th December 2013)

  8. #7
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: How to load Mysql driver?

    I have installed Qt 5.2.0 using offline installer,did not build it from source and I have installed mysql client using the software center and mysql server using tasksel.
    I am new to Qt and extremely new in QtSql, so can you be more specific?
    Thank you for taking your time to help.
    Forgot to say that I am on Ubuntu

    Update:
    I found out from this thread that I am missing libmysqlclient_r.so.16.

    I managed to fix it using
    adi@adi-5732Z:/usr/lib$ sudo ln -s x86_64-linux-gnu/libmysqlclient_r.so libmysqlclient_r.so.16
    Last edited by adutzu89; 17th December 2013 at 11:51.

  9. #8
    Join Date
    Oct 2013
    Location
    Bangalore,India
    Posts
    64
    Thanks
    21
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to load Mysql driver?

    I am using Qt 4.8 and faced the same problem.Here is what I did:
    //for development work
    Qt Code:
    1. apt-get install libmysqlclient-dev
    To copy to clipboard, switch view to plain text mode 
    add this to your .pro file
    Qt Code:
    1. INCLUDEPATH += /usr/include/mysql
    To copy to clipboard, switch view to plain text mode 
    finally
    Qt Code:
    1. apt-get install libqt4-sql-mysql
    To copy to clipboard, switch view to plain text mode 

  10. The following user says thank you to prkhr4u for this useful post:

    adutzu89 (23rd December 2013)

Similar Threads

  1. Qt Creator App launched by run option does not load mysql driver
    By l0ud in forum Qt Tools
    Replies: 0
    Last Post: 19th September 2012, 18:48
  2. cannot load mysql driver
    By saman_artorious in forum Qt Programming
    Replies: 1
    Last Post: 9th July 2012, 01:08
  3. source code for odbc driver or MySql driver in arm-embedded-linux
    By sattu in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 24th January 2011, 10:11
  4. I need MySQL driver for Qt 4.6, WindowsXP(32), MySQL 5.1
    By User_3 in forum Installation and Deployment
    Replies: 7
    Last Post: 15th October 2010, 15:19
  5. SQL driver load problem
    By vieraci in forum Qt Programming
    Replies: 1
    Last Post: 12th December 2009, 14:59

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.