{
QSqlDatabase db_sqlite = QSqlDatabase::addDatabase("QSQLITE",file_target);
db_sqlite.setDatabaseName(file_target);
if (!db_sqlite.open()) {
qDebug()<<"open database error!";
}else{
QSqlQuery query(db_sqlite);
query.exec("drop table if exists test0;");
QString attach = "attach database '" + file_source + "' as db_source;";
query.exec(attach);
query.exec("create table test0 as select * from db_source.test0;");
}
}
QSqlDatabase::removeDatabase(path_project);
!!!注意file_source需要用引号引起来,不然没法识别
https://blog.csdn.net/mad2man/article/details/38144235