Graduation Design qt Connection MySQL

Source: Internet
Author: User

The function that connects the MySQL database bool Loginview::createconnection () {Qsqldatabase t_db = qsqldatabase::adddatabase ("Qmysql");    T_db.sethostname ("localhost");    T_db.setdatabasename ("Chatsystem");    T_db.setusername ("root");    T_db.setpassword ("123456"); if (!t_db.open ()) {//Open failed qmessagebox::critical (0, Qobject::tr ("Database Error"), T_db.lasterror (). Text ()        );    return false; } return true;

When I press CTRL+R, QT Creator reports a lot of big mistakes. I Baidu for a long time to find that Qt itself is not connected to the driver of MySQL, so I faced a "how to use Qt compiled MySQL driver" problem. Later on the internet for a long time, have to say that some of the online technical problems are mostly n years ago. But I found what I wanted (Qt5.1.1 compiling the MySql5.6.17 driver's procedures and considerations).

Don't think the technology is always smooth, QT creator seems to have a joke with me. In fact, that person said Qtbase in the QT installation directory in the SRC file. But I don't know what's going on, altogether even SRC files,

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/5B/F0/wKioL1UXlwODFk3ZAABCdZtJTk8607.jpg "title=" QQ picture 20150329140354.png "alt=" Wkiol1uxlwodfk3zaabcdztjtk8607.jpg "/>

The workaround is to reinstall QT and tick the source components in the selected component you want to install:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/5B/F5/wKiom1UXlpGTStLnAACcAhjmdpU867.jpg "title=" 2015-03-28_183624.jpg "alt=" Wkiom1uxlpgtstlnaaccahjmdpu867.jpg "/>

In this way, the src file also has, I thought this should be OK. But I was compiling the mingw32-make command when there was a big push of the error (said it seems to be a missing file, but the Internet to find a lot of it did not find). At first I always thought it was my step to forget the operation or QT and MySQL did not install well, so I kept unloading and loading and unloading. It took me an afternoon, but it was still a mistake at night and I collapsed!

The next day, I went on the internet to find the "QT compiled MySQL driver" problem, the result is still not found. But the good news is from a netizen's blog to see the qt5.2 later versions are brought with the MySQL driver (my version: qt5.1). I immediately ran to the official web site under a qt5.4 (here I would like to spit out a dog browser download tool, on average only 90kb/s. Hundreds of trillion things, you should be able to guess how long I've been down. The most abominable thing is that when I get down to 90%, I don't move when I 0b/s. Ah!!! It's crashing again! haha but there are also bright spots oh I tentatively in the download bar there clicked the right button, actually appeared "copy". So I immediately sacrificed my artifact-a ray, instantly reached the 600kb/s. Install, and when I run the program, there is a scene that makes me heartache:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/5B/F6/wKiom1UXopbCpwQKAADUDlacDkU678.jpg "title=" 2015-03-28_173553.jpg "alt=" Wkiom1uxopbcpwqkaadudlacdku678.jpg "/>

Meet the problem on Baidu, I follow the internet for a long time did not do well (maybe really I am too stupid!!!) )。 But I found a problem:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/5B/F0/wKioL1UXphfyMVMEAAIywo1ECdE873.jpg "title=" 2015-03-29_150856.jpg "alt=" Wkiol1uxphfymvmeaaiywo1ecde873.jpg "/>

The black box was the one I had before. In fact, there are many versions of QT, the difference between black and Orange is that the compiler is different. Finally, QT's done. Since I had already removed MySQL, I had to reinstall it, so I got a mysql-installer-community-5.6.23.0 from the MySQL website (address: http://dev.mysql.com/downloads /windows/installer/used MySQL 5.5, want to try the latest version). But there are a lot of problems, and this is the first one to come up:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/5B/F6/wKiom1UXp9vRVS_5AACIunN7oV8819.jpg "title=" 2015-03-28_192820.jpg "alt=" Wkiom1uxp9vrvs_5aaciunn7ov8819.jpg "/>

The internet for a long time, still did not find the reason. So I don't care about it, go on next, the next step seems to be downloading some of the MySQL needs to use the package (this is the software check the update and download. Have to say that the process is really a bit long, the main thing is that the download process unexpectedly because the connection server failed and again again, crash!!!!!! )。 Some of the information on the Internet can be checked by checking the skip option without having to check for updates, but mine is not. I don't know if this is the case or this version of MySQL. Regardless of this, continue next, waiting for a long time, although finally there is a call to connect C + + is not installed successfully, but overall is ok (install the above OK). But when I want to open the MySQL and then there is a nasty mistake, I how so miserable Ah!!!! So I directly unloaded MySQL5.6 (this has been engaged for a long time, originally just want to use QT connection MySQL so simple. At this moment you should understand my mood!!!! )。 No way, only to go before the old road, continue to use MySQL5.5 (this time the absolute pro).

Finally MySQL and Qt are all done. Test it:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/5B/F6/wKiom1UXr5LRnRYRAADq8oZWrAo356.jpg "title=" 2015-03-29_000538.jpg "alt=" wkiom1uxr5lrnryraadq8ozwrao356.jpg "/> or something went wrong! haha but it doesn't matter! Because I've been doing this for a long time on the QT compile MySQL driver issue, I can probably see what the problem is. So I copied the D:\MySQL\lib\libmysql.dll to D:\Qt\5.4\mingw491_32\bin.

Test:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/5B/F7/wKiom1UXsc3il-qIAADd7DehCTc134.jpg "title=" 2015-03-29_160334.jpg "alt=" wkiom1uxsc3il-qiaadd7dehctc134.jpg "/> haha!!! Finally succeeded ....   This is the whole process of using QT to connect to MySQL.     





Graduation Design qt Connection MySQL

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.