Qt meta class
-
wrote on 8 Jul 2011, 09:42 last edited by
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.
-
wrote on 8 Jul 2011, 09:50 last edited by
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
-
wrote on 8 Jul 2011, 09:52 last edited by
How do you want using Meta classes? It is main question, because its are needed only for specific cases.
-
wrote on 8 Jul 2011, 10:06 last edited by
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.
-
wrote on 8 Jul 2011, 10:08 last edited by
[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). :)
-
wrote on 8 Jul 2011, 10:21 last edited by
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.
-
wrote on 8 Jul 2011, 10:29 last edited by
[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.
-
wrote on 8 Jul 2011, 10:33 last edited by
[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.
-
wrote on 8 Jul 2011, 10:33 last edited by
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).
-
wrote on 8 Jul 2011, 10:37 last edited by
[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 :)
-
wrote on 10 Jul 2011, 22:31 last edited by
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.
-
wrote on 11 Jul 2011, 08:03 last edited by
Thanks a lot! Start my way to understanding internal Qt mechanism by looking this video files.
-
wrote on 11 Jul 2011, 08:24 last edited by
There is another one specifically on QWidget based GUI classes. This covers the interaction with the graphics system et al in detail.
-
wrote on 11 Jul 2011, 08:41 last edited by
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();
}
@
1/14