OnWorks favicon

moc-qt5 - Online in the Cloud

Run moc-qt5 in OnWorks free hosting provider over Ubuntu Online, Fedora Online, Windows online emulator or MAC OS online emulator

This is the command moc-qt5 that can be run in the OnWorks free hosting provider using one of our multiple free online workstations such as Ubuntu Online, Fedora Online, Windows online emulator or MAC OS online emulator



moc - generate Qt meta object support code


moc [-o file] [-i] [-f] [-k] [-ldbg] [-nw] [-p path] [-q path] [-v] file


This page documents the Meta Object Compiler for the Qt GUI application framework. The moc
reads one or more C++ class declarations from a C++ header or source file and generates
one C++ source file containing meta object information for the classes. The C++ source
file generated by the moc must be compiled and linked with the implementation of the class
(or it can be #included into the class's source file).

If you use qmake to create your Makefiles, build rules will be included that call the moc
when required, so you will not need to use the moc directly.

In brief, the meta object system is a structure used by Qt (see http://doc.trolltech.com)
for component programming and run time type information. It adds properties and
inheritance information to (some) classes and provides a new type of communication between
those instances of those classes, signal-slot connections.


-o file
Write output to file rather than to stdout.

-f Force the generation of an #include statement in the output. This is the default
for files whose name matches the regular expression .[hH][^.]* (i.e. the extension
starts with H or h ). This option is only useful if you have header files that do
not follow the standard naming conventions.

-i Do not generate an #include statement in the output. This may be used to run moc
on a C++ file containing one or more class declarations. You should then #include
the meta object code in the .cpp file (see USAGE below). If both -f and -i are
present, the last one wins.

-nw Do not generate any warnings. Not recommended.

-ldbg Write a flood of lex debug information to stdout.

-p path
Makes moc prepend path/ to the file name in the generated #include statement (if
one is generated).

-q path
Makes moc prepend path/ to the file name of qt #include files in the generated

-v Displays the version of moc and Qt.

You can explicitly tell the moc not to parse parts of a header file. It recognizes any C++
comment (//) that contains the substrings MOC_SKIP_BEGIN or MOC_SKIP_END. They work as you
would expect and you can have several levels of them. The net result as seen by the moc is
as if you had removed all lines between a MOC_SKIP_BEGIN and a MOC_SKIP_END


moc is almost always invoked by make(1), not by hand.

moc is typically used with an input file containing class declarations like this:

class YourClass : public QObject {

YourClass( QObject * parent=0, const char * name=0 );


public slots:


Here is a useful makefile rule if you only use GNU make:

m%.cpp: %.h
moc $< -o $@

If you want to write portably, you can use individual rules of the following form:

mNAME.cpp: NAME.h
moc $< -o $@

You must also remember to add mNAME.cpp to your SOURCES (substitute your favorite name)
variable and mNAME.o to your OBJECTS variable.

(While we prefer to name our C++ source files .cpp, the moc doesn't know that, so you can
use .C, .cc, .CC, .cxx or even .c++ if you prefer.)

If you have class declarations in C++ files, we recommend that you use a makefile rule
like this:

NAME.o: mNAME.cpp

mNAME.cpp: NAME.cpp
moc -i $< -o $@

This guarantees that make(1) will run the moc before it compiles NAME.cpp. You can then

#include "nNAME.cpp"

at the end of NAME.cpp, where all the classes declared in that file are fully known.


Sometimes you may get linkage errors, saying that YourClass::className() is undefined or
that YourClass lacks a vtbl. Those errors happen most often when you forget to compile
the moc-generated C++ code or include that object file in the link command.

The moc will warn you about a number of dangerous or illegal constructs.

Use moc-qt5 online using onworks.net services

Free Servers & Workstations

Download Windows & Linux apps

  • 1
    OfficeFloor provides inversion of
    coupling control, with its: - dependency
    injection - continuation injection -
    thread injection For more information
    visit the...
    Download OfficeFloor
  • 2
    DivKit is an open source Server-Driven
    UI (SDUI) framework. It allows you to
    roll out server-sourced updates to
    different app versions. Also, it can be
    used fo...
    Download DivKit
  • 3
    Utility to convert between various
    subscription format. Shadowrocket users
    should use ss, ssr or v2ray as target.
    You can add &remark= to
    Telegram-liked HT...
    Download subconverter
  • 4
    SWASH is a general-purpose numerical
    tool for simulating unsteady,
    non-hydrostatic, free-surface,
    rotational flow and transport phenomena
    in coastal waters as ...
    Download SWASH
  • 5
    VBA-M (Archived - Now on Github)
    VBA-M (Archived - Now on Github)
    Project has moved to
    Features:Cheat creationsave statesmulti
    system, supports gba, gbc, gb, sgb,
    Download VBA-M (Archived - Now on Github)
  • 6
    Linux System Optimizer and Monitoring
    Github Repository:
    Audience: End Users/Desktop. User
    interface: Qt. Programming La...
    Download Stacer
  • More »

Linux commands