Generate includes for Qt containers used as auto-metatypes.
Otherwise the containers might be forward declared in the moc file, and when the moc file is compiled in a standalone translation unit, the full definition of it would not be available. This results in odd compile errors, so instead generate the includes if required. Change-Id: Ie01c5a5d45314daad0b00dec03b3e1e18cdbae64 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Volker Krause <volker.krause@kdab.com> Reviewed-by: Olivier Goffart <ogoffart@woboq.com>bb10
parent
6efec23b10
commit
5a1fa8860c
|
|
@ -797,6 +797,38 @@ void Moc::parse()
|
|||
}
|
||||
}
|
||||
|
||||
static void findRequiredContainers(ClassDef *cdef, QSet<QByteArray> *requiredQtContainers)
|
||||
{
|
||||
static const QVector<QByteArray> candidates = QVector<QByteArray>()
|
||||
#define STREAM_SMART_POINTER(SMART_POINTER) << #SMART_POINTER
|
||||
QT_FOR_EACH_AUTOMATIC_TEMPLATE_SMART_POINTER(STREAM_SMART_POINTER)
|
||||
#undef STREAM_SMART_POINTER
|
||||
#define STREAM_1ARG_TEMPLATE(TEMPLATENAME) << #TEMPLATENAME
|
||||
QT_FOR_EACH_AUTOMATIC_TEMPLATE_1ARG(STREAM_1ARG_TEMPLATE)
|
||||
#undef STREAM_1ARG_TEMPLATE
|
||||
;
|
||||
|
||||
for (int i = 0; i < cdef->propertyList.count(); ++i) {
|
||||
const PropertyDef &p = cdef->propertyList.at(i);
|
||||
foreach (const QByteArray candidate, candidates) {
|
||||
if (p.type.contains(candidate + "<"))
|
||||
requiredQtContainers->insert(candidate);
|
||||
}
|
||||
}
|
||||
|
||||
QList<FunctionDef> allFunctions = cdef->slotList + cdef->signalList + cdef->methodList;
|
||||
|
||||
for (int i = 0; i < allFunctions.count(); ++i) {
|
||||
const FunctionDef &f = allFunctions.at(i);
|
||||
foreach (const ArgumentDef &arg, f.arguments) {
|
||||
foreach (const QByteArray candidate, candidates) {
|
||||
if (arg.normalizedType.contains(candidate + "<"))
|
||||
requiredQtContainers->insert(candidate);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Moc::generate(FILE *out)
|
||||
{
|
||||
|
||||
|
|
@ -837,6 +869,16 @@ void Moc::generate(FILE *out)
|
|||
if (mustIncludeQPluginH)
|
||||
fprintf(out, "#include <QtCore/qplugin.h>\n");
|
||||
|
||||
QSet<QByteArray> requiredQtContainers;
|
||||
for (i = 0; i < classList.size(); ++i) {
|
||||
findRequiredContainers(&classList[i], &requiredQtContainers);
|
||||
}
|
||||
|
||||
foreach (const QByteArray &qtContainer, requiredQtContainers) {
|
||||
fprintf(out, "#include <QtCore/%s>\n", qtContainer.constData());
|
||||
}
|
||||
|
||||
|
||||
fprintf(out, "#if !defined(Q_MOC_OUTPUT_REVISION)\n"
|
||||
"#error \"The header file '%s' doesn't include <QObject>.\"\n", fn.constData());
|
||||
fprintf(out, "#elif Q_MOC_OUTPUT_REVISION != %d\n", mocOutputRevision);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,76 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2012 Intel Corporation
|
||||
** Contact: http://www.qt-project.org/
|
||||
**
|
||||
** This file is part of the test suite of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** GNU Lesser General Public License Usage
|
||||
** This file may be used under the terms of the GNU Lesser General Public
|
||||
** License version 2.1 as published by the Free Software Foundation and
|
||||
** appearing in the file LICENSE.LGPL included in the packaging of this
|
||||
** file. Please review the following information to ensure the GNU Lesser
|
||||
** General Public License version 2.1 requirements will be met:
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU General
|
||||
** Public License version 3.0 as published by the Free Software Foundation
|
||||
** and appearing in the file LICENSE.GPL included in the packaging of this
|
||||
** file. Please review the following information to ensure the GNU General
|
||||
** Public License version 3.0 requirements will be met:
|
||||
** http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** Other Usage
|
||||
** Alternatively, this file may be used in accordance with the terms and
|
||||
** conditions contained in a signed written agreement between you and Nokia.
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
#include <qobject.h>
|
||||
#include <qmetatype.h>
|
||||
|
||||
// test support for const refs to forward-declared structs in parameters
|
||||
|
||||
struct ForwardDeclaredParam;
|
||||
template <typename T> class ForwardDeclaredContainer;
|
||||
|
||||
struct FullyDefined {};
|
||||
Q_DECLARE_METATYPE(FullyDefined)
|
||||
|
||||
class ForwardDeclaredParamClass : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public slots:
|
||||
void slotNaked(const ForwardDeclaredParam &) {}
|
||||
void slotFDC(const ForwardDeclaredContainer<ForwardDeclaredParam> &) {}
|
||||
void slotFDC(const ForwardDeclaredContainer<int> &) {}
|
||||
void slotFDC(const ForwardDeclaredContainer<QString> &) {}
|
||||
void slotFDC(const ForwardDeclaredContainer<FullyDefined> &) {}
|
||||
void slotQSet(const QSet<ForwardDeclaredParam> &) {}
|
||||
void slotQSet(const QSet<int> &) {}
|
||||
void slotQSet(const QSet<QString> &) {}
|
||||
void slotQSet(const QSet<FullyDefined> &) {}
|
||||
|
||||
signals:
|
||||
void signalNaked(const ForwardDeclaredParam &);
|
||||
void signalFDC(const ForwardDeclaredContainer<ForwardDeclaredParam> &);
|
||||
void signalFDC(const ForwardDeclaredContainer<int> &);
|
||||
void signalFDC(const ForwardDeclaredContainer<QString> &);
|
||||
void signalFDC(const ForwardDeclaredContainer<FullyDefined> &);
|
||||
void signalQSet(const QSet<ForwardDeclaredParam> &);
|
||||
void signalQSet(const QSet<int> &);
|
||||
void signalQSet(const QSet<QString> &);
|
||||
void signalQSet(const QSet<FullyDefined> &);
|
||||
};
|
||||
|
|
@ -21,6 +21,7 @@ HEADERS += using-namespaces.h no-keywords.h task87883.h c-comments.h backslash-n
|
|||
task234909.h task240368.h pure-virtual-signals.h cxx11-enums.h \
|
||||
cxx11-final-classes.h \
|
||||
cxx11-explicit-override-control.h \
|
||||
forward-declared-param.h \
|
||||
|
||||
|
||||
if(*-g++*|*-icc*|*-clang*|*-llvm):!irix-*:!win32-*: HEADERS += os9-newlines.h win-newlines.h
|
||||
|
|
|
|||
Loading…
Reference in New Issue