Qt-interest Archive, May 2007
will RTTI concept wok in qt
Message 1 in thread
hi, frends i would like to get the type of an object the was refferenced by it's base class pointer..So that i need to use RTTI concept.. but here iam not getting desired output...
How can i do it?????????
Please c my code..
#include <iostream>
#include <typeinfo>
using namespace std;
class Mammal {
public:
virtual bool lays_eggs() { return false; }// Mammal is polymorphic
};
class Cat: public Mammal {
public:
};
class Platypus: public Mammal {
public:
bool lays_eggs() { return true; }
};
// Demonstrate typeid with a reference parameter.
void WhatMammal(Mammal *ob)
{
QString str;
str = "ob is referencing an object of type ";
str = typeid(ob).name();
}
CRTTITesting::CRTTITesting(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
ui.setupUi(this);
Mammal AnyMammal;
Cat cat;
Platypus platypus;
WhatMammal(&AnyMammal);
WhatMammal(&cat);
WhatMammal(&platypus);
}
D. Anil kumar
Every success has a story of great failure.
So don't stop with failure where
Success comes after failure.
Message 2 in thread
anil kumar schrieb:
> ...
> by it's base class pointer..So that i need to use RTTI concept.. but ...
> How can i do it?????????
(Shouting out loud with the exact number of '!' as '?' in the
question)Enable RTTI support in your compiler!!!!!!!!! Alternatively use
the Qt meta system which also provides class information and more.
> Please c my code..
What does that mean? Shall we rewrite your C++ code into C code or what? ;)
Cheers, Oliver
--
[ signature omitted ]
Message 3 in thread
> > Please c my code..
>
> What does that mean? Shall we rewrite your C++ code into C code or
what?
> ;)
hehe thats what i thought, too ;-) gonna be hard when you have to keep
RTTI working...
Peter
--
[ signature omitted ]
Message 4 in thread
Anil, please write to the list instead, *not in private* (and yes, my
sending to you in private was a mistake, too).
anil kumar schrieb:
> NOTHING , I GOT IT AVTUALLY I AM USING VISUAL STUDIO FOR WRITING & COMPILING
> MY QT CODE...
Huh? What do you mean by "nothing"?
> IN VISUAL STUDIO IDE WE HAVE TO ENABLE " RTTI OPTION" SORRY THIS IS NOT
> RELATED TO QT......
You don't have to be sorry - simply choose the proper mailing list. This
is *not* the appropriate list, as you have already figured out.
> AND MORE OVER
> My C CODE MEANS , PLEASE SEA MY CODE...
Ahh.. now I get it: We should dump your code into the sea!
> ANY WAY THAX....
Honestly (and this applies to all human-to-human communication forms):
if you expect other people to invest some time as to answer your
questions, don't write in this childish style. This is *not a chatroom*!
And please stop writing in CAPITALS, this sounds very rude.
Google for "How to ask smart questions".
Cheers, Oliver
--
[ signature omitted ]
Message 5 in thread
Hi,
> hi, frends i would like to get the type of an object the was refferenced
> by it's base class pointer..So that i need to use RTTI concept.. but
> here iam not getting desired output...
How is this related to Qt?
--
[ signature omitted ]