1. Requirements
Originally saved data using SQLite memory database, and then need to save configuration information and so on to the database, the program is configured to turn off open to be able to display the normal display saved configuration information
2. Resolve
1. Write the configuration information to the normal configuration file (INI, etc.), the first version of this implementation, the disadvantage of reading and writing files is a bit slow
2. The program uses two kinds of database, the memory database and the file database, the sensitive information is stored in the memory database, and the user configuration information is stored in the file database for long-term preservation.
3. Section code 1. Creating a Memory Database
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE""memory");db.setDatabaseName(":memory:");if (!db.open()) { LOG_ALL_ERROR(QStringLiteral("failed open sqlite.")); return bret;}
2. Create a file database
QString strdbpath("""/db"dir("");dir"/mysqlite.db";QSqlDatabase dbset = QSqlDatabase::addDatabase("QSQLITE""file");dbset.setDatabaseName(strdbpath);if (!dbset.open()) { LOG_ALL_ERROR(QStringLiteral("failed open mysqlite.db")); return bret;}
3. Using the In-memory database
Qsqlquery query (qsqldatabase::d atabase ("Memory", true); bret = Query.exec ("Create TableBacklist (No varchar( -)," "Namevarchar( $), Colorvarchar( -)," "size varchar( -), RetailDouble," "DiscountDouble, UnitDouble," "Attridvarchar( -), Salenumint," "Backmaxint, Backnumint, TotalpriceDouble," "Serialvarchar( -), OrderIDvarchar( -)," "Date varchar( -))");
4. Working with the file database
Qsqlquery setquery (qsqldatabase::d atabase ("file", true); bret = Setquery.exec ("Create TablePrintset (BtitleINTEGER, BshopINTEGER, BbarcodeINTEGER," "BsellidINTEGER, BcashdeskINTEGER, BcashierINTEGER," "BdateINTEGER, BmemidINTEGER, BscoreINTEGER," "BpayableINTEGER, BprivilegeINTEGER, BtotalINTEGER," "BgoodnameINTEGER, BgoodcountINTEGER, BunitINTEGER," "BsumINTEGER, BdiscountINTEGER, BpriceINTEGER," "BcashINTEGER, BbankINTEGER, bchangeINTEGER," "BtelINTEGER, BendINTEGER)");
4. Reference
1.http://blog.csdn.net/abeldeng/article/details/24767245 This article describes the creation of not saying use
2.QT Assistant
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Enabling multiple databases to be opened with QT