qmltyperegistrar: Fix file inclusion and writing to stdout

Apparently if you write #include into a raw string literal, the file is
included right there, as part of the string. We don't want this.
Therefore, write the #include as regular string.

Furthermore, drop some dead code, and make sure we actually write to
stdout if no -o option is given.

Amends commit dbe42f6435.

Change-Id: Ia4074dd486bdf9430acec4ac2564f9e654b5e3a8
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Ulf Hermann 2022-08-24 09:30:08 +02:00
parent cc89f62851
commit ef8cd39b28
2 changed files with 4 additions and 15 deletions

View File

@ -149,11 +149,11 @@ void QmlTypeRegistrar::write(QTextStream &output)
** WARNING! All changes made in this file will be lost!
*****************************************************************************/
#include <QtQml/qqml.h>
#include <QtQml/qqmlmoduleregistration.h>
)"_s;
output << u"#include <QtQml/qqml.h>\n"_s;
output << u"#include <QtQml/qqmlmoduleregistration.h>\n"_s;
for (const QString &include : m_includes)
output << u"\n#include <%1>"_s.arg(include);

View File

@ -12,15 +12,6 @@
using namespace Qt::Literals;
struct ScopedPointerFileCloser
{
static inline void cleanup(FILE *handle)
{
if (handle)
fclose(handle);
}
};
int main(int argc, char **argv)
{
// Produce reliably the same output for the same input by disabling QHash's random seeding.
@ -146,8 +137,6 @@ int main(int argc, char **argv)
parser.isSet(followForeignVersioningOption));
typeRegistrar.setTypes(processor.types(), processor.foreignTypes());
QScopedPointer<FILE, ScopedPointerFileCloser> outputFile;
if (parser.isSet(outputOption)) {
// extract does its own file handling
QString outputName = parser.value(outputOption);
@ -159,7 +148,7 @@ int main(int argc, char **argv)
QTextStream output(&file);
typeRegistrar.write(output);
} else {
QTextStream output(stdin);
QTextStream output(stdout);
typeRegistrar.write(output);
}