Hi, I'm making multiples queries to a database by just pressing a QPushButton and reading the query from a QLineEdit. I need to show that queries in a QTabWidget that has multiples QTableViews each one in a different tab. I created a QThread, an in the run() a send a signal with one dynamic model to the QDialog where I have the QTabWidget. Here's the code:

Qt Code:
  1. class GeneralSearchThread : public QThread
  2. {
  3. Q_OBJECT
  4. public:
  5. explicit GeneralSearchThread( QObject *parent = 0 );
  6. ~GeneralSearchThread();
  7. void makeQuery( const QString &query );
  8.  
  9. signals:
  10. void modelReadytoRead( QSqlQueryModel *model ); //this signal will be connected to the QDialog.
  11.  
  12. public slots:
  13.  
  14. protected:
  15. void run();
  16.  
  17. private:
  18. QString nameUser;
  19. QString passUser;
  20. QString queryString;
  21.  
  22. QList< QSqlQueryModel *> listaModels;
  23. };
  24.  
  25. GeneralSearchThread::GeneralSearchThread( QObject *parent ) : QThread( parent )
  26. {
  27. }
  28.  
  29. GeneralSearchThread::~GeneralSearchThread()
  30. {
  31. wait();
  32.  
  33. qDeleteAll(listaModels); /// I get the problem here!!!
  34. listaModels.clear(); /// I get the problem here!!!
  35. }
  36.  
  37. void GeneralSearchThread::makeQuery( const QString &query )
  38. {
  39. queryString = query;
  40. start();
  41. }
  42.  
  43. void GeneralSearchThread::run()
  44. {
  45. QSqlDatabase db = QSqlDatabase::database( "someName" );
  46. if( db.open() )
  47. {
  48. model->setQuery( queryString, db );
  49. listaModels.append( model );
  50. emit modelReadytoRead( model );
  51. db.close();
  52. }
  53. }
To copy to clipboard, switch view to plain text mode 

The question here, is that I'm creating the QSqlQueryModels dynamically and trying to store them in a QList (which I call listaModels) and delete it in the destructor of the QThread. But I get a problem of Segmentation fault . But when I put away the lines inside the destructor I get no problems, but I'm afraid of a memory leak. Does anyone know how to solve this problem?, the QSqlQueryModels get deleted when the driver is closed and I'm re-deleting them?. Thanks a lot in advanced.
Extra Info: Driver: QMYSQL3, OS: Ubuntu 9.04, gcc version 4.4.1, Qt version 4.6.