Qt-interest Archive, November 2007
Including moc_ file
Message 1 in thread
Hello all,
Can somebody explain me when do I need to do:
#include "moc_xxx.cpp"
?
I've been trying to understand when do I need to do this but I can't
figure it out.
--
[ signature omitted ]
Message 2 in thread
On Wednesday 28 November 2007 23:51:56 Paulo J. Matos wrote:
> Hello all,
>
> Can somebody explain me when do I need to do:
> #include "moc_xxx.cpp"
> ?
>
> I've been trying to understand when do I need to do this but I can't
> figure it out.
You shouldn't have to. It should be in the Makefile, however.
Why do you need to do this?
--
[ signature omitted ]
Message 3 in thread
On torsdag den 29. November 2007, Eric Methorst wrote:
> On Wednesday 28 November 2007 23:51:56 Paulo J. Matos wrote:
> > Hello all,
> >
> > Can somebody explain me when do I need to do:
> > #include "moc_xxx.cpp"
> > ?
> >
> > I've been trying to understand when do I need to do this but I can't
> > figure it out.
>
> You shouldn't have to. It should be in the Makefile, however.
> Why do you need to do this?
1) It's a choice you have. With other build systems than qmake, there might be
places where you need to tell it that these files are related. Including the
moc header is one way.
2) More realistic: Whenever you make a QObject subclass that has the Q_OBJECT
macro, and that class is only present in the cpp file, then you must include
the moc header output. If you use qmake, at least. If your private class is a
subclass of QObject, but doesn't have Q_OBJECT, then you don't need to
include the header file.
There are a couple of standard places where 2) is needed. First one is the
private pointer pattern that Qt uses; if you need the private object to use
signals and slots, then you need to do the include. Another one is to make
small helper classes for throwing signals and slots around.
Bo.
--
[ signature omitted ]
Message 4 in thread
> Hello all,
>
> Can somebody explain me when do I need to do:
> #include "moc_xxx.cpp"
> ?
>
> I've been trying to understand when do I need to do this but I can't
> figure it out.
>
The only time I have ever had to do it, was when I defined a "hidden"
class in a C++ file that was also QObject based. So I had to have moc
run on the C++ file, and include the output in that C++ file.
Scott
--
[ signature omitted ]
Message 5 in thread
Scott Aron Bloom wrote:
>> Hello all,
>>
>> Can somebody explain me when do I need to do:
>> #include "moc_xxx.cpp"
>> ?
>>
>> I've been trying to understand when do I need to do this but I can't
>> figure it out.
>>
> The only time I have ever had to do it, was when I defined a "hidden"
> class in a C++ file that was also QObject based. So I had to have moc
> run on the C++ file, and include the output in that C++ file.
In this case, shouldn't it be:
#include "<cpp-file-name>.moc"
not the:
#include "moc_<cpp-file-name>.cpp"
mentioned by the original poster? I've never needed to include a
moc_xxx.cpp file.
Martin.
--
[ signature omitted ]
Message 6 in thread
> -----Original Message-----
> From: Martin Irman [mailto:imartin@xxxxxxx]
> Sent: Friday, November 30, 2007 8:45 AM
> To: qt-interest@xxxxxxxxxxxxx
> Subject: Re: Including moc_ file
>
> Scott Aron Bloom wrote:
> >> Hello all,
> >>
> >> Can somebody explain me when do I need to do:
> >> #include "moc_xxx.cpp"
> >> ?
> >>
> >> I've been trying to understand when do I need to do this but I
can't
> >> figure it out.
> >>
> > The only time I have ever had to do it, was when I defined a
"hidden"
> > class in a C++ file that was also QObject based. So I had to have
moc
> > run on the C++ file, and include the output in that C++ file.
>
> In this case, shouldn't it be:
>
> #include "<cpp-file-name>.moc"
>
> not the:
>
> #include "moc_<cpp-file-name>.cpp"
>
> mentioned by the original poster? I've never needed to include a
> moc_xxx.cpp file.
>
> Martin.
I believe you are correct, however, its been a long time since I had to
do it myself ;)
I was speaking more of the "why would you include a moc generated file
at all" not just the moc_<>.cpp
Scott
--
[ signature omitted ]
Message 7 in thread
Martin wrote:
> Scott Aron Bloom wrote:
> > The only time I have ever had to do it, was when I defined
> a "hidden"
> > class in a C++ file that was also QObject based. So I had
> to have moc
> > run on the C++ file, and include the output in that C++ file.
>
> In this case, shouldn't it be:
>
> #include "<cpp-file-name>.moc"
>
> not the:
>
> #include "moc_<cpp-file-name>.cpp"
>
> mentioned by the original poster? I've never needed to include a
> moc_xxx.cpp file.
>
> Martin.
Have a look at the qtsolutions, qtpropertybrowser has an example for
this.
Basically, any <file_name>.h file that has something as
Q_DECLARE_PRIVATE in it produces a moc_<file_name>.cpp that has to be
included in the corresponding <file_name>.cpp file.
Cheers,
Peter
--
[ signature omitted ]