QT Operation SQLite Database

Source: Internet
Author: User
Tags sqlite sqlite database

Finally in Qt the operation of SQLite successfully, write a summary of it. In fact, the right time, but to view the database is not desired results. The final discovery of the generated execution file in the Dbug directory, unlike the previously set path, dawned. First, to use the database module, you need to include in the Pro file:
QT + = SQL Second, the required database operations related header files:
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlRecord>
#include <QSqlField> third, connect SQLite
1 voidDbcon ()2 {3 Qsqldatabase db;4db = Qsqldatabase::adddatabase ("Qsqlite");//indicates that the database type is SQLite5Db.setdatabasename ("test.db");//test.db database file opened or created in the directory where the program is located6    if(Db.open ()) {//Open database, loan processing7Qmessagebox::information ( This, TR ("Connect ..."), TR ("database connection Failed!"));8        return;9    }Ten}

Four, the operation of SQLite a case

1 voidInsertData ()2 { 3     //Once the database is open, try to get to the Operation4 qsqlquery query;5     //query.exec ("CREATE table User (name,information);");//If there are no tables in the database, then create one.6Query.exec ("INSERT INTO admin values ('%1 ', '%2 ');"). Arg (name). Arg (pass));7Db.close ();//Close the database8}

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.