3

当我检查它在这一行中打开的数据库时,我遇到了这个问题,它给出了 true

    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." );
    }
4

0 回答 0