标签:
1、目录
2、用ODBC的方式excel文件(xls)从输入数据
QString str; str = QString::fromLocal8Bit("请选择Excel文件"); QString filePath = QFileDialog::getOpenFileName(this,str,"",tr("Exel file(*.xls)"));//excel文件路径读取 //加载数据库驱动 QSqlDatabase db = QSqlDatabase::addDatabase("QODBC","excelexport"); //DSN设置 QString dsn = "DRIVER={Microsoft Excel Driver (*.xls)};" "DSN=‘‘;FIRSTROWHASNAMES=1;READONLY=FALSE;CREATE_DB="; db.setDatabaseName(dsn); //数据库查询 QSqlQuery query(db); qDebug() << QString::fromLocal8Bit("成功开数据库"); QString tableName = "Sheet1$"; //sheet名,$是必须的 QString sql="select * from ["+tableName+"]"; query.exec(sql); //数据的读入 while(query.next()){ QString id = query.value(0).toString(); QString name = query.value(1).toString(); }
db.close();
3、GUI界面的入门设计
private slots: void input(); void output(); void quit();
4、QT内QFile的用法
QString filename = QFileDialog::getSaveFileName(this,str,"savefile.txt",tr("*.txt")); //选择路径 QFile f(filename); str = QString::fromLocal8Bit("导出文件中..."); QTextStream txtOutput(&f); txtOutput << str << "\n";
5、Qt内中文乱码的解决
QString str = QString::fromLocal8Bit("导出文件中...");
标签:
原文地址:http://www.cnblogs.com/ddblog/p/5965073.html