Thursday, May 7, 2009

Q. What is moc file and what is the use of it in Qt?

Ans: The Meta-Object Compiler, moc, is the program that handles Qt's C++ extensions.
The moc tool reads a C++ header file. If it finds one or more class declarations that contain the Q_OBJECT macro, it produces a C++ source file containing the meta-object code for those classes. Among other things, meta-object code is required for the signals and slots mechanism, the run-time type information, and the dynamic property system.
The C++ source file generated by moc must be compiled and linked with the implementation of the class.
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. For more background information on moc, see http://doc.trolltech.com/4.3/moc.html

Q. After compiling the Qt code, not getting the moc file.

Ans: Its a general mistake, what new commers in Qt use to do. Please check your code, you have forget to add 'Q_OBJECT' macro in the class.

Ex.

Class B : public QWidget

{

Q_OBJECT

//rest of the code

}

Q. Installed Qt-4.xxx version on Linux, written a program and then used 'qmake -project' then 'qmake' and finally 'make' to compile the program. But I am getting error, After checking the make file, I came to know that it has been created for qt-3.xxx version. How to get rid from this?

Ans: Qt-3.xxx is the default package, you will get it with linux. And at the time of installing Linux, this Qt-3.xxx also get installed. So now if you installed new version, you have to link it to the library. Please follow the following steps:

1.Please login as a root user

2.Go to bin directory by using $cd /usr/bin and remove the old links
rm –f assistant
rm –f lrelease
rm –f pixeltool
rm –f uic3
rm –f qtdemo
rm –f designer
rm –f lupdate
rm –f qmake
rm –f qt3to4
rm –f rcc
rm –f linguist
rm –f moc
rm –f qtconfig
rm –f uic

Once the old links are removed add new links,
Go to /usr/bin by using $cd /usr/bin and do as follows
$ ln –s /usr/local/Trolltech/Qt-4.xxx/bin/assistant.
$ ln –s /usr/local/Trolltech/Qt-4.xxx/bin/ lrelease.
$ ln –s /usr/local/Trolltech/Qt-4.xxx/bin/ pixeltool.
$ ln –s /usr/local/Trolltech/Qt-4.xxx/bin/ uic3.
$ ln –s /usr/local/Trolltech/Qt-4.xxx/bin/ qtdemo.
$ ln –s /usr/local/Trolltech/Qt-4.xxx/bin/ designer.
$ ln –s /usr/local/Trolltech/Qt-4.xxx/bin/ lupdate.
$ ln –s /usr/local/Trolltech/Qt-4.xxx/bin/ qmake.
$ ln –s /usr/local/Trolltech/Qt-4.xxx/bin/ qt3to4.
$ ln –s /usr/local/Trolltech/Qt-4.xxx/bin/ rcc.
$ ln –s /usr/local/Trolltech/Qt-4.xxx/bin/ linguist.
$ ln –s /usr/local/Trolltech/Qt-4.xxx/bin/ moc.
$ ln –s /usr/local/Trolltech/Qt-4.xxx/bin/ qtconfig.
$ ln –s /usr/local/Trolltech/Qt-4.xxx/bin/ uic.

Now you can directly use 'qmake ', by default it would be your Qt-4.xxx version.