In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the method of mysql and qt connection, the article is very detailed, has a certain reference value, interested friends must read it!
The method of connecting mysql and qt: first download and install mysql and qt;, then enter SQL-related instructions in the "cmd.exe" software, then establish the QT program, and finally add "QT + = sql" to the "sql_test.pro" file.
Because Bishu needs to use QT to read the data in the database and save the data to the database. It took a day to finally read the data from the database from QT. There are a lot of relevant information on the Internet, but it is not very complete, and there are some problems in the middle, which are more troublesome to solve. So this article is downloaded and installed from MYSQL, and the QT connection MYSQL is written in as much detail as possible. If there are any deficiencies, please forgive me.
1. Download QT5.5
The windows32 QT5.5 version used in this article is (qt-opensource-windows-x86-mingw492-5.5.10), which can be downloaded from my Baidu Cloud: https://pan.baidu.com/s/1XsVmgd3Qd-J0BHPVOtMVkA
If you choose a high version, the specific installation method can be their own Baidu.
2. Download MYSQL5.6
Because QT chooses the Windows32 bit, MYSQL should also choose the Windows32 bit version as mysql-5.6.39-win32.zip. (if the Windows64 bit is selected by QT, the MYSQL should select the Windows64 bit)
Can be downloaded from my Baidu Cloud: https://pan.baidu.com/s/1XsVmgd3Qd-J0BHPVOtMVkA.
If you choose a high version, the specific download method can be their own Baidu.
3. MYSQL5.6 installation
1) extract the mysql-5.6.39-win32.zip to the MYSQL SERVER in disk D and rename it to mysql-5.6. The result of decompression and modification is shown in figure 1-1.
Figure 1-1
2) modify my-default.ini, as shown in figure 1-2
Figure 1-2
3) increase the environmental variables. Right-click my computer, click Properties, click Advanced system Settings, click environment variables, add in PATH; D:\ MYSQL SERVER\ mysql-5.6\ bin (don't forget the semicolon, rewrite according to your installation directory), click OK.
4) find cmd.exe in disk C and open it with administrator privileges. Execute the following instructions respectively:
D:
Cd MYSQL SERVER\ mysql-5.6\ bin
Mysqld-initalize-user=mysql-console
Mysqld-install, Service successfully installed will be printed after entering this instruction
Net start mysql, which will be printed after entering this directive. The MySQL service has started successfully. At this point, MYSQL5.6 has been successfully installed and running.
4. Log in to MYSQL and change password
1) in the cmd.exe software, continue to enter SQL-related instructions:
Mysql-u root-p, Enter password: appears after entering the command, log in for the first time and enter directly into the mysql software. As shown in figure 1-3
Figure 1-3
2) add the password of root.
Mysql > set password for root@localhost=password ('8888888888')
After entering this instruction, the password of ront is changed to 88888888. (the user name is root and the password is 88888888 when writing QT programs.)
Mysql > exit
Enter the instruction and exit.
Log in again, type mysql-u root-p, enter Enter password: after entering the instruction, enter 88888888. If the password is not 88888888, an error will occur, as shown in figure 1-4
Figure 1-4
3) add test tables, add student tables to the test library, and add some data. The specific operation is shown in figure 1-5, and the MYSQL part has been completed by now. (note that it is added in the test library. Test should be selected for the corresponding QT.
Figure 1-5
5. Establish QT program
1) copy the libmysql.dll and libmysqld.dll in the lib directory of the mysql-5.6 file to the bin file of mingw493_32 in Qt5.5. As shown in figure 1-6
Figure 1-6
2) create a new project and select QT Console Application. Name the project sql_test
Add QT + = sql to the sql_test.pro file
Change main.cpp to
1 # include 2 # include 3 # include 4 # include 5 # include 6 void connect_mysql () 7 {8 QSqlDatabase db=QSqlDatabase::addDatabase ("QMYSQL"); 9 db.setHostName ("127.0.0.1"); / / the hostname of the connection database. Note here (if it is "127.0.0.1" and cannot be connected, change it to localhost) 10 db.setPort (3306) / / connection database port number, consistent with the setting 11 db.setDatabaseName ("test"); / / connection database name, consistent with the setting 12 db.setUserName ("root"); / / database user name, consistent with the setting 13 db.setPassword ("88888888"); / / database password, consistent with the setting 14 db.open () 15 if (! db.open ()) 16 {17 qDebug ()
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.