SQLite数据库未打开

时间:2013-03-16 15:10:06

标签: c++ sqlite qt-creator

我有这个问题,当我检查它在这一行打开的数据库时,它给出了真实的

    bool opened = PatternLibrary.open();
    if(opened){

但是当我尝试执行表创建查询时,它无法提供此输出

    QSqlQuery::prepare: database not open

这是我的代码

    PatternLibrary = QSqlDatabase::addDatabase( "QSQLITE" );
    PatternLibrary.setDatabaseName( "./Library.db" );
    bool opened = PatternLibrary.open();
    if(opened)
    {
       qDebug( "Connected!");
       query.prepare( "CREATE TABLE IF NOT EXISTS Pattern (patternName VARCHAR(30),RectangleID   INTEGER ,minWidth INTEGER, minHeight INTEGER, maxWidth INTEGER, maxHeight INTEGER, X Integer, Y INTEGER)" );
       bool create = query.exec();
       if(!create)
       {
           qDebug() <<PatternLibrary.lastError().text();
       }

    }
    else
    {
        qDebug() << PatternLibrary.lastError().text();
        qFatal( "Failed to connect." );
    }

0 个答案:

没有答案