diff options
author | Ulf Hermann <ulf.hermann@theqtcompany.com> | 2015-04-15 15:50:30 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@theqtcompany.com> | 2015-04-15 17:10:06 +0300 |
commit | 1e910371d7544764724c8045d2f71954cbaae597 (patch) | |
tree | 8aa24e76efd9bf3b3eeb628f64ead3d552baac3e | |
parent | f1c01c47c40d85b82b8e665b8ad4f62b69a09449 (diff) |
Use deferred execution and remove the exitCode variable
By starting the loading from app.exec() we can be sure that qapp.exit()
terminates it. Also, we don't want to try unwinding if we cannot
determine the CPU architecture.
Change-Id: I230ba02a1fe86295d1051459842d6f592bbe1ab9
Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
-rw-r--r-- | app/main.cpp | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/app/main.cpp b/app/main.cpp index 0c21e0e..e50f242 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -61,8 +61,6 @@ private: int main(int argc, char *argv[]) { - int exitCode = -1; - QCoreApplication app(argc, argv); app.setApplicationName(QLatin1String("perfparser")); app.setApplicationVersion(QLatin1String("1.0")); @@ -191,7 +189,8 @@ int main(int argc, char *argv[]) if (unwind.architecture() == PerfRegisterInfo::ARCH_INVALID) { qWarning() << "No information about CPU architecture found. Cannot unwind."; - app.exit(MissingData); + qApp->exit(MissingData); + return; } QObject::connect(infile.data(), &QIODevice::readyRead, &data, &PerfData::read); @@ -199,17 +198,16 @@ int main(int argc, char *argv[]) data.read(); }); - QObject::connect(&header, &PerfHeader::error, [&]() { - app.exit(HeaderError); + QObject::connect(&header, &PerfHeader::error, []() { + qApp->exit(HeaderError); }); - QObject::connect(&data, &PerfData::finished, [&]() { - exitCode = NoError; - app.exit(NoError); + QObject::connect(&data, &PerfData::finished, []() { + qApp->exit(NoError); }); - QObject::connect(&data, &PerfData::error, [&]() { - app.exit(DataError); + QObject::connect(&data, &PerfData::error, []() { + qApp->exit(DataError); }); if (parser.isSet(host)) { @@ -221,10 +219,10 @@ int main(int argc, char *argv[]) } else { if (!infile->open(QIODevice::ReadOnly)) return CannotOpen; - header.read(); + QMetaObject::invokeMethod(&header, "read", Qt::QueuedConnection); } - return exitCode == -1 ? app.exec() : NoError; + return app.exec(); } @@ -232,7 +230,7 @@ void PerfTcpSocket::processError(QAbstractSocket::SocketError error) { if (reading) { qWarning() << "socket error" << error << errorString(); - QCoreApplication::instance()->exit(TcpSocketError); + qApp->exit(TcpSocketError); } // Otherwise ignore the error. We don't need the socket anymore } |