Results 1 to 2 of 2

Thread: what is a moc file?

  1. #1
    Join Date
    Jul 2009
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default what is a moc file?

    hi,

    i noticed that qt creates a file named moc_projectname.cpp and i wonder what this file is.

    thanks

  2. #2
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default

    source from C++ GUI Programming with Qt4 book
    One of Qt's major achievements has been the extension of C++ with a mechanism for creating independent software components that can be bound together without any component knowing anything about the other components it is connected to.

    The mechanism is called the meta-object system, and it provides two key services: signals–slots and introspection. The introspection functionality is necessary for implementing signals and slots, and allows application programmers to obtain "meta-information" about QObject subclasses at run-time, including the list of signals and slots supported by the object and its class name. The mechanism also supports properties (used extensively by Qt Designer) and text translation (for internationalization), and it lays the foundation for the QtScript module.

    Standard C++ doesn't provide support for the dynamic meta-information needed by Qt's meta-object system. Qt solves this problem by providing a separate tool, moc, that parses Q_OBJECT class definitions and makes the information available through C++ functions. Since moc implements all its functionality using pure C++, Qt's meta-object system works with any C++ compiler.

    The mechanism works as follows:

    The Q_OBJECT macro declares some introspection functions that must be implemented in every QObject subclass: metaObject(), tr(), qt_metacall(), and a few more.

    Qt's moc tool generates implementations for the functions declared by Q_OBJECT and for all the signals.

    QObject member functions such as connect() and disconnect() use the introspection functions to do their work.
    All of this is handled automatically by qmake, moc, and QObject, so you rarely need to think about it. But if you are curious, you can read the QMetaObject class documentation and have a look at the C++ source files generated by moc to see how the implementation works.


    also this
    http://doc.trolltech.com/4.1/qmetaobject.html
    Last edited by wysota; 20th July 2009 at 13:45.
    "Behind every great fortune lies a crime" - Balzac

  3. The following user says thank you to wagmare for this useful post:

    meozeren (20th July 2009)

Similar Threads

  1. Adding a new file to moc process in XCode
    By redneon in forum Qt Programming
    Replies: 0
    Last Post: 2nd May 2009, 18:49
  2. Read binary from file
    By weldpua2008 in forum Newbie
    Replies: 2
    Last Post: 3rd April 2009, 23:50
  3. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21
  4. moc with same file names?
    By cjhuitt in forum Qt Programming
    Replies: 9
    Last Post: 27th April 2007, 20:36
  5. Qt 3.3.4 -> Qt 4.1.2, moc file issue
    By philski in forum Qt Tools
    Replies: 1
    Last Post: 11th September 2006, 21:08

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.