• qtsqlite


    https://blog.csdn.net/u014252478/article/details/79980899

    #include <QtSql/QSqlDatabase>
    #include <QtSql/QSqlQuery>
    #include <QtSql/QSqlRecord>
    #include <QtSql/qsqlerror.h>
    
    int main(int argc, char *argv[])
    {
        QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");  
     
        QString path =/* QApplication::applicationDirPath() + */"F:\record.db";
        db.setDatabaseName(path);
        bool bOpen = db.open();
        if (!bOpen)
        {
            return 0;
        }
    
        
        QSqlQuery query(db);
        QString sqlStr ="CREATE TABLE [detail] ([ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 
                             [Time] DATETIME NOT NULL, [DevModel] VARCHAR NOT NULL, 
                             [DevSN] VARCHAR,[Result] VARCHAR NOT NULL,[Item] VARCHAR NOT NULL,
                             [Mark] VARCHAR,[ChangeSystem] VARCHAR,[CTMEI] VARCHAR)";
       
        QString selectStr ="select * from detail ";
        bool success = query.exec(selectStr);//"select * from test "
    
        
        QSqlRecord rec = query.record();
        int a = rec.count();
        if(success)
        {
                while(query.next())
                {
                    for(int index = 0; index < 10; index++){
                        QVariant a =(QVariant)query.value(index);
                    }
            
                }
        }else{
            //QString  strErr = query.lastError().text() ;
        }
        query.clear(); //不加释放时内存异常
        db.close();
    
        return 1;
    
        /*
        QApplication a(argc, argv);
        camera_emt w;
        w.show();
        return a.exec();*/
    
    }

    另外 GetSystemDirectory 路径问题

  • 相关阅读:
    Mysql-窗口函数
    aplly-lambda-map用法
    python-pymysql 操作数据库-创建-写入-多线程写入-读取-清空表
    graphviz安装
    sklearn-决策树
    pandas-烹饪指南
    Tomcat配置https
    azkaban 编译部署
    sqoop部署及使用
    spark面试题-1
  • 原文地址:https://www.cnblogs.com/cnchengv/p/13958800.html
Copyright © 2020-2023  润新知