Archive for the ‘qt’ tag
How to enable MySQL support in Qt SDK for Windows
- Download Qt SDK for Windows at Qt Software and install.
- Download MySQL Community Server (MSI Installer) from MySQL and install. Make sure you’ve included C header and necessary lib files during the installation (use Custom Install)

- Open Qt Command Prompt from the Start Menu

- Run these commands, modify it if you install your MySQL at different path. You just have to set the path to your MySQL library since Qt’s paths will be set automatically based on your installation if you use Qt Command Prompt:
Setting up a MinGW/Qt only environment...
-- QTDIR set to C:\Qt\2010.02.1\qt
-- PATH set to C:\Qt\2010.02.1\qt\bin
-- Adding C:\Qt\2010.02.1\bin to PATH
-- Adding C:\WINDOWS\System32 to PATH
-- QMAKESPEC set to win32-g++
C:\Qt\2010.02.1\qt>set mySQLDIR=C:\PROGRA~1\MySQL\MYSQLS~1.1
C:\Qt\2010.02.1\qt>cd %QTDIR%\src\plugins\sqldrivers\mysql
C:\Qt\2010.02.1\qt\src\plugins\sqldrivers\mysql>qmake "INCLUDEPATH+=%mySQLDIR%\include" "LIBS+=%mySQLDIR%\lib\opt\libmysql.lib" -o Makefile mysql.pro
C:\Qt\2010.02.1\qt\src\plugins\sqldrivers\mysql>mingw32-make - Create new project and put these codes to test your new plugin
1
2
3
4
5
6
7
8
9
10
11#include <QCoreApplication>
#include <QtSql>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
qDebug() << QSqlDatabase::drivers();
return a.exec();
}Make sure you have QtSql Module in your project configuration file (.pro file)
QT += sqlYou’ll get these outputs showing that your Qt has supports for MySQL:
("QSQLITE", "QMYSQL3", "QMYSQL", "QODBC3", "QODBC")What matters is that you have QMYSQL in the output.
Fixing Blank Help in Qt Creator
I just upgraded my SDK to Qt SDK 4.6.2 and installed Qt Creator 1.3.1. After running both editors (from the SDK and the one that I installed separately), I noticed that I’m getting blank pages in my help. I can’t search for any documentation. However, I can open the help file manually from the terminal (won’t work if your Qt is not in the PATH).
amree@pikopong:~$ assistant
Anyway, to solve it, we just need to point the the correct help file.
- Open your Qt Creator.
- Go to Tools > Options…
- Open the Documentation section.

- Clear everything you have in the list of Registered Documentation.
- Now, we must add all the help files back. The help files should be ending with .qch as the extension. Click Add… and browse to the directory where the help files are located.
/* ----------------------------------------------------
* LINUX
*
* Assuming your main SDK installation directory
* is at '/opt/qt/qtsdk-2010.02'
* ----------------------------------------------------/
/opt/qt/qtsdk-2010.02/qt/doc/qch/assistant.qch
/opt/qt/qtsdk-2010.02/qt/doc/qch/designer.qch
/opt/qt/qtsdk-2010.02/qt/doc/qch/linguist.qch
/opt/qt/qtsdk-2010.02/qt/doc/qch/qmake.qch
/opt/qt/qtsdk-2010.02/qt/doc/qch/qt.qch
// If you're going to use the editor from the SDK, add this one too
/opt/qt/qtsdk-2010.02/share/doc/qtcreator/qtcreator.qch/* ----------------------------------------------------
* WINDOWS
*
* Assuming your main SDK installation directory
* is at 'C:\Qt\2010.02.1'
* ----------------------------------------------------/
C:\Qt\2010.02.1\qt\doc\qch\assistant.qch
C:\Qt\2010.02.1\qt\doc\qch\designer.qch
C:\Qt\2010.02.1\qt\doc\qch\linguist.qch
C:\Qt\2010.02.1\qt\doc\qch\qmake.qch
C:\Qt\2010.02.1\qt\doc\qch\qt.qch
// If you're going to use the editor from the SDK, add this one too
C:\Qt\2010.02.1\share\doc\qtcreator\qtcreator.qch/*
* If your are using different editor (other than the one from SDK),
* make sure you add the help file for the editor too.
* The path for Linux and Windows should be the same
*/
%QTCREATOR_INSTALLATION_PATH%/share/doc/qtcreator/qtcreator.qch - Maybe there’ll be more files, just add every help files in the directory. Click OK and you’ll get your help files back. Good luck !
How to enable MySQL support in Qt SDK for Linux
- Download Qt SDK for Linux/X11 at Qt Software.
- Install it anywhere you want, just make sure you remember the path.
- To build MySQL as a plugin, you need to know two other paths:
- Your MySQL header files directory. It should be something like this:
decimal.h m_string.h my_dbug.h my_list.h my_sys.h mysql_embed.h mysqld_error.h sql_state.h typelib.h
errmsg.h my_alloc.h my_dir.h my_net.h my_xml.h mysql_time.h raid.h sslopt-case.h
keycache.h my_attribute.h my_getopt.h my_no_pthread.h mysql.h mysql_version.h readline.h sslopt-longopts.h
m_ctype.h my_config.h my_global.h my_pthread.h mysql_com.h mysqld_ername.h sql_common.h sslopt-vars.h - Your MySQL lib files directory. Something like this:
libdbug.a libmyisammrg.a libmysqlclient.so@ libmysqlclient_r.a libmysqlclient_r.so.15@ libmysys.a
libheap.a libmysqlclient.a libmysqlclient.so.15@ libmysqlclient_r.la* libmysqlclient_r.so.15.0.0* libvio.a
libmyisam.a libmysqlclient.la* libmysqlclient.so.15.0.0* libmysqlclient_r.so@ libmystrings.a
- Your MySQL header files directory. It should be something like this:
- For Slackware 12.2, it should be:
1
2/usr/include/mysql # MySQL header directory
/usr/lib/mysql # MySQL libraries - Go to your Qt SDK installation directory, mine is: /opt/qtsdk-2009.03/
1
2
3
4
5
6cd /opt/qtsdk-2009.03/
cd qt/src/plugins/sqldrivers/mysql/
# Replace all the path based on your computer environment.
# Make sure 'qmake' can be run from anywhere or you'd have to specify the full path for it.
qmake -o Makefile "INCLUDEPATH+=/usr/include/mysql" "LIBS+=-L/usr/lib/mysql -lmysqlclient" mysql.pro
make - You should have new files created for you:
Makefile
README
libqsqlmysql.so*
main.cpp
main.o
moc_qsql_mysql.cpp
moc_qsql_mysql.o
mysql.pro
qsql_mysql.moc
qsql_mysql.o - Copy MySQL plugin to your Qt’s plugins directory,
cp libqsqlmysql.so /opt/qtsdk-2009.03/qt/plugins/sqldrivers
- Create new project and put these codes to test your new plugin
1
2
3
4
5
6
7
8
9
10
11#include <QCoreApplication>
#include <QtSql>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
qDebug() << QSqlDatabase::drivers();
return a.exec();
}You’ll get these outputs showing that your Qt has supports for MySQL
("QSQLITE", "QMYSQL3", "QMYSQL")

