I am sorry for posting this question but can someone explain me how can I load the QMYSQL driver into my application?
gives me the following errors:
Printable View
I am sorry for posting this question but can someone explain me how can I load the QMYSQL driver into my application?
gives me the following errors:
Please post a minimal compilable example reproducing the problem.
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
Code:
#include "default.h" #include "ui_default.h" #include <QtSql/QSql> #include <QtSql/QSqlDatabase> #include <QtSql/QSqlDriver> #include <QtSql/QSqlQuery> #include <QLayout> ui(new Ui::default) { ui->setupUi(this); } default::~default() { delete ui; } void default::on_actionSetari_Baza_de_Date_triggered() { db.setHostName("localhost"); db.setDatabaseName("db"); db.setUserName("user"); db.setPassword("password"); db.open(); }
This is not a compilable example. Please post a minimal compilable example reproducing the problem.
I am sorry but what do you want?Project,Header,source files and UI-form?
untitled.pro file:
Code:
QT += core gui\ sql greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = untitled TEMPLATE = app SOURCES += main.cpp\ mainwindow.cpp HEADERS += mainwindow.h FORMS += mainwindow.ui
mainwindow.h
Code:
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> namespace Ui { class MainWindow; } { Q_OBJECT public: ~MainWindow(); private: Ui::MainWindow *ui; }; #endif // MAINWINDOW_H
main.cpp
Code:
#include "mainwindow.h" #include <QApplication> int main(int argc, char *argv[]) { MainWindow w; w.show(); return a.exec(); }
mainwindow.cpp
Code:
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QtSql/QSql> #include <QtSql/QSqlDatabase> ui(new Ui::MainWindow) { ui->setupUi(this); db.setHostName("localhost"); db.setDatabaseName("papadopoulos"); db.setUserName("root"); db.setPassword(""); db.open(); } MainWindow::~MainWindow() { delete ui; }
form xml version
Code:
<?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>MainWindow</class> <widget class="QMainWindow" name="MainWindow"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>400</width> <height>300</height> </rect> </property> <property name="windowTitle"> <string>MainWindow</string> </property> <widget class="QWidget" name="centralWidget"/> <widget class="QMenuBar" name="menuBar"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>400</width> <height>20</height> </rect> </property> </widget> <widget class="QToolBar" name="mainToolBar"> <attribute name="toolBarArea"> <enum>TopToolBarArea</enum> </attribute> <attribute name="toolBarBreak"> <bool>false</bool> </attribute> </widget> <widget class="QStatusBar" name="statusBar"/> </widget> <layoutdefault spacing="6" margin="11"/> <resources/> <connections/> </ui>
Are the dependencies of the qmysql driver met? In particular do you have mysqlclient library available where your dynamic linker can find it?
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
I am using Qt 4.8 and faced the same problem.Here is what I did:
//for development work
add this to your .pro fileCode:
apt-get install libmysqlclient-dev
finallyCode:
INCLUDEPATH += /usr/include/mysql
Code:
apt-get install libqt4-sql-mysql