When is a class added to the list of moc files

W. Tasin tasin at e-technik.fh-muenchen.de
Tue Apr 18 11:16:27 BST 2000


Falk Brettschneider wrote:
> 
> Hi,

Hi,

> 
> Werner Modenbach wrote:
> >
> > Recently we created a class which was derived from QFrame.
> > Everything worked fine until we tried to create a signal.
> > The linker reclaimed for a missing reference.
> > It took us a long while to find out that there is no meta object created from
> > our class. Where do I tell to build a meta object. Isn't it possible to do this
> > automatically when detecting signals or slots?

as both mails before already mentioned, you have to insert
Q_OBJECT in your class definition...


> >
> > After we fixed this (by creating a new project and transfering the source to
> > the prebuild classes - our project ist still small ;-)) now we tried to connect
> > the signal to a slot of another class.
> > This seend to work fine, but unfortinately when I debug until the emit
> > statement the emit returns without calling the slot.
> Signal-slot works only in classes that insert the Q_OBJECT macro right
> at the beginning of its class definition:
> 
> class Falk : public Boss {
>   Q_OBJECT
> public:
>   ...
> };
> 
> >
> > Do I have to take care about some specialities to make this work?
> Initially call ´tmake x.pro -o Makefile´. Tmake parses your sources and
> headers for the Q_OBJECT macro and set the rules in your Makefile to
> create and compile the meta objects. Those meta objects are inserted in
> the moc_....cpp file and they are generated by a tool called ´moc´ (meta
> object compiler). See the tmake-generated Makefile for rules that call
> the moc.
> 
> But you don´t need to do anything except inserting Q_OBJECT.
> Note: whenever you change your .pro-File, tmake is called automatically.
> 
> For further question look into the Qt documentation (section
> signal&slots)
> 
> Hope that helps,
>   Falk
> 

Now you know how it would be done with tmake...
but tmake won´t be really used by KDevelop, apart from using a custom
project...
and why using a custom, if all this what Falk mentioned is already done
by KDE/QT projects (and the automake/autoconf)?

For example creating a KDE/QT-project "myProject".
Then you will find a perl-script called "am_edit", which is called by
"make -f Makefile.dist" (or using KDevelop´s command "Build/Automake &
Autoconf" and "Build/configure").
This am_edit call will patch the Makefiles to use the moc (the only
difference is in the resulting filename: <name>.moc.cpp)

Requirements:
In myProject/myProject/Makefile.am:
----
myProject_METASOURCES=AUTO
----
but this line has been already added by the KDE/QT project app-wizard.

and "perl am_edit" adds the Makefile-rules (inside Makefile.in) to
invoke the moc-compiler for those headerfiles, which contain the
Q_OBJECT macro.

=================
In kdevelop 1.1:
you still find the old kind of handling this:
using "automoc" script instead of "am_edit"

In myProject/myProject/Makefile.am:
----
myProject_METASOURCES=USE_AUTOMOC
----
and the call is "perl automoc" instead of "perl am_edit", of course.
=================

Thats it...
you don´t have to use tmake and to create a custom project to get it
worked.
Only insert Q_OBJECT to the class-definitions, which uses the
signal/slot-concept.

If you create a class by KDevelop (like using the CV and the
right-mouse-button to select the menuitem "New class") and select
"Generate a QWidget-Childclass", the Q_OBJECT macro will be inserted
automatically.


Bye

Walter


> __________________________________________________
> Do You Yahoo!?
> Talk to your friends online with Yahoo! Messenger.
> http://im.yahoo.com

-- 
The KDevelop project: tasin at kdevelop.de [www.kdevelop.org]
--
oohhh sveglia.... il mondo e' ammalato, ma x colpa di chi.........
(Zucchero)
:-------W. Tasin, FB
04,FHM-------------------PGP-KeyID:0x7961A645----------:
<Key-Fingerprint: 1610 835F 0080 32F4 6140  6CF7 A7D0 44CD 7961A645>






More information about the KDevelop mailing list