Results 1 to 5 of 5

Thread: A simple basic fundamental doubt !

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default A simple basic fundamental doubt !

    Hi,

    I was just trying to understand the concept behind qobject_cast and have landed in to some dilemma . I would be more than happy if some one could tell me the difference between the two representation of the same logic. I am here by trying to expand the q_object macro to see how it is using the meta object for dynamic identification of the object type.

    Preconditions
    ----------------
    I have a QObject subclass,

    Qt Code:
    1. class QMyTestClass : public QObject
    2. {
    3. Q_OBJECT
    4. public:
    5. QMyTestClass(){}
    6. int Get(){return 23;}
    7. };
    8.  
    9. QObject *n ;
    10. QMyTestClass *o
    To copy to clipboard, switch view to plain text mode 

    First
    -----
    Qt Code:
    1. //QMyTestClass
    2. QMyTestClass* l = reinterpret_cast<QMyTestClass*>(0);
    3. const QMetaObject m = l->staticMetaObject;
    4. n = m.cast(myptr);
    5. o = static_cast<QMyTestClass*> (n);
    To copy to clipboard, switch view to plain text mode 
    Second
    ---------
    Qt Code:
    1. n = reinterpret_cast<QMyTestClass*>(0)->staticMetaObject.cast(myptr);
    2. o = static_cast<QMyTestClass*>(n);
    To copy to clipboard, switch view to plain text mode 

    In the first scenario I am getting the cast as NULL (i.e. o = NULL) where as in the second case I am getting the same as the correct cast. Just wondering what's the difference.

    Regards,
    Subhransu
    Last edited by wysota; 14th August 2008 at 07:55. Reason: missing [code] tags

Similar Threads

  1. very simple and basic FAM/Gamin wrapper for qt
    By momesana in forum Qt-based Software
    Replies: 0
    Last Post: 8th April 2008, 13:46
  2. Basic C++ doubt
    By munna in forum General Programming
    Replies: 8
    Last Post: 30th November 2006, 21:54

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
  •  
Qt is a trademark of The Qt Company.