Qt4-preview-feedback Archive, November 2004
Moc 4.0.0 issues: multiple inheritance with namespaces and the -pch flag
Message 1 in thread
Hi,
I have run into a couple of issues with moc.exe in the 4.0.0 technology preview:
1. Classes in a namespace using multiple inheritance
Running moc on such a class generates code with a syntax error. For example,
running moc on this code:
#include <QObject>
class A
{
};
namespace my_namespace
{
class my_class : public QObject, public A
{
Q_OBJECT;
};
}
generates this method:
void *my_namespace::my_class::qt_metacast(const char *_clname)
{
if (!_clname) return 0;
if (!strcmp(_clname, qt_meta_stringdata_my_namespace__my_class))
return static_cast<void*>(const_cast<my_namespace::my_class*>(this));
if (!strcmp(_clname, "A"))
return static_cast<A*>(const_cast<my_namespace__my_class*>(this)); // <- ERROR
return QObject::qt_metacast(_clname);
}
Presumedly, the indicated line should read:
return static_cast<A*>(const_cast<my_namespace::my_class*>(this));
2. -pch flag no longer supported
The moc distributed with Qt3.3.1 supported the flag "-pch <filename>" used to
specify a file to be #included at the start of the generated code. This flag no
longer appears to work:
> moc.exe -pch path/stdafx.h my_class.h
moc: Too many input files specified
Usage: moc [options] <header-file>
-o<file> Write output to file rather than stdout
-I<dir> Add dir to the include path for header files
-E Preprocess only; do not generate meta object code
-D<macro>[=<def>] Define macro, with optional definition
-U<macro> Undefine macro
-i Do not generate an #include statement
-p<path> Path prefix for included file
-f[<file>] Force #include, optional file name
-nw Do not display warnings
-v Display version of moc
Is there a way to achieve the same effect in 4.0.0?
Thanks for your time,
Trent.
Message 2 in thread
> 2. -pch flag no longer supported
>
> The moc distributed with Qt3.3.1 supported the flag "-pch <filename>" used to
> specify a file to be #included at the start of the generated code. This flag no
> longer appears to work:
>
> > moc.exe -pch path/stdafx.h my_class.h
> moc: Too many input files specified
> Usage: moc [options] <header-file>
> -o<file> Write output to file rather than stdout
> -I<dir> Add dir to the include path for header files
> -E Preprocess only; do not generate meta object code
> -D<macro>[=<def>] Define macro, with optional definition
> -U<macro> Undefine macro
> -i Do not generate an #include statement
> -p<path> Path prefix for included file
> -f[<file>] Force #include, optional file name
> -nw Do not display warnings
> -v Display version of moc
>
> Is there a way to achieve the same effect in 4.0.0?
It's no longer needed for the purpose of PCH support.
http://doc.trolltech.com/3.3/qmake-manual-7.html explains more on using
precompiled headers in Qt.
This is a Qt 3.3 version of the manual, but the method should still
work. You may take a look at src/kernel/qt_pch.h for the PCH file used
with Qt itself. Note that too big of a PCH file may actually _slow down_
your compilation since the compiler state gets too big, so be careful
with what you put in there.
Basically what happens is that instead of requiring the inclusion of a
given file (stdafx.h in your case), the qmake generated project files
(Makefiles for nmake, DSP/VCPROJ for VS) "injects" this inclusion at
compile time. This way we may more transparently support PCH only on
systems that have such a feature.
This means that you don't have to change your programming style just
because you suddenly want to use PCH in your project.
Good luck!
.marius
Message 3 in thread
On Friday 12 November 2004 06:25, Trent Hill wrote:
> Hi,
>
> I have run into a couple of issues with moc.exe in the 4.0.0 technology
> preview:
>
> 1. Classes in a namespace using multiple inheritance
The same error got reported a few days ago, it's fixed now.
>
>
> 2. -pch flag no longer supported
>
> The moc distributed with Qt3.3.1 supported the flag "-pch <filename>" used
> to specify a file to be #included at the start of the generated code. This
> flag no
[...]
>
> Is there a way to achieve the same effect in 4.0.0?
Interestingly enough moc -help in Qt 3.3 didn't document the option.
You are using pch for precompiled headers?
Matthias
Message 4 in thread
> > 1. Classes in a namespace using multiple inheritance
>
> The same error got reported a few days ago, it's fixed now.
Great, thanks. I did search the archive before posting but didn't find
anything - is there a public issues list available?
> > 2. -pch flag no longer supported
> >
> > The moc distributed with Qt3.3.1 supported the flag "-pch <filename>" used
> > to specify a file to be #included at the start of the generated code. This
> > flag no
> [...]
> >
> > Is there a way to achieve the same effect in 4.0.0?
>
> Interestingly enough moc -help in Qt 3.3 didn't document the option.
This is true, I believe it was documented in release notes but I can't be sure.
> You are using pch for precompiled headers?
I am. Another poster gave details of a qmake-based solution, however we have
integrated Qt into our in-house build system and do not use qmake. I'm sure
there are other methods to inject includes prior to compiling the generated
code but the -pch option provided a simple, compiler-independent solution.
Is there a chance that -pch will be reinstated for the official release?
Thanks,
Trent.
Message 5 in thread
>>You are using pch for precompiled headers?
>
> I am. Another poster gave details of a qmake-based solution,
> however we have integrated Qt into our in-house build system
> and do not use qmake. I'm sure there are other methods to
> inject includes prior to compiling the generated code but the
> -pch option provided a simple, compiler-independent solution.
Hmm, I'm not sure I see the problem. Instead of specifying -pch for the
moc command, you specify -FI<name of PCH file> (for MSVC's cl.exe) on
the compile line. More flexible, and guaranteed to support all code
generation tools out there.
And it has the added benefit that you don't have to add the
#include "stdafx.h"
in every sourcefile in your project, no matter which platform you're on.
> Is there a chance that -pch will be reinstated for the
> official release?
Probably not, sorry.
.marius
Message 6 in thread
> > I am. Another poster gave details of a qmake-based solution,
> > however we have integrated Qt into our in-house build system
> > and do not use qmake. I'm sure there are other methods to
> > inject includes prior to compiling the generated code but the
> > -pch option provided a simple, compiler-independent solution.
>
> Hmm, I'm not sure I see the problem. Instead of specifying -pch for the
> moc command, you specify -FI<name of PCH file> (for MSVC's cl.exe) on
> the compile line. More flexible, and guaranteed to support all code
> generation tools out there.
Our code targets a number of platforms using various compilers. All of
these compilers support precompiled headers where the precompiled header
is the first include in a source file.
We currently manually add the header include to our own source files and use
the -pch option to add the include in the moc-generated files. As you say,
the alternative is to use compiler flags to inject the include. However this
approach requires us to write a different rule to inject the include for each
compiler we use - which is fine, just more work than using the -pch option
in our case.
I just wanted to check that -pch was officially no longer supported before
writing the injection rules.
Thanks for you time,
Trent.