宗悠然:Qt开源报表limereport备忘录

开源报表limereport 

1.记住connection对话框里面,database填写 数源的名称,不是数据库的名称

2.注意 databand 别忘了填写写数据源名称 zfg

宗悠然:Qt开源报表limereport备忘录_第1张图片

宗悠然:Qt开源报表limereport备忘录_第2张图片

查看代码看看:

bool DataSourceManager::initAndOpenDB(QSqlDatabase& db, ConnectionDesc& connectionDesc){

    bool connected = false;
    db.setHostName(replaceVariables(connectionDesc.host()));
    db.setUserName(replaceVariables(connectionDesc.userName()));
    db.setPassword(replaceVariables(connectionDesc.password()));

    if (!connectionDesc.keepDBCredentials() && m_dbCredentialsProvider){
        if (!m_dbCredentialsProvider->getUserName(connectionDesc.name()).isEmpty())
            db.setUserName(m_dbCredentialsProvider->getUserName(connectionDesc.name()));
        if (!m_dbCredentialsProvider->getPassword(connectionDesc.name()).isEmpty())
            db.setPassword(m_dbCredentialsProvider->getPassword(connectionDesc.name()));
    }

    QString dbName = replaceVariables(connectionDesc.databaseName());
    if (connectionDesc.driver().compare("QSQLITE")==0){//对于sqlite数据库
        if (!defaultDatabasePath().isEmpty()){
            dbName = !QFileInfo(dbName).exists() ?
                    defaultDatabasePath()+QFileInfo(dbName).fileName() :
                    dbName;
        }
        if (QFileInfo(dbName).exists()){
            db.setDatabaseName(dbName);
        } else {
            setLastError(tr("Database \"%1\" not found").arg(dbName));
            return false;
        }
    } 
      else {
        db.setDatabaseName(dbName);
    }

    connected=db.open();
    if (!connected) setLastError(db.lastError().text());
    return  connected;
}

分析源代码后,发现,直接在database里面写链接字符串:

DRIVER={SQL SERVER};SERVER=192.168.1.42;Uid=sa;Pwd=woaini;DATABASE=Northwind

也是可以的,如下图:

宗悠然:Qt开源报表limereport备忘录_第3张图片

 

你可能感兴趣的:(Qt,数据库,开发工具,C&C++)