Hello!

I've got my simple application, but it causes memory leak. I think one of this three functions is a problem:

Qt Code:
  1. bool MainWindow::pobierzKomunikaty()
  2. {
  3. bool ok;
  4. QTextStream out(stdout);
  5. QString zapytanie;
  6. QSqlQueryModel queryModel;
  7.  
  8. QFont font;
  9. font.setPointSize(7);
  10.  
  11. odczytanoOstatnieKomunikaty=0;
  12.  
  13. ok = bdb.open();
  14.  
  15. if (ok)
  16. {
  17. out << endl << "Otworzylem baze!" << endl ;
  18. } else {
  19. out << "Nie udalo sie otworzyc bazy!" << endl;
  20. }
  21.  
  22. queryModel.setQuery("SELECT * FROM server_notifications WHERE complete='0'", bdb); //LIMIT 1
  23.  
  24. liczbaWiadomosci = queryModel.rowCount();
  25.  
  26. bdb.close();
  27.  
  28. out << "Mamy: " << liczbaWiadomosci << " wiadomosci!" << endl;
  29.  
  30.  
  31. for(int i=0 ; i<liczbaWiadomosci; i++)
  32. {
  33. rec = queryModel.record(i);
  34.  
  35.  
  36. out << rec.value(1).toString() << ": ";
  37. out << rec.value(2).toString() << endl;
  38.  
  39. QMessageBox *msgBox=new QMessageBox;
  40.  
  41. if(rec.value(1).toString()=="warning") msgBox->setIcon(QMessageBox::Warning);
  42. else if (rec.value(1).toString()=="info") msgBox->setIcon(QMessageBox::Information);
  43. else if (rec.value(1).toString()=="error") msgBox->setIcon(QMessageBox::Critical);
  44.  
  45. msgBox->setFont(font);
  46.  
  47. msgBox->setWindowTitle(rec.value(1).toString());
  48. msgBox->setText(rec.value(2).toString());
  49.  
  50. QSpacerItem* horizontalSpacer = new QSpacerItem(240, 290, QSizePolicy::Minimum, QSizePolicy::Minimum);
  51. QGridLayout* layout = (QGridLayout*)msgBox->layout();
  52. layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount());
  53.  
  54. msgBox->move(0,0);
  55. msgBox->exec();
  56.  
  57. delete msgBox;
  58.  
  59. ok = bdb.open();
  60.  
  61. zapytanie.clear();
  62. zapytanie="update server_notifications set complete='1'";
  63. zapytanie.append(" where id='");
  64. zapytanie.append(QString::number(rec.value(0).toInt()));
  65. zapytanie.append("'");
  66.  
  67. QSqlQuery *query=new QSqlQuery;
  68.  
  69. query->clear();
  70. query->prepare(zapytanie);
  71. ok = query->exec();
  72.  
  73. bdb.close();
  74.  
  75. delete query;
  76. }
  77.  
  78. odczytanoOstatnieKomunikaty=1;
  79.  
  80. return ok;
  81. }
  82.  
  83. bool MainWindow::wyswietlKomunikaty()
  84. {
  85. if(odczytanoOstatnieKomunikaty==0)
  86. {
  87.  
  88. } else
  89. {
  90. pobierzKomunikaty();
  91. odczytajNotificationInterval();
  92. timer->start(notificationInterval);
  93. }
  94.  
  95. return 1;
  96. }
  97.  
  98. bool MainWindow::odczytajNotificationInterval()
  99. {
  100. bool ok;
  101. QTextStream out(stdout);
  102. QSqlQueryModel queryModel;
  103.  
  104. ok = bdb.open();
  105.  
  106. if (ok)
  107. {
  108. out << endl << "Otworzylem baze!" << endl ;
  109. } else {
  110. out << "Nie udalo sie otworzyc bazy!" << endl;
  111. }
  112.  
  113. queryModel.setQuery("SELECT * FROM config WHERE name='qt-notification-interval'", bdb);
  114.  
  115. rec = queryModel.record(0);
  116. notificationInterval = (rec.value(1).toInt())*1000;
  117.  
  118. out << "Notification interval: " << notificationInterval << " ms" << endl;
  119.  
  120. bdb.close();
  121.  
  122. return ok;
  123. }
To copy to clipboard, switch view to plain text mode 

Maybe someone can tell me where?

thanks in advance
best regards
Tomasz