Connect QT to MySQL database

Source: Internet
Author: User
Today I want to try how to connect to the database with QT. I am depressed when I have finished writing the prompt driver not loaded. My own environment of vs2010 + qt4.8.4 + mysql5.1 was found to be C: \ QT \ 4.8.4 \ plugins \ sqldrivers without MySQL DLL and Lib files. Therefore, you must compile it yourself.

1. Run QT 4.8.4 command prompt command to enter ($ qtdir $) \ SRC \ plugins \ sqldrivers \ mysql

2. Because the absolute path of MySQL has spaces, makefile cannot be accurately found. Create a new MySQL folder (for example, c: \ mysql) in the root directory of any drive letter, and copy the ($ mysqldir $) \ inlcude and ($ mysqldir $) \ Lib folders to this folder.2. Enter the command Qmake-O makefile "includepath + = c: \ mysql \ include""Libs + = c: \ mysql \ Lib \ opt \ libmysql. lib" mysql. Pro Nmake3. Check whether the file is generated in the ($ qtdir $) \ plugins \ sqldrivers folder. Sqlmysql4.dll, qsqlmysql4.lib, qsqlmysqld4.dll, qsqlmysqld4.lib
Qsqldatabase DB = qsqldatabase: adddatabase ("qmysql"); dB. sethostname ("localhost"); dB. setdatabasename ("mydb"); dB. setusername ("root"); dB. setpassword (""); If (! DB. open () qmessagebox: Information (this, TR (""), DB. lasterror (). Text ());

No ..

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.