diff options
| author | Oleksii Zbykovskyi <Oleksii.Zbykovskyi@qt.io> | 2025-07-25 09:54:49 +0200 |
|---|---|---|
| committer | Oleksii Zbykovskyi <Oleksii.Zbykovskyi@qt.io> | 2025-07-25 20:36:21 +0200 |
| commit | a74a1ee297ad4540d9b28e2cdeebe02eafe3c3a7 (patch) | |
| tree | 9460692e5ece58b93286f3f37fedc3e7650b8ccc /src/corelib/doc/snippets | |
| parent | de156489923b5092a12a925c20a0245004622c00 (diff) | |
Fix of files under mimetype and plugin prefix in code folder
Made these files compileable.
Task-number: QTBUG-137566
Change-Id: I68747552d4508ebee1f9fbd62683a3738ef9050f
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/corelib/doc/snippets')
4 files changed, 74 insertions, 50 deletions
diff --git a/src/corelib/doc/snippets/code/CMakeLists.txt b/src/corelib/doc/snippets/code/CMakeLists.txt index 5f8fba7b528..31f676031b9 100644 --- a/src/corelib/doc/snippets/code/CMakeLists.txt +++ b/src/corelib/doc/snippets/code/CMakeLists.txt @@ -46,6 +46,9 @@ add_library(corelib_snippets_code OBJECT src_corelib_kernel_qproperty.cpp src_corelib_kernel_qsystemsemaphore.cpp src_corelib_kernel_qvariant.cpp + src_corelib_mimetype_qmimedatabase.cpp + src_corelib_plugin_qlibrary.cpp + src_corelib_plugin_quuid.cpp ) target_link_libraries(corelib_snippets_code PRIVATE diff --git a/src/corelib/doc/snippets/code/src_corelib_mimetype_qmimedatabase.cpp b/src/corelib/doc/snippets/code/src_corelib_mimetype_qmimedatabase.cpp index 0b8d1e93340..ff7c803097d 100644 --- a/src/corelib/doc/snippets/code/src_corelib_mimetype_qmimedatabase.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_mimetype_qmimedatabase.cpp @@ -1,23 +1,31 @@ // Copyright (C) 2016 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QMimeDatabase> +#include <QMimeType> +#include <QStandardPaths> + using namespace Qt::StringLiterals; -//! [0] -QMimeDatabase db; -QMimeType mime = db.mimeTypeForFile(fileName); -if (mime.inherits("text/plain")) { - // The file is plain text, we can display it in a QTextEdit -} -//! [0] +void examples(QString fileName) +{ + //! [0] + QMimeDatabase db; + QMimeType mime = db.mimeTypeForFile(fileName); + if (mime.inherits("text/plain")) { + // The file is plain text, we can display it in a QTextEdit + } + //! [0] -//! [1] -using namespace Qt::StringLiterals; -// ... -QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, "mime/packages"_L1, - QStandardPaths::LocateDirectory); -//! [1] + //! [1] + using namespace Qt::StringLiterals; + // ... + QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, "mime/packages"_L1, + QStandardPaths::LocateDirectory); + //! [1] +} +#if 0 //! [2] <?xml version="1.0" encoding="UTF-8"?> <mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info"> @@ -27,3 +35,4 @@ QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, "mime/packages"_L </mime-type> </mime-info> //! [2] +#endif diff --git a/src/corelib/doc/snippets/code/src_corelib_plugin_qlibrary.cpp b/src/corelib/doc/snippets/code/src_corelib_plugin_qlibrary.cpp index 6edb937208c..b5822fb29bb 100644 --- a/src/corelib/doc/snippets/code/src_corelib_plugin_qlibrary.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_plugin_qlibrary.cpp @@ -1,42 +1,42 @@ // Copyright (C) 2016 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -//! [0] -QLibrary myLib("mylib"); -typedef void (*MyPrototype)(); -MyPrototype myFunction = (MyPrototype) myLib.resolve("mysymbol"); -if (myFunction) - myFunction(); -//! [0] +#include <QLibrary> - -//! [1] -typedef void (*MyPrototype)(); -MyPrototype myFunction = - (MyPrototype) QLibrary::resolve("mylib", "mysymbol"); -if (myFunction) - myFunction(); -//! [1] - - -//! [2] -typedef int (*AvgFunction)(int, int); - -AvgFunction avg = (AvgFunction) library->resolve("avg"); -if (avg) - return avg(5, 8); -else - return -1; -//! [2] - - -//! [3] -extern "C" MY_EXPORT int avg(int a, int b) +int examples(QLibrary *library) { - return (a + b) / 2; + { + //! [0] + QLibrary myLib("mylib"); + typedef void (*MyPrototype)(); + MyPrototype myFunction = (MyPrototype) myLib.resolve("mysymbol"); + if (myFunction) + myFunction(); + //! [0] + } + + { + //! [1] + typedef void (*MyPrototype)(); + MyPrototype myFunction = + (MyPrototype) QLibrary::resolve("mylib", "mysymbol"); + if (myFunction) + myFunction(); + //! [1] + } + + { + //! [2] + typedef int (*AvgFunction)(int, int); + + AvgFunction avg = (AvgFunction) library->resolve("avg"); + if (avg) + return avg(5, 8); + else + return -1; + //! [2] + } } -//! [3] - //! [4] #ifdef Q_OS_WIN @@ -45,3 +45,10 @@ extern "C" MY_EXPORT int avg(int a, int b) #define MY_EXPORT #endif //! [4] + +//! [3] +extern "C" MY_EXPORT int avg(int a, int b) +{ + return (a + b) / 2; +} +//! [3] diff --git a/src/corelib/doc/snippets/code/src_corelib_plugin_quuid.cpp b/src/corelib/doc/snippets/code/src_corelib_plugin_quuid.cpp index 4d8f0b8d343..111901c03ed 100644 --- a/src/corelib/doc/snippets/code/src_corelib_plugin_quuid.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_plugin_quuid.cpp @@ -1,7 +1,12 @@ // Copyright (C) 2016 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -//! [0] -// {67C8770B-44F1-410A-AB9A-F9B5446F13EE} -QUuid IID_MyInterface(0x67c8770b, 0x44f1, 0x410a, 0xab, 0x9a, 0xf9, 0xb5, 0x44, 0x6f, 0x13, 0xee); -//! [0] +#include <QUuid> + +void example() +{ + //! [0] + // {67C8770B-44F1-410A-AB9A-F9B5446F13EE} + QUuid IID_MyInterface(0x67c8770b, 0x44f1, 0x410a, 0xab, 0x9a, 0xf9, 0xb5, 0x44, 0x6f, 0x13, 0xee); + //! [0] +} |
