qdbusxml2cpp: Fix warnings about writing to closed devices.

Unearthed by fe1cbe9ca7 while
building QPlatformSupport.

Change-Id: Ife56efe111dda6bcf9f11f9c144a4d1dc1651380
Reviewed-by: Laszlo Papp <lpapp@kde.org>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Friedemann Kleint 2013-10-29 09:41:08 +01:00 committed by The Qt Project
parent 175489f102
commit d7f8f7e078

View File

@ -509,10 +509,10 @@ static QString stringify(const QString &data)
return retval; return retval;
} }
static void openFile(const QString &fileName, QFile &file) static bool openFile(const QString &fileName, QFile &file)
{ {
if (fileName.isEmpty()) if (fileName.isEmpty())
return; return false;
bool isOk = false; bool isOk = false;
if (fileName == QLatin1String("-")) { if (fileName == QLatin1String("-")) {
@ -525,6 +525,7 @@ static void openFile(const QString &fileName, QFile &file)
if (!isOk) if (!isOk)
fprintf(stderr, "Unable to open '%s': %s\n", qPrintable(fileName), fprintf(stderr, "Unable to open '%s': %s\n", qPrintable(fileName),
qPrintable(file.errorString())); qPrintable(file.errorString()));
return isOk;
} }
static void writeProxy(const QString &filename, const QDBusIntrospection::Interfaces &interfaces) static void writeProxy(const QString &filename, const QDBusIntrospection::Interfaces &interfaces)
@ -821,15 +822,17 @@ static void writeProxy(const QString &filename, const QDBusIntrospection::Interf
hs.flush(); hs.flush();
QFile file; QFile file;
openFile(headerName, file); const bool headerOpen = openFile(headerName, file);
file.write(headerData); if (headerOpen)
file.write(headerData);
if (headerName == cppName) { if (headerName == cppName) {
file.write(cppData); if (headerOpen)
file.write(cppData);
} else { } else {
QFile cppFile; QFile cppFile;
openFile(cppName, cppFile); if (openFile(cppName, cppFile))
cppFile.write(cppData); cppFile.write(cppData);
} }
} }
@ -1125,15 +1128,17 @@ static void writeAdaptor(const QString &filename, const QDBusIntrospection::Inte
hs.flush(); hs.flush();
QFile file; QFile file;
openFile(headerName, file); const bool headerOpen = openFile(headerName, file);
file.write(headerData); if (headerOpen)
file.write(headerData);
if (headerName == cppName) { if (headerName == cppName) {
file.write(cppData); if (headerOpen)
file.write(cppData);
} else { } else {
QFile cppFile; QFile cppFile;
openFile(cppName, cppFile); if (openFile(cppName, cppFile))
cppFile.write(cppData); cppFile.write(cppData);
} }
} }