QT Sqlite ARM 编写程序

前端之家收集整理的这篇文章主要介绍了QT Sqlite ARM 编写程序前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

 
 
  1. #include<QApplication>@H_404_19@
  2. #include<QTextEdit>@H_404_19@
  3. #include<QString>@H_404_19@
  4. #include<qsqldatabase.h>@H_404_19@
  5. #include<QsqlQuery>@H_404_19@
  6. #include<QsqlError>@H_404_19@
  7. #include<QsqlDriver>@H_404_19@
  8. #include<QDateTime>@H_404_19@
  9. #include<QDebug>@H_404_19@
  10. intmain(intargc,char*argv[])
  11. {
  12. QApplicationapp(argc,argv);
  13. QTextEditdisplay;
  14. display.resize(300,160);
  15. display.show();//下面进行数据库设置
  16. //QsqlDatabase*db=QsqlDatabase@H_404_19@::addDatabase("QsqlITE");//使用sqlite数据库驱动
  17. QsqlDatabasedb=QsqlDatabase::addDatabase("QsqlITE"); @H_404_19@
  18. //db.addDatabase("QsqlITE");
  19. db.setDatabaseName("test");//我们之前建立的数据库
  20. boolok=db.open();//尝试连接数据库 @H_404_19@
  21. if(ok)
  22. {//这里用text已经成功连上数据库
  23. QsqlQueryquery;//新建一个查询的实例
  24. if(query.exec("select*fromstudent"))//尝试列出student表的所有记录
  25. {//本次查询成功
  26. intnumRows=0;//询问数据库驱动,是否驱动含有某种特性 @H_404_19@
  27. if(db.driver()->hasFeature(QsqlDriver::QuerySize)) @H_404_19@
  28. {
  29. numRows=query.size();//如果支持结果影响的行数,那么直接记录下来 @H_404_19@
  30. }
  31. else
  32. {
  33. query.last();//否则定位到结果最后,qt文档说,这个方法非常慢
  34. numRows=query.at()+1; @H_404_19@
  35. query.seek(-1);
  36. }
  37. QStringname,age;
  38. display.append("===========================================");
  39. while(query.next())
  40. {//定位结果到下一条记录
  41. name=query.value(0).toString(); @H_404_19@
  42. age=query.value(1).toString(); @H_404_19@
  43. QStringresult=name+""+age; @H_404_19@
  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】@H_404_19@

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

 
 
  1. #include<QApplication>@H_404_19@
  2. #include<QTextEdit>@H_404_19@
  3. #include<QString>@H_404_19@
  4. #include<qsqldatabase.h>@H_404_19@
  5. #include<QsqlQuery>@H_404_19@
  6. #include<QsqlError>@H_404_19@
  7. #include<QsqlDriver>@H_404_19@
  8. #include<QDateTime>@H_404_19@
  9. #include<QDebug>@H_404_19@
  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】@H_404_19@

猜你在找的Sqlite相关文章