Hi all, Have a nice day.

I am new to the forum and is my first post, I reviewed most of this forum and the web and not get anything definitive to help me understand the problem I am waiting here can help me as I often they have done in other post for other people.

I am trying to apply the abstract factory pattern to create a series of modules that require to an application I'm developing.

I have taken an example from the book An Introduction to Design Patterns in C ++ With Qt (Prentice Hall-2011-2nd Edition) page 483, paragraph 16.1.1 Abstract Factory
Chapter 16, as well as, I read on the website of some other examples and
I have the following code to do what I need.

Qt Code:
  1. typedef QHash<QString, QMetaObject> T_Modules;
  2.  
  3. T_Modules modulesTypesList () {
  4.  
  5. T_Modules hash;
  6.  
  7. hash [ "LibraryGui" ] = LibraryGui::staticMetaObject;
  8. hash [ "ConvertGui" ] = ConvertGui::staticMetaObject;
  9. hash [ "BurnGui" ] = BurnGui::staticMetaObject;
  10. hash [ "PlaylistGui" ] = PlaylistGui::staticMetaObject;
  11. hash [ "PlayingGui" ] = PlayingGui::staticMetaObject;
  12.  
  13. return hash;
  14. }
  15.  
  16. Module *ModulesFactory::createModule ( QString className, QWidget *parent ) {
  17.  
  18. T_Modules modulesType = modulesTypesList ();
  19.  
  20. Module *moduleCreated = 0;
  21.  
  22. if ( modulesType.contains ( className ) ) {
  23.  
  24. const QMetaObject& metaObjectClass = modulesType [ className ];
  25. moduleCreated = qobject_cast<Module *> ( metaObjectClass.newInstance () );
  26.  
  27. if ( moduleCreated == 0 ) {
  28.  
  29. qDebug () << "Error creating " << className;
  30. abort ();
  31.  
  32. } else if ( parent != 0 ) {
  33.  
  34. moduleCreated->setParent ( parent );
  35. }
  36. } else {
  37.  
  38. qDebug () << "Error creating " << className;
  39. abort ();
  40. }
  41. return moduleCreated;
  42. }
To copy to clipboard, switch view to plain text mode 

In theory everything is fine (compiles complete), but when running, it generates the
following error:

Qt Code:
  1. Starting /home/remizero/Proyectos/Qt/rockola/build-rockola-Desktop-Debug/rockola...
  2. Error creating "LibraryGui"
  3. The program has unexpectedly finished.
  4. /home/remizero/Proyectos/Qt/rockola/build-rockola-Desktop-Debug/rockola crashed
To copy to clipboard, switch view to plain text mode 

Of course, not a bug properly, the detail is that I did not create the object (send to abort to avoid having to close the application and to debug faster; p)

My question is, What am I doing wrong trying to create object of type Module? on line 25

Qt Code:
  1. moduleCreated = qobject_cast<Module *> ( metaObjectClass.newInstance () );
To copy to clipboard, switch view to plain text mode 

I'm working with QtCreator 3.2.1, Qt 5.3.2, gcc 4.9.1 32bit

If you need a compilable example, I'll have to pass on the project with a minimum of 20 files and tell the file in question to go directly.

Sorry for my bad English.

Thanks in advance.