diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-04-16 08:23:07 +0200 |
---|---|---|
committer | cherrypickbot <cherrypickbot@codereview.qt-project.org> | 2020-04-24 09:19:35 +0000 |
commit | dccea132cb8bdf3e9a933a64e24b90e46536e3d4 (patch) | |
tree | 5e015e7e70fb64dadd3a965d9792abcbdcab9f02 | |
parent | b3cdd63d4bdaea09222fb93ffcd5104a2dc0bf2e (diff) | |
download | qttools-dccea132cb8bdf3e9a933a64e24b90e46536e3d4.tar.gz |
SimpleTextViewer example: Fix documentation not showing
Add a path search including the application source directory, which
should at least fix Qt 5.15. For educational purposes, also uses
some standard paths.
Change-Id: I1b20bd632b604a1413d7ac66d2e419e771708562
(cherry picked from commit: 492fd5bb5ebbe4300a67e10aa0eb52a633c63bfe)
Reviewed-by: cherrypickbot
-rw-r--r-- | examples/assistant/simpletextviewer/assistant.cpp | 43 | ||||
-rw-r--r-- | examples/assistant/simpletextviewer/assistant.h | 1 | ||||
-rw-r--r-- | examples/assistant/simpletextviewer/simpletextviewer.pro | 2 |
3 files changed, 38 insertions, 8 deletions
diff --git a/examples/assistant/simpletextviewer/assistant.cpp b/examples/assistant/simpletextviewer/assistant.cpp index 58103c14a..da29cea9e 100644 --- a/examples/assistant/simpletextviewer/assistant.cpp +++ b/examples/assistant/simpletextviewer/assistant.cpp @@ -50,11 +50,13 @@ #include "assistant.h" +#include <QApplication> #include <QByteArray> #include <QDir> #include <QLibraryInfo> #include <QMessageBox> #include <QProcess> +#include <QStandardPaths> Assistant::Assistant() : proc(0) @@ -85,6 +87,23 @@ void Assistant::showDocumentation(const QString &page) } //! [1] +QString documentationDirectory() +{ + QStringList paths; +#ifdef SRCDIR + paths.append(QLatin1String(SRCDIR)); +#endif + paths.append(QLibraryInfo::location(QLibraryInfo::ExamplesPath)); + paths.append(QCoreApplication::applicationDirPath()); + paths.append(QStandardPaths::standardLocations(QStandardPaths::AppDataLocation)); + for (const auto &dir : qAsConst(paths)) { + const QString path = dir + QLatin1String("/documentation"); + if (QFileInfo::exists(path)) + return path; + } + return QString(); +} + //! [2] bool Assistant::startAssistant() { @@ -99,21 +118,29 @@ bool Assistant::startAssistant() app += QLatin1String("Assistant.app/Contents/MacOS/Assistant"); #endif - QStringList args; - args << QLatin1String("-collectionFile") - << QLibraryInfo::location(QLibraryInfo::ExamplesPath) - + QLatin1String("/assistant/simpletextviewer/documentation/simpletextviewer.qhc") - << QLatin1String("-enableRemoteControl"); + const QString collectionDirectory = documentationDirectory(); + if (collectionDirectory.isEmpty()) { + showError(tr("The documentation directory cannot be found")); + return false; + } + + QStringList args{QLatin1String("-collectionFile"), + collectionDirectory + QLatin1String("/simpletextviewer.qhc"), + QLatin1String("-enableRemoteControl")}; proc->start(app, args); if (!proc->waitForStarted()) { - QMessageBox::critical(nullptr, - tr("Simple Text Viewer"), - tr("Unable to launch Qt Assistant (%1)").arg(app)); + showError(tr("Unable to launch Qt Assistant (%1): %2").arg(app, proc->errorString())); return false; } } return true; } //! [2] + +void Assistant::showError(const QString &message) +{ + QMessageBox::critical(QApplication::activeWindow(), + tr("Simple Text Viewer"), message); +} diff --git a/examples/assistant/simpletextviewer/assistant.h b/examples/assistant/simpletextviewer/assistant.h index 1ea7dd78f..c9b8f382c 100644 --- a/examples/assistant/simpletextviewer/assistant.h +++ b/examples/assistant/simpletextviewer/assistant.h @@ -69,6 +69,7 @@ public: private: bool startAssistant(); + void showError(const QString &message); QProcess *proc; }; diff --git a/examples/assistant/simpletextviewer/simpletextviewer.pro b/examples/assistant/simpletextviewer/simpletextviewer.pro index 314e75b36..b0de7f4e7 100644 --- a/examples/assistant/simpletextviewer/simpletextviewer.pro +++ b/examples/assistant/simpletextviewer/simpletextviewer.pro @@ -8,6 +8,8 @@ SOURCES = main.cpp \ assistant.cpp \ textedit.cpp +DEFINES += SRCDIR=\\\"$$PWD/\\\" + QT += widgets target.path = $$[QT_INSTALL_EXAMPLES]/assistant/simpletextviewer |