Qt Code:
  1. ///////////////////////////////////////////////////////// MAIN.CPP
  2.  
  3. PostgresDriver* driver = new PostgresDriver("localhost" , 5432 , "database" , "user" , "user" , "main");
  4.  
  5. QListIterator<QSqlRecord> i( driver->executeQuery( "SELECT * FROM WHATEVER" ) );
  6. while( i.hasNext() ){
  7. }
  8. driver->deleteLater();
To copy to clipboard, switch view to plain text mode 
Works perfectly.

Now:

Qt Code:
  1. ///////////////////////////////////////////////////////// AGENT.H
  2.  
  3. class Agent : public QObject
  4. {
  5. Q_OBJECT
  6. public:
  7. Agent(QString class_name = "Agent");
  8. ~Agent();
  9.  
  10. // GETTERS
  11. unsigned int getId();
  12. QString getClass();
  13.  
  14. slots:
  15. virtual void start();
  16. virtual void end(){this->deleteLater();}
  17.  
  18. private:
  19.  
  20. // INCREMENTAL FOR IDS
  21. static unsigned int counter;
  22.  
  23. unsigned int id;
  24. QString class_name;
  25. };
  26.  
  27. ///////////////////////////////////////////////////////// AGENT.CPP
  28.  
  29. #include "Agent.h"
  30.  
  31. unsigned int Agent::counter = 0;
  32.  
  33. Agent::Agent(QString class_name) : QObject()
  34. {
  35. this->id = ++Agent::counter;
  36. this->class_name = class_name;
  37. this->setObjectName( QString("%1%2").arg( this->getClass() ).arg( this->getId() ) );
  38. }
  39.  
  40. Agent::~Agent() {
  41. this->thread()->deleteLater();
  42. }
  43.  
  44. unsigned int Agent::getId(){
  45. return this->id;
  46. }
  47.  
  48. QString Agent::getClass(){
  49. return this->class_name;
  50. }
  51.  
  52. void Agent::start(){
  53. PostgresDriver* db = new PostgresDriver("localhost" , 5432 , "database" , "user" , "user" , this->objectName() ); //CRASHES
  54. }
  55.  
  56. ///////////////////////////////////////////////////////// MAIN.CPP
  57.  
  58. Agent* agent = new Agent("Car");
  59. QThread *thread = new QThread( );
  60. agent->moveToThread( thread );
  61. agent->connect( thread, SIGNAL( started() ), agent, SLOT( start() ) );
  62. thread->start();
To copy to clipboard, switch view to plain text mode 
Crashes when creating a PostgresDriver inside the Agent.