Results 1 to 11 of 11

Thread: Factory design pattern issue

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Factory design pattern issue

    hi there. I have a base class "Shape" where I derive other classes like "Circle", "Square" "Rectangle" etc. Now I have a function that takeS one parameter of type "Shape" and then within the function I have to get the name of the class that was passed to the function and I am getting the class name through QMetaObject. This is how I get the class name:
    Qt Code:
    1. QString getClassName(Shape* shapeObj){
    2. const QMetaObject meta = shapeObj->QMetaObject();
    3. return meta->className();
    4. }
    To copy to clipboard, switch view to plain text mode 

    Outside the function I have instantiated two instances of "Shape" in the following manner:

    Qt Code:
    1. Shape* circleObj = new Circle();
    2. Shape* squareObj = new Square();
    To copy to clipboard, switch view to plain text mode 

    After that I pass these objects to my function
    Qt Code:
    1. void getClassName(Shape* shapeObj)
    To copy to clipboard, switch view to plain text mode 
    . This function is suppose to get the class name of a passed object. for exmple: If i pass the object "circleObj" to the function the function must return the class name "Circle" but instead the function always returns the base class name "Shape".

    HOW CAN I FIX THIS?
    Last edited by ayanda83; 26th August 2014 at 16:05.

Similar Threads

  1. Facade design pattern implementation
    By ehnuh in forum General Programming
    Replies: 5
    Last Post: 2nd November 2012, 16:37
  2. QObject factory (singleton pattern)
    By area51 in forum Qt Programming
    Replies: 8
    Last Post: 24th June 2010, 14:55
  3. Design pattern of qwt library
    By Hogwarts in forum Qwt
    Replies: 1
    Last Post: 4th June 2010, 10:04
  4. GIS design pattern
    By olosie in forum Qt Programming
    Replies: 2
    Last Post: 19th May 2009, 16:19
  5. Observer Design Pattern
    By joseph in forum General Programming
    Replies: 1
    Last Post: 21st January 2008, 12:17

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.