Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt meta class
QtWS25 Last Chance

Qt meta class

Scheduled Pinned Locked Moved General and Desktop
14 Posts 7 Posters 6.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maxim.prishchepa
    wrote on last edited by
    #1

    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.

    Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz).

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chuck Gao
      wrote on last edited by
      #2

      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

      Chuck

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vsorokin
        wrote on last edited by
        #3

        How do you want using Meta classes? It is main question, because its are needed only for specific cases.

        --
        Vasiliy

        1 Reply Last reply
        0
        • M Offline
          M Offline
          maxim.prishchepa
          wrote on last edited by
          #4

          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.

          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz).

          1 Reply Last reply
          0
          • M Offline
            M Offline
            maxim.prishchepa
            wrote on last edited by
            #5

            [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). :)

            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz).

            1 Reply Last reply
            0
            • T Offline
              T Offline
              thisisbhaskar
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • V Offline
                V Offline
                vsorokin
                wrote on last edited by
                #7

                [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.

                --
                Vasiliy

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  maxim.prishchepa
                  wrote on last edited by
                  #8

                  [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.

                  Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz).

                  1 Reply Last reply
                  0
                  • Z Offline
                    Z Offline
                    ZapB
                    wrote on last edited by
                    #9

                    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).

                    Nokia Certified Qt Specialist
                    Interested in hearing about Qt related work

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      maxim.prishchepa
                      wrote on last edited by
                      #10

                      [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 :)

                      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz).

                      1 Reply Last reply
                      0
                      • G Offline
                        G Offline
                        goetz
                        wrote on last edited by
                        #11

                        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.

                        http://www.catb.org/~esr/faqs/smart-questions.html

                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          maxim.prishchepa
                          wrote on last edited by
                          #12

                          Thanks a lot! Start my way to understanding internal Qt mechanism by looking this video files.

                          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz).

                          1 Reply Last reply
                          0
                          • G Offline
                            G Offline
                            goetz
                            wrote on last edited by
                            #13

                            There is another one specifically on QWidget based GUI classes. This covers the interaction with the graphics system et al in detail.

                            http://www.catb.org/~esr/faqs/smart-questions.html

                            1 Reply Last reply
                            0
                            • C Offline
                              C Offline
                              changsheng230
                              wrote on last edited by
                              #14

                              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_OBJECT

                              public:
                              MyApp() {}
                              };

                              class MyNonQObject : public QObject
                              {
                              public:
                              MyNonQObject() {}
                              };

                              class MyQObject : public QObject
                              {
                              Q_OBJECT

                              public:
                              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&#40;&#41;;
                              

                              }

                              @

                              Chang Sheng
                              常升

                              1 Reply Last reply
                              0

                              • Login

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • Users
                              • Groups
                              • Search
                              • Get Qt Extensions
                              • Unsolved