加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

QT Sqlite ARM 编写程序

发布时间:2020-12-12 20:42:08 所属栏目:百科 来源:网络整理
导读:QT Sql ite ARM 编写 程序 是本文要介绍的内容,主要是代码,先来看内容。 #include QApplication #include QTextEdit #include QString #include qsqldatabase.h #include QSqlQuery #include QSqlError #include QSqlDriver #include QDateTime #include Q

QT Sqlite ARM 编写程序是本文要介绍的内容,主要是代码,先来看内容。

 
 
  1. #include<QApplication>
  2. #include<QTextEdit>
  3. #include<QString>
  4. #include<qsqldatabase.h>
  5. #include<QSqlQuery>
  6. #include<QSqlError>
  7. #include<QSqlDriver>
  8. #include<QDateTime>
  9. #include<QDebug>
  10. intmain(intargc,char*argv[])
  11. {
  12. QApplicationapp(argc,argv);
  13. QTextEditdisplay;
  14. display.resize(300,160);
  15. display.show();//下面进行数据库设置
  16. //QSqlDatabase*db=QSqlDatabase::addDatabase("QSQLITE");//使用sqlite数据库驱动
  17. QSqlDatabasedb=QSqlDatabase::addDatabase("QSQLITE");
  18. //db.addDatabase("QSQLITE");
  19. db.setDatabaseName("test");//我们之前建立的数据库
  20. boolok=db.open();//尝试连接数据库
  21. if(ok)
  22. {//这里用text已经成功连上数据库
  23. QSqlQueryquery;//新建一个查询的实例
  24. if(query.exec("select*fromstudent"))//尝试列出student表的所有记录
  25. {//本次查询成功
  26. intnumRows=0;//询问数据库驱动,是否驱动含有某种特性
  27. if(db.driver()->hasFeature(QSqlDriver::QuerySize))
  28. {
  29. numRows=query.size();//如果支持结果影响的行数,那么直接记录下来
  30. }
  31. else
  32. {
  33. query.last();//否则定位到结果最后,qt文档说,这个方法非常慢
  34. numRows=query.at()+1;
  35. query.seek(-1);
  36. }
  37. QStringname,age;
  38. display.append("===========================================");
  39. while(query.next())
  40. {//定位结果到下一条记录
  41. name=query.value(0).toString();
  42. age=query.value(1).toString();
  43. QStringresult=name+""+age;
  44. display.append(result);
  45. }
  46. display.append("===========================================");
  47. display.append(QString("totally%1rows").arg(numRows));
  48. }
  49. else
  50. {//打开数据库失败,显示数据库返回的失败描述
  51. display.append("cannotopendatabase.");
  52. display.append("Reason:"+db.lastError().databaseText());
  53. }
  54. QApplication::connect(&app,SIGNAL(lastWindowClose()),&app,SLOT(quit()));
  55. returnapp.exec();
  56. }

编译出错:

 
 
  1. undefinedreferenceto`QSqlDatabase::defaultConnection’

解决办法:

第一种办法:

 
 
  1. .pro里面加一句
  2. QT+=sql

第二种办法:

 
 
  1. INCLUDEPATH+=/usr/local/Trolltech/QtEmbedded-4.6.3/include/QtSql
  2. LIBS+=-lQtSql

小结:关于详解QT Sqlite ARM 编写程序实例的内容介绍完了,希望本文对你会有所帮助!

【内容整理:蚂蚁爬 URL:www.z8soft.com】

QT Sqlite ARM 编写程序是本文要介绍的内容,主要是代码,先来看内容。

 
 
  1. #include<QApplication>
  2. #include<QTextEdit>
  3. #include<QString>
  4. #include<qsqldatabase.h>
  5. #include<QSqlQuery>
  6. #include<QSqlError>
  7. #include<QSqlDriver>
  8. #include<QDateTime>
  9. #include<QDebug>
  10. intmain(intargc,SLOT(quit()));
  11. returnapp.exec();
  12. }

编译出错:

 
 
  1. undefinedreferenceto`QSqlDatabase::defaultConnection’

解决办法:

第一种办法:

 
 
  1. .pro里面加一句
  2. QT+=sql

第二种办法:

 
 
  1. INCLUDEPATH+=/usr/local/Trolltech/QtEmbedded-4.6.3/include/QtSql
  2. LIBS+=-lQtSql

小结:关于详解QT Sqlite ARM 编写程序实例的内容介绍完了,希望本文对你会有所帮助!

【内容整理:蚂蚁爬 URL:www.z8soft.com】

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读