Qt meta class
-
Hi, where i can find some examples about Qt MetaClasses? I looked at example directory and find nothing :( At Qt Assistant find description about QMetaObject class and other meta classes, but don't see any examples, how to use meta classes.
-
There are some documents about "The Meta-Object System" and some related knowledge, but no example. I think the document is good enough to learn what's meta-object system is in Qt, and how to use it. If you want to dig into Qt itself, you can read some article of Qt Internals "here":http://developer.qt.nokia.com/wiki/Category:QtInternals , and read some source code :D
-
Tnx, i won't to learn "Meta-Object System" for understanding how dose it work :) Looks some piece of code, at first look nothing complicated, but when i try to create some "unknown" class like that: get some pointer to object, than get class name of this object: @someObj->getMetaObject()->className();@ then i want create new object same class name, and hear i don't understand how to do that.
-
[quote author="Vass" date="1310118759"]How do you want using Meta classes? It is main question, because its are needed only for specific cases.[/quote]
I think - nowhere :) in my practice i don't needed to use meta classes, but i won't to understand how them works (for myself). :)
-
Good way to learn is to look at the moc_* files generated by your moc compiler for your application and try to understand them. This can help you understand how signals / slot, Qt Property system works.
-
[quote author="Maxim Prishchepa" date="1310119737"]
I think - nowhere :) in my practice i don't needed to use meta classes, but i won't to understand how them works (for myself). :)[/quote]Ahh, good idea for learning. Then I think only studing of Qt source code can help you.
-
[quote author="Vijay Bhaska Reddy" date="1310120517"]Good way to learn is to look at the moc_* files generated by your moc compiler for your application and try to understand them. This can help you understand how signals / slot, Qt Property system works. [/quote]
Tnx a lot, i hope i understand how to work signal\slot system :), but i can't understand how to create some class if at compilation stage compiler doesn't know what class name need to use.
-
Make a simple class that inherits QObject, build your project and look at the generated moc_.cpp file. This "page":http://dev.libqxt.org/libqxt/wiki/Meta_Object_Format from the Qxt project explains the format in some detail.
Once you understand that look at the Qt code by stepping into an emit call in the debugger (you'll need a debug build of Qt).
-
[quote author="ZapB" date="1310121223"]Make a simple class that inherits QObject, build your project and look at the generated moc_.cpp file. This "page":http://dev.libqxt.org/libqxt/wiki/Meta_Object_Format from the Qxt project explains the format in some detail.
Once you understand that look at the Qt code by stepping into an emit call in the debugger (you'll need a debug build of Qt).[/quote]
Thank you very much for link :)
-
There was some presentation of the meta object system during one of the last DevDays - you might want to search the "video archive":http://developer.qt.nokia.com/elearning on DevNet, especially "Qt in depth":http://developer.qt.nokia.com/elearning/watch/qt_in_depth from 2006.
-
Thanks a lot! Start my way to understanding internal Qt mechanism by looking this video files.
-
Here are some chunks of codes which you can run for the basic understanding of Qt meta system.
@#include <QtCore/QCoreApplication>
#include <iostream>
using namespace std;#include <QObject>
class MyApp : public QObject
{
Q_OBJECTpublic:
MyApp() {}
};class MyNonQObject : public QObject
{
public:
MyNonQObject() {}
};class MyQObject : public QObject
{
Q_OBJECTpublic:
MyQObject() {}
};int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);MyQObject obj; obj.setObjectName("instanceName"); QString objName = obj.objectName(); QString clasName = obj.metaObject()->className(); cout << "MyQObject objName: " << objName.toStdString() <<endl; cout << "MyQObject className: " << clasName.toStdString() <<endl; bool isherited = obj.inherits("QObject"); cout << "Derive from QObject ? " << isherited << endl; isherited = obj.inherits("QWideget"); cout << "Derive from QWideget ? " << isherited << endl; MyNonQObject obj2; clasName = obj2.metaObject()->className(); cout << "MyNonQObject className: " << clasName.toStdString() <<endl; int sizeOfQObject = sizeof(QObject); cout << "size of QObject: " << sizeOfQObject <<endl; return a.exec();
}
@