homestead.h
Qt Code:
  1. #ifndef HOMESTEAD_H
  2. #define HOMESTEAD_H
  3. #include <QMainWindow>
  4. class homestead : public QMainWindow
  5. .....
  6. {
  7. Q_OBJECT
  8.  
  9. public:
  10. homestead(QWidget *parent = 0);
  11. ....
  12. QSqlQuery persQry;
  13. ....
  14. ...
  15. }
To copy to clipboard, switch view to plain text mode 
and
homestead.cpp
Qt Code:
  1. /*
  2. Program: homestead.cpp
  3. */
  4. #include "homestead.h"
  5. #include "wholenamedlg.h"
  6. #include "historydialog.h"
  7. ...
  8.  
  9. homestead::homestead(QWidget *parent) : QMainWindow(parent) {
  10. ui.setupUi(this); // draw the gui interface
  11. ...
  12. // create global query objects
  13. QSqlQuery persQry;
  14. ...
  15. }
  16. void homestead::searchAll() {
  17. .....
  18. QString queryStr = "";
  19. ...
  20. if (ui.rbProprtyID->isChecked()) {
  21. // user is searching for property id
  22. requestString.append(" in Property");
  23. ui.leStatus->setText(requestString);
  24. queryStr = this->propPIDqryStr; // default property id select
  25. queryStr.append(ui.leSearch->text()); // append property id
  26. propQry.clear();
  27. propQry.exec(queryStr);
  28. if (propQry.first()){
  29. // found property record, now fetch associated persinfo record
  30. foundProp = true;
  31. queryStr = this->persPIDqryStr;
  32. queryStr.append(ui.leSearch->text());
  33. persQry.clear();
  34. persQry.exec(queryStr);
  35. if (persQry.first()) {
  36. foundPers = true;
  37. }
  38. ...
  39. }
  40. ...
To copy to clipboard, switch view to plain text mode 
and main.cpp
Qt Code:
  1. .....
  2. int main( int argc, char * argv[] ) {
  3. QString strRejected = "";
  4. QApplication app(argc, argv);
  5. app.setQuitOnLastWindowClosed(false);
  6. dlgLogin dlg;
  7. if( dlg.exec() == QDialog::Accepted ){
  8. QSqlDatabase hapdb = QSqlDatabase::addDatabase(DBDRIVER);
  9. hapdb.setHostName(DBHOST);
  10. hapdb.setDatabaseName(DBNAME);
  11. hapdb.setUserName(dlg.dui.leUserName->text());
  12. hapdb.setPassword(dlg.dui.leUserPassword->text());
  13. if ( hapdb.open() ) {
  14. homestead ht;
  15. ht.RevID = dlg.dui.leUserName->text();
  16. ht.show();
  17. app.setQuitOnLastWindowClosed(true);
  18. return app.exec();
  19. } else {
  20. strRejected = QString("The Login was rejected because: %1").arg(hapdb.lastError().text()).toLatin1();
  21. QMessageBox::information(0,"Login Rejected!",strRejected,
  22. QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
  23. return 1;
  24. }
  25. } else {
  26. strRejected = QString("User Canceled the login!").toLatin1();
  27. QMessageBox::information(0,"Login Rejected!",strRejected,
  28. QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
  29. return 2;
  30. }
  31. }
To copy to clipboard, switch view to plain text mode 

A cursor is created each time "persQry.exec(queryStr): is executed but it is not released by persQry.clear*() the next time the searchAll function is called.
The Oracle cursor count continues to increase until MAX_OPEN_CURSOR is reached.