
4. 访问成功。若访问不堪利,请先实行ping操作看是否能ping通,检讨防火墙等。
Qt访问远程sqlite数据库代码QSqlDatabase db=QSqlDatabase::addDatabase("QSQLITE");db.setDatabaseName("\\\\Win-8241fbm6j4v\\db\\ECSTool.db"); //连接的数据库db.setUserName("h");db.setPassword("123456");if ( !db.open()) {QMessageBox: :warning(0, QObject::tr("Database Error"),db.lastError().text());return;}QSqlQuery query;query.exec("SELECT FROM NmDegLog");while(query.next()) //遍历数据表格mqtt.account每一行,从第0行到末了一行{QString user=query.value(0).toString().trimmed(); //trimmed函数表示去除QString两边的空格QString password=query.value(1).toString().trimmed();qDebug()<<user<<password;}
Qt访问远程sqlite数据库代码实行结果数据库中的信息
代码查询的信息
原文地址 “it宅个人博客: https://itzhai.cn/xuexijiaocheng/799.html”