Qt Learning (5) connect SQLite

Source: Internet
Author: User

SQLite, as long as you have used a database, you should not be afraid of it. It is enough to think of it as a simple database, but it only supports limited data. Next, let me talk about how to use it. My environment is vs2008 + QT.

 

Like most people, I first need to Google the Code. The Code is as follows:

# Include <qtgui/qapplication> <br/> // # include <qapplication> <br/> # include <qsqldatabase> <br/> # include <qtsql> <br/> # include <qsqlitedriver> <br/> int main (INT argc, char * argv []) <br/>{< br/> qapplication app (argc, argv); </P> <p> qsqldatabase DB = qsqldatabase :: adddatabase ("qsqlite"); <br/> dB. setdatabasename ("test. DB "); <br/> // test. DB is a database file created through the SQLite Program, under the current folder <br/> If (! DB. open () <br/>{< br/> return 0; <br/>}< br/> return app.exe C (); <br/>}< br/>

Run the command to view the result:

Qsqldatabase: qsqlite driver not loaded
Qsqldatabase: available drivers:

 

 

At this step, we are depressed .....

The solution is as follows:
Step 1: Add qsqlite. lib to the link of the project.

The method is: select your project> Properties> Configuration Properties> linker> input> additional dependency> Add qsqlite. Lib.

Step 2: Modify the adddatabase method.

To:

Qsqldatabase DB = qsqldatabase: adddatabase (New qsqlitedriver (), "qsqlite ");
Re-compile, O, hey. Of course, you can also add q_import_plugin (qsqlite) directly above the main function without modifying the content here)

OK. This is the end !!!!

 

 

I planned to end it here, but some of my siblings won't be SQLite. So I re-wrote how to use sqlite3

First, download a sqlite3.exe file. Go to csdn and search for it.

Second, use the authorization command to go to your sqlite3.exe directory.

Step 3: Type sqlite3.exe test. DB

The fourth step is to enter the; this semicolon will show that you have the file test. DB in your current project. This is the database file we want.

Of course, you can also directly create a table create table (age int Nam varchar (10 ));

O, this is the whole process of table creation !!!!

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.