### Install Example Source: https://doc.qt.io/qt-6.5/qttestlib-tutorial4-example.html Specifies the installation path for the QtTestLib tutorial 4 example. ```makefile target.path = $$[QT_INSTALL_EXAMPLES]/qtestlib/tutorial4 INSTALLS += target ``` -------------------------------- ### Basic QHttpServer Setup and Routing Source: https://doc.qt.io/qt-6.5/qhttpserver.html Demonstrates how to create a QHttpServer instance, define a route for the root path, and start the server. This is a fundamental example for getting started with QHttpServer. ```cpp QHttpServer server; server.route("/", [] () { return "hello world"; }); server.listen(); ``` -------------------------------- ### Configuring Example Install Path Source: https://doc.qt.io/qt-6.5/22-qdoc-configuration-generalvariables.html Sets the root path for project examples within the installed example directory. This path is used in conjunction with \"exampledirs\" and the \"example\" command to record correct paths in the example manifest file. ```qdoc exampledirs = ./snippets \ ../../../examples/mymodule examplesinstallpath = mymodule ``` -------------------------------- ### Specifying Example Install Path with \meta Source: https://doc.qt.io/qt-6.5/12-0-qdoc-commands-miscellaneous.html Use \meta {installpath} to specify the location of an installed example, overriding the configuration variable. ```cpp /*! \example helloworld \title Hello World Example \meta {installpath} {tutorials} */ ``` -------------------------------- ### Project File Setup Source: https://doc.qt.io/qt-6.5/qtquick3dphysics-material-material-pro.html This snippet shows the qmake project file configuration for the Qt Quick 3D Physics material example. It includes necessary modules, installation paths, source files, resources, and other files. ```qmake QT += quick quick3d target.path = $$[QT_INSTALL_EXAMPLES]/quick3dphysics/material INSTALLS += target SOURCES += \ main.cpp RESOURCES += \ qml.qrc OTHER_FILES += \ doc/src/*.* ``` -------------------------------- ### Core Translation Setup Source: https://doc.qt.io/qt-6.5/qtranslator.html This example demonstrates how to load a translation file and install it into the Qt application. Ensure the translator is created before the application's widgets. ```cpp int main(int argc, char *argv[]) { QApplication app(argc, argv); QTranslator translator; // look up e.g. :/i18n/myapp_de.qm if (translator.load(QLocale(), "myapp"_L1, "_"_L1, ":/i18n"_L1)) QCoreApplication::installTranslator(&translator); QPushButton hello(QCoreApplication::translate("main", "Hello world!")); hello.resize(100, 30); hello.show(); return app.exec(); } ``` -------------------------------- ### Building the Notepad Example with Ninja Source: https://doc.qt.io/qt-6.5/qtwidgets-tutorials-notepad-example.html This example shows the specific commands to build the Notepad example application on Windows using Ninja as the build generator. Ensure your Qt installation path and example source path are correct. ```bash md notepad-build cd notepad-build C:\Qt\6.5.12\msvc2019_64\bin\qt-cmake -GNinja C:\Examples\notepad ninja ``` -------------------------------- ### QUICK_TEST_MAIN_WITH_SETUP Example Source: https://doc.qt.io/qt-6.5/qquicktest.html Demonstrates setting up a Qt Quick Test application with a custom setup class. The Setup class provides slots for application and QML engine availability, as well as custom cleanup. ```cpp #include #include #include #include class Setup : public QObject { Q_OBJECT public: Setup() {} public slots: void applicationAvailable() { // Initialization that only requires the QGuiApplication object to be available } void qmlEngineAvailable(QQmlEngine *engine) { // Initialization requiring the QQmlEngine to be constructed engine->rootContext()->setContextProperty("myContextProperty", QVariant(true)); } void cleanupTestCase() { // Implement custom resource cleanup } }; QUICK_TEST_MAIN_WITH_SETUP(mytest, Setup) #include "src_qmltest_qquicktest.moc" ``` -------------------------------- ### Configure Example URL with Path Placeholder Source: https://doc.qt.io/qt-6.5/25-qdoc-configuration-derivedprojects.html This configuration demonstrates using a placeholder `\1` in the `url.examples` variable to include dynamic path components in the generated example URLs. The `examplesinstallpath` variable specifies the installation path for examples. ```qdocconf url.examples = "https://code.qt.io/cgit/qt/qtbase.git/tree/examples/\1?h=$QT_VER" examplesinstallpath = corelib ``` -------------------------------- ### Qt Quick 3D Project Setup Source: https://doc.qt.io/qt-6.5/qtquick3d-intro-intro-pro.html This snippet shows the essential qmake configuration for a Qt Quick 3D project. It includes adding the 'quick' and 'quick3d' modules, setting the installation path for examples, and specifying source and resource files. ```qmake QT += quick quick3d target.path = $$[QT_INSTALL_EXAMPLES]/quick3d/intro INSTALLS += target SOURCES += \ main.cpp RESOURCES += \ qml.qrc OTHER_FILES += \ doc/src/*.* ``` -------------------------------- ### Instancing Example Project Configuration Source: https://doc.qt.io/qt-6.5/qtquick3d-instancing-instancing-pro.html This .pro file configures the Qt Quick 3D Instanced Rendering Example. It specifies required Qt modules, installation paths, source files, and resources. ```qmake QT += quick quick3d target.path = $$[QT_INSTALL_EXAMPLES]/quick3d/instancing INSTALLS += target SOURCES += \ main.cpp RESOURCES += \ qml.qrc OTHER_FILES += \ doc/src/*.* ``` -------------------------------- ### Basic Image Capture Setup Source: https://doc.qt.io/qt-6.5/qimagecapture.html This snippet demonstrates the basic setup for using QImageCapture with a QCamera and QMediaCaptureSession. It shows how to initialize the objects, connect them, and start the camera. ```cpp QMediaCaptureSession captureSession; camera = new QCamera; captureSession.setCamera(camera); viewfinder = new QVideoWidget(); viewfinder->show(); captureSession.setVideoOutput(viewfinder); imageCapture = new QImageCapture(camera); captureSession.setImageCapture(imageCapture); camera->start(); //on shutter button pressed imageCapture->capture(); ``` -------------------------------- ### Basic View3D Setup with SceneEnvironment Source: https://doc.qt.io/qt-6.5/qml-qtquick3d-sceneenvironment.html A basic Qt Quick 3D View3D setup. This example demonstrates how to integrate a SceneEnvironment within a View3D item. ```qml import QtQuick import QtQuick3D import QtQuick3D.Helpers Item { width: 1280 height: 720 View3D { id: v3d anchors.fill: parent // SceneEnvironment properties would be set here // For example: // sceneEnvironment: SceneEnvironment { // aoEnabled: true // aoStrength: 75.0 // } } } ``` -------------------------------- ### Qt Quick 3D Lights Example Project File Source: https://doc.qt.io/qt-6.5/qtquick3d-lights-lights-pro.html This is the main project file (.pro) for the Qt Quick 3D Lights Example. It specifies the necessary Qt modules, installation paths, source files, resources, and other files required for the example. ```qmake QT += quick quick3d target.path = $$[QT_INSTALL_EXAMPLES]/quick3d/lights INSTALLS += target SOURCES += \ main.cpp RESOURCES += \ qml.qrc OTHER_FILES += \ doc/src/*.* ``` -------------------------------- ### Particles 3D Testbed Example Project File Source: https://doc.qt.io/qt-6.5/qtquick3d-particles3d-particles3d-pro.html This is the project file (.pro) for the Qt Quick 3D Particles 3D Testbed example. It specifies the required Qt modules, installation path, source files, resources, and other files needed for the example. ```qmake QT += quick quick3d target.path = $$[QT_INSTALL_EXAMPLES]/quick3d/particles3d INSTALLS += target SOURCES +=\ main.cpp RESOURCES +=\ qml.qrc OTHER_FILES +=\ doc/src/*.* ``` -------------------------------- ### Project File Configuration Source: https://doc.qt.io/qt-6.5/qtquick3d-lodhelper-lodhelper-pro.html Configures the Qt project file (.pro) for the Level of Detail Helper Example. It includes necessary Qt modules and sets the installation path for the example. ```pro QT += quick quick3d target.path = $$[QT_INSTALL_EXAMPLES]/quick3d/lodhelper INSTALLS += target SOURCES += main.cpp RESOURCES += qml.qrc ``` -------------------------------- ### Main Function Setup Source: https://doc.qt.io/qt-6.5/qtwidgets-painting-imagecomposition-example.html Instantiates QApplication and ImageComposer, then shows the composer. This is the entry point for the application. ```cpp int main(int argc, char *argv[]) { QApplication app(argc, argv); ImageComposer composer; composer.show(); return app.exec(); } ``` -------------------------------- ### Start Line Edits Example Client Source: https://doc.qt.io/qt-6.5/qtvirtualkeyboard-deployment-guide.html Starts the Line Edits example application as a Wayland client. ```bash ./lineedits -platform wayland ``` -------------------------------- ### Main Application Entry Point Source: https://doc.qt.io/qt-6.5/remoteobjects-example-static-source.html Sets up the QCoreApplication, instantiates the SimpleSwitch source, creates the QRemoteObjectHost, enables remoting, and starts the event loop. ```cpp #include #include "simpleswitch.h" int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); SimpleSwitch srcSwitch; // create simple switch // Create host node without Registry: QRemoteObjectHost srcNode(QUrl(QStringLiteral("local:replica"))); srcNode.enableRemoting(&srcSwitch); // enable remoting/sharing return a.exec(); } ``` -------------------------------- ### Main Application Entry Point Source: https://doc.qt.io/qt-6.5/qtquick3d-bakedlightmap-main-cpp.html Sets up the Qt Quick 3D application, loads the QML file, and starts the event loop. Includes necessary headers and initializes the application. ```cpp #include #include #include int main(int argc, char *argv[]) { qputenv("QT_QUICK_CONTROLS_STYLE", "Basic"); QGuiApplication app(argc, argv); QSurfaceFormat::setDefaultFormat(QQuick3D::idealSurfaceFormat()); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); if (engine.rootObjects().isEmpty()) return -1; return app.exec(); } ``` -------------------------------- ### Simple Fog Example Project File Source: https://doc.qt.io/qt-6.5/qtquick3d-simplefog-simplefog-pro.html This is the .pro file for the Qt Quick 3D Simple Fog Example. It specifies the required Qt modules, installation path, source files, resources, and other files. ```qmake QT += quick quick3d target.path = $$[QT_INSTALL_EXAMPLES]/quick3d/simplefog INSTALLS += target SOURCES += main.cpp RESOURCES += qml.qrc OTHER_FILES += doc/src/*.* ``` -------------------------------- ### C++ Application Setup Source: https://doc.qt.io/qt-6.5/qtlocation-minimal-map-example.html Sets up the QGuiApplication and QQmlApplicationEngine to load the main QML file. This is the standard entry point for Qt Quick applications. ```cpp #include #include ``` ```cpp int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); return app.exec(); } ``` -------------------------------- ### Example Usage of qt_generate_deploy_app_script Source: https://doc.qt.io/qt-6.5/qt-generate-deploy-app-script.html Demonstrates how to use `qt_generate_deploy_app_script` within a CMake project to generate a deployment script and install it. This example sets up an executable, installs it, generates the deployment script, and then installs that script. ```cmake cmake_minimum_required(VERSION 3.16...3.22) project(MyThings) find_package(Qt6 REQUIRED COMPONENTS Core) qt_standard_project_setup() qt_add_executable(MyApp main.cpp) install(TARGETS MyApp BUNDLE DESTINATION . RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) qt_generate_deploy_app_script( TARGET MyApp OUTPUT_SCRIPT deploy_script NO_UNSUPPORTED_PLATFORM_ERROR ) install(SCRIPT ${deploy_script}) ``` -------------------------------- ### Main Function Setup and Window Initialization Source: https://doc.qt.io/qt-6.5/qtopengl-openglwindow-example.html Initializes the QGuiApplication, configures surface format for antialiasing, creates and shows the TriangleWindow, and enables animation. ```cpp int main(int argc, char **argv) { QGuiApplication app(argc, argv); QSurfaceFormat format; format.setSamples(16); TriangleWindow window; window.setFormat(format); window.resize(640, 480); window.show(); window.setAnimating(true); return app.exec(); } ``` -------------------------------- ### Get and Set Start Address Source: https://doc.qt.io/qt-6.5/qmodbusdataunit.html Manage the starting address of the Modbus data unit. Use startAddress() to get the current address and setStartAddress() to modify it. ```c++ int startAddress() const ``` ```c++ void setStartAddress(int _address_) ``` -------------------------------- ### Direct Approach: Setting up UI in main.cpp Source: https://doc.qt.io/qt-6.5/designer-using-a-ui-file.html This C++ code demonstrates the direct approach to using a UI file. It includes the generated UI header, creates a QWidget, instantiates the UI object, and calls `setupUi` to populate the widget with the UI elements defined in the `.ui` file. This method is suitable for simple, self-contained components. ```cpp #include "ui_calculatorform.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget widget; Ui::CalculatorForm ui; ui.setupUi(&widget); widget.show(); return app.exec(); } ``` -------------------------------- ### Get Start Timestamp Source: https://doc.qt.io/qt-6.5/qopcuahistoryreadrawrequest.html Returns the start timestamp for the historical data range. ```cpp QDateTime startTimestamp() const ``` -------------------------------- ### Setup Data Source: https://doc.qt.io/qt-6.5/qhelpenginecore.html Initialize the help engine's data. Emits setupStarted() and setupFinished() signals. ```cpp bool setupData() ``` -------------------------------- ### Main Window and Viewport Setup Source: https://doc.qt.io/qt-6.5/qtquick3d-lodhelper-main-qml.html Sets up the main window, View3D, camera, and environment for the Qt Quick 3D scene. Includes camera animation for dynamic viewing. ```QML import QtQuick import QtQuick3D import QtQuick3D.Helpers Window { id: window width: 1280 height: 720 visible: true View3D { id: view anchors.fill: parent environment: SceneEnvironment { clearColor: "black" backgroundMode: SceneEnvironment.Color antialiasingMode: SceneEnvironment.MSAA antialiasingQuality: SceneEnvironment.High } PerspectiveCamera { id: camera position: Qt.vector3d(0, 10, 300) clipNear: 1.0 NumberAnimation on z { from: 200 to: -100 duration: 40 * 1000 } } DirectionalLight { eulerRotation.x: -30 eulerRotation.y: -70 ambientColor: Qt.rgba(0.5, 0.5, 0.5, 1.0) } RandomInstancing { id: randomInstancing instanceCount: 800 position: InstanceRange { from: Qt.vector3d(-200, 0, -200) to: Qt.vector3d(200, 1, 200) } scale: InstanceRange { from: Qt.vector3d(10, 10, 10) to: Qt.vector3d(10, 10, 10) } rotation: InstanceRange { from: Qt.vector3d(0, 0, 0) to: Qt.vector3d(0, 0, 0) } color: InstanceRange { from: "grey" to: "white" proportional: true } randomSeed: 2021 } PrincipledMaterial { id: marbleMaterial baseColorMap: Texture { source: "maps/baseColor.png" generateMipmaps: true mipFilter: Texture.Linear } opacityChannel: Material.A metalnessMap: Texture { source: "maps/occlusionRoughnessMetallic.png" generateMipmaps: true mipFilter: Texture.Linear } metalnessChannel: Material.B roughnessMap: Texture { source: "maps/occlusionRoughnessMetallic.png" generateMipmaps: true mipFilter: Texture.Linear } roughnessChannel: Material.G metalness: 1 roughness: 1 normalMap: Texture { source: "maps/normal.png" generateMipmaps: true mipFilter: Texture.Linear } } LodManager { camera: camera distances: [100, 140, 180] fadeDistance: 10 Model { scale: Qt.vector3d(100, 100, 100); source: "meshes/marble_bust_01_LOD_0.mesh" materials: marbleMaterial } Model { scale: Qt.vector3d(100, 100, 100); source: "meshes/marble_bust_01_LOD_1.mesh" materials: marbleMaterial } Model { scale: Qt.vector3d(100, 100, 100); source: "meshes/marble_bust_01_LOD_2.mesh" materials: marbleMaterial } Model { scale: Qt.vector3d(100, 100, 100); source: "meshes/marble_bust_01_LOD_3.mesh" materials: marbleMaterial } } LodManager { camera: camera distances: [50, 100, 150] Model { instancing: randomInstancing source: "#Sphere" materials: [ PrincipledMaterial { metalness: 0 roughness: 1 baseColor: "red" } ] scale: Qt.vector3d(0.005, 0.005, 0.005) } Model { instancing: randomInstancing source: "#Cylinder" materials: [ PrincipledMaterial { metalness: 0 roughness: 1 baseColor: "orange" } ] scale: Qt.vector3d(0.005, 0.005, 0.005) } Model { instancing: randomInstancing source: "#Cube" materials: [ PrincipledMaterial { metalness: 0 roughness: 1 baseColor: "yellow" } ] scale: Qt.vector3d(0.005, 0.005, 0.005) } Model { instancing: randomInstancing source: "#Rectangle" materials: [ ``` -------------------------------- ### Get Y-coordinate of Start Point Source: https://doc.qt.io/qt-6.5/qlinef.html Retrieves the y-coordinate of the line's starting point. ```cpp qreal y1 = line.y1(); ``` -------------------------------- ### Get X-coordinate of Start Point Source: https://doc.qt.io/qt-6.5/qlinef.html Retrieves the x-coordinate of the line's starting point. ```cpp qreal x1 = line.x1(); ``` -------------------------------- ### Initialize ExampleShell Source: https://doc.qt.io/qt-6.5/qtwaylandcompositor-custom-shell-example.html Initializes the ExampleShell extension by registering it with the compositor and initializing the protocol extension itself. ```cpp void ExampleShell::initialize() { QWaylandCompositorExtensionTemplate::initialize(); QWaylandCompositor *compositor = static_cast(extensionContainer()); if (!compositor) { qWarning() << "Failed to find QWaylandCompositor when initializing ExampleShell"; return; } init(compositor->display(), 1); } ``` -------------------------------- ### Get Start Point of QLineF Source: https://doc.qt.io/qt-6.5/qlinef.html Retrieves the starting point of the line as a QPointF object. ```cpp QPointF startPoint = line.p1(); ``` -------------------------------- ### Basic Window Setup with Principled Material Source: https://doc.qt.io/qt-6.5/qtquick3d-principledmaterial-main-qml.html Sets up the main window, background image, and split view for the Qt Quick 3D application. It initializes the environment with lighting and antialiasing. ```qml // Copyright (C) 2022 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause import QtQuick import QtQuick3D import QtQuick3D.Effects import QtQuick3D.Helpers import QtQuick.Controls import QtQuick.Layouts Window { id: window width: 1280 height: 720 visible: true title: "Principled Materials Example" //color: "black" color: "#848895" Image { anchors.fill: parent source: "maps/grid.png" fillMode: Image.Tile horizontalAlignment: Image.AlignLeft verticalAlignment: Image.AlignTop } SplitView { id: splitView anchors.fill: parent Page { id: toolPage SplitView.fillHeight: true SplitView.preferredWidth: 420 SplitView.minimumWidth: 300 header: TabBar { id: tabBar TabButton { text: "Basics" } TabButton { text: "Alpha" } TabButton { text: "Details" } TabButton { text: "Clearcoat" } TabButton { text: "Refraction" } TabButton { text: "Special" } } StackLayout { id: toolPageSwipeView anchors.fill: parent anchors.margins: 10 currentIndex: tabBar.currentIndex BasicsPane { id: basicsPane principledMaterial: basicMaterial specularGlossyMaterial: specularGlossyMaterial } AlphaPane { targetMaterial: viewport.specularGlossyMode ? specularGlossyMaterial : basicMaterial specularGlossyMode: viewport.specularGlossyMode } DetailsPane { targetMaterial: viewport.specularGlossyMode ? specularGlossyMaterial : basicMaterial view3D: viewport } ClearcoatPane { targetMaterial: viewport.specularGlossyMode ? specularGlossyMaterial : basicMaterial } RefractionPane { targetMaterial: viewport.specularGlossyMode ? specularGlossyMaterial : basicMaterial specularGlossyMode: viewport.specularGlossyMode } SpecialPane { targetMaterial: viewport.specularGlossyMode ? specularGlossyMaterial : basicMaterial linesModel: linesLogo pointsModel: pointsLogo specularGlossyMode: viewport.specularGlossyMode } } } View3D { id: viewport SplitView.fillHeight: true SplitView.fillWidth: true SplitView.minimumWidth: splitView.width * 0.5 environment: SceneEnvironment { property bool enableEffects: false antialiasingMode: SceneEnvironment.MSAA antialiasingQuality: SceneEnvironment.High lightProbe: Texture { source: "maps/OpenfootageNET_garage-1024.hdr" } effects: enableEffects ? [bloom, scurveTonemap] : [] backgroundMode: SceneEnvironment.SkyBox SCurveTonemap { id: scurveTonemap } HDRBloomTonemap { id: bloom } } Node { id: originNode PerspectiveCamera { id: cameraNode z: 600 clipNear: 1 clipFar: 10000 } } property bool specularGlossyMode: basicsPane.specularGlossyMode PrincipledMaterial { id: basicMaterial baseColor: "red" } SpecularGlossyMaterial { id: specularGlossyMaterial property alias baseColor: specularGlossyMaterial.albedoColor property real specularAmount: 1.0 property real specularTint: 1.0 specularColor: Qt.rgba(0.22, 0.22, 0.22, 1.0) albedoColor: "red" } Model { id: cube source: "#Cube" materials: viewport.specularGlossyMode ? specularGlossyMaterial : basicMaterial pickable: true } Model { id: sphereModel x: -200 scale: Qt.vector3d(1.5, 1.5, 1.5) source: "#Sphere" ``` -------------------------------- ### Get Start Page ID Source: https://doc.qt.io/qt-6.5/qwizard.html Returns the ID of the first page to be displayed when the wizard is started. ```cpp int startId() const ``` -------------------------------- ### Main Application Entry Point Source: https://doc.qt.io/qt-6.5/qtscxml-sudoku-example.html Sets up the QApplication, Sudoku state machine, and MainWindow. It starts the state machine, shows the main window, and enters the Qt event loop. ```cpp #include "mainwindow.h" #include "sudoku.h" #include int main(int argc, char **argv) { QApplication app(argc, argv); Sudoku machine; MainWindow mainWindow(&machine); machine.start(); mainWindow.show(); return app.exec(); } ``` -------------------------------- ### Get QTimeLine Start Frame Source: https://doc.qt.io/qt-6.5/qtimeline.html Retrieve the starting frame of the timeline's frame range. ```cpp int startFrame() const ``` -------------------------------- ### Define Extra Commands for Install Set (Unix) Source: https://doc.qt.io/qt-6.5/qmake-advanced-usage.html Adds platform-specific commands to be executed before installation for a given install set. This example is specific to Unix. ```qmake unix:documentation.extra = create_docs; mv master.doc toc.doc ``` -------------------------------- ### Main Function Setup Source: https://doc.qt.io/qt-6.5/qtwidgets-itemviews-spinboxdelegate-example.html Initializes the Qt application, creates a standard item model, sets up a table view, and associates a custom SpinBoxDelegate with the table view. ```cpp int main(int argc, char *argv[]) { QApplication app(argc, argv); QStandardItemModel model(4, 2); QTableView tableView; tableView.setModel(&model); SpinBoxDelegate delegate; tableView.setItemDelegate(&delegate); ``` -------------------------------- ### Get AutoPlay Property Source: https://doc.qt.io/qt-6.5/qspatialsound.html Returns whether the sound should automatically start playing when a source gets specified. ```cpp bool autoPlay() const ``` -------------------------------- ### Get Elapsed Time in Microseconds Source: https://doc.qt.io/qt-6.5/qaudiosource.html Get the time elapsed since the audio source started, in microseconds. ```cpp qint64 elapsedUSecs() const ``` -------------------------------- ### Main Function Setup Source: https://doc.qt.io/qt-6.5/qtwidgets-widgets-tablet-example.html Initializes the TabletApplication, creates a TabletCanvas and MainWindow, and starts the application event loop. ```cpp int main(int argv, char *args[]) { TabletApplication app(argv, args); TabletCanvas *canvas = new TabletCanvas; app.setCanvas(canvas); MainWindow mainWindow(canvas); mainWindow.resize(500, 500); mainWindow.show(); return app.exec(); } ``` -------------------------------- ### List Starting at a Specific Character Source: https://doc.qt.io/qt-6.5/10-qdoc-commands-tablesandlists.html Explains how to start a list at a specific character or number by providing it as an argument to the \list command. This example starts numbering at 'G'. ```qdoc /*! \list G \li How to Learn Qt \li Installation \li Tutorial and Examples \endlist */ ``` -------------------------------- ### Query Specific Installation Path Source: https://doc.qt.io/qt-6.5/qmake-environment-reference.html Example of querying the installation prefix for the current qmake version using the QT_INSTALL_PREFIX property. ```bash qmake -query "QT_INSTALL_PREFIX" ``` -------------------------------- ### Main Application Entry Point Source: https://doc.qt.io/qt-6.5/qtquick-scenegraph-openglunderqml-example.html Sets up the Qt Quick application, configures OpenGL as the graphics API, and loads the main QML file. ```cpp int main(int argc, char **argv) { QGuiApplication app(argc, argv); QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL); QQuickView view; view.setResizeMode(QQuickView::SizeRootObjectToView); view.setSource(QUrl("qrc:///scenegraph/openglunderqml/main.qml")); view.show(); return QGuiApplication::exec(); } ``` -------------------------------- ### Basic State Machine Setup Source: https://doc.qt.io/qt-6.5/qml-qtqml-statemachine-state.html This example demonstrates how to set up a basic StateMachine with an initial state in QML. It requires importing QtQuick and QtQml.StateMachine. ```qml import QtQuick import QtQml.StateMachine as DSM Rectangle { DSM.StateMachine { id: stateMachine initialState: state running: true DSM.State { id: state } } } ``` -------------------------------- ### Get Start Bit Source: https://doc.qt.io/qt-6.5/qcanuniqueiddescription.html Returns the start bit position of the unique identifier within the data source. Bits are counted from the LSB. ```cpp quint16 startBit() const ``` -------------------------------- ### Basic Application Window Setup Source: https://doc.qt.io/qt-6.5/qml-qtquick-application.html This snippet demonstrates how to set up a basic QML Window, using Application properties for the title and connecting to the aboutToQuit signal. ```qml import QtQuick Window { id: root visible: true width: 800 height: 680 title: `${Application.name} (${Application.version})` Connections { target: Application function onAboutToQuit() { console.log("Bye!") } } } ``` -------------------------------- ### Specify Framework Headers for Installation Source: https://doc.qt.io/qt-6.5/qmake-platform-notes.html Use QMAKE_BUNDLE_DATA to specify header files to be installed with a library bundle. This example defines headers for a framework. ```qmake FRAMEWORK_HEADERS.version = Versions FRAMEWORK_HEADERS.files = path/to/header_one.h path/to/header_two.h FRAMEWORK_HEADERS.path = Headers QMAKE_BUNDLE_DATA += FRAMEWORK_HEADERS ``` -------------------------------- ### Basic Window Setup with View3D Source: https://doc.qt.io/qt-6.5/qtquick3d-custommaterial-main-qml.html Sets up the main window and the View3D component for rendering. Includes camera, environment, and lighting configurations. ```qml // Copyright (C) 2020 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause import QtQuick import QtQuick3D import QtQuick.Controls import QtQuick.Layouts Window { id: window width: 1280 height: 720 visible: true title: "Custom Materials Example" View3D { id: v3d anchors.fill: parent camera: camera environment: SceneEnvironment { backgroundMode: SceneEnvironment.SkyBox probeExposure: 2 lightProbe: Texture { source: "maps/OpenfootageNET_lowerAustria01-1024.hdr" } } PerspectiveCamera { id: camera fieldOfView: 45 position: Qt.vector3d(0, 100, 900) } SpotLight { position: Qt.vector3d(0, 500, 0) eulerRotation.x: -60 color: Qt.rgba(1.0, 1.0, 0.1, 1.0) brightness: 50 castsShadow: true shadowMapQuality: Light.ShadowMapQualityHigh } property real globalRotation: 0 NumberAnimation on globalRotation { from: 0 to: 360 duration: 27000 loops: Animation.Infinite } property real radius: 400 property real separation: 360/5 Model { id: floor source: "#Rectangle" y: -200 scale: Qt.vector3d(15, 15, 1) eulerRotation.x: -90 materials: [ DefaultMaterial { diffuseColor: "white" } ] } // Start with a simple material, using the built-in implementation for everything. Node { eulerRotation.y: v3d.globalRotation Model { source: "weirdShape.mesh" scale: Qt.vector3d(100, 100, 100) rotation: Quaternion.fromEulerAngles(-90, 0, 0) x: v3d.radius materials: [ CustomMaterial { shadingMode: CustomMaterial.Shaded fragmentShader: "material_simple.frag" property color uDiffuse: "fuchsia" property real uSpecular: 1.0 } ] } } // A metallic material using defaults for everything, except ambient light, and no uniforms. Node { eulerRotation.y: v3d.globalRotation + v3d.separation * 1 Model { source: "weirdShape.mesh" scale: Qt.vector3d(100, 100, 100) rotation: Quaternion.fromEulerAngles(-90, 0, 0) x: v3d.radius materials: [ CustomMaterial { shadingMode: CustomMaterial.Shaded fragmentShader: "material_metallic.frag" } ] } } // A material with custom handling of all the lights, but still using // the built-in specular function. Node { eulerRotation.y: v3d.globalRotation + v3d.separation * 2 Model { source: "weirdShape.mesh" scale: Qt.vector3d(100, 100, 100) rotation: Quaternion.fromEulerAngles(-90, 0, 0) x: v3d.radius materials: [ CustomMaterial { shadingMode: CustomMaterial.Shaded fragmentShader: "material_customlights.frag" property color uDiffuse: "orange" property real uShininess: 150 } ] } } // Custom handling of everything, including specular. Node { eulerRotation.y: v3d.globalRotation + v3d.separation * 3 Model { source: "weirdShape.mesh" scale: Qt.vector3d(100, 100, 100) rotation: Quaternion.fromEulerAngles(-90, 0, 0) x: v3d.radius materials: [ CustomMaterial { shadingMode: CustomMaterial.Shaded fragmentShader: "material_customspecular.frag" property color uDiffuse: "green" property real uShininess: 150 } ] } } // Custom lights, plus custom vertex shader Node { eulerRotation.y: v3d.globalRotation + v3d.separation * 4 Model { source: "weirdShape.mesh" scale: Qt.vector3d(100, 100, 100) rotation: Quaternion.fromEulerAngles(-90, 0, 0) x: v3d.radius materials: [ CustomMaterial { ``` -------------------------------- ### Get Substring by Start and Length Source: https://doc.qt.io/qt-6.5/qlatin1stringview.html Returns a substring of a specified length starting at a given position. If the start position exceeds the string length, an empty view is returned. If fewer characters are available than requested, all available characters from the start position are returned. ```cpp QLatin1StringView QLatin1StringView::mid(qsizetype _start_ , qsizetype _length_ = -1) const ``` -------------------------------- ### Example Main Application File (main.cpp) Source: https://doc.qt.io/qt-6.5/qmake-precompiledheaders.html The main entry point for the application. It initializes QApplication, creates instances of MyObject and MyDialog, connects a signal to a slot, and shows the dialog. ```cpp #include #include #include #include "myobject.h" #include "mydialog.h" int main(int argc, char **argv) { QApplication app(argc, argv); MyObject obj; MyDialog dialog; dialog.connect(dialog.aButton, SIGNAL(clicked()), SLOT(close())); dialog.show(); return app.exec(); } ``` -------------------------------- ### Starting Animation on Ready Status Source: https://doc.qt.io/qt-6.5/qml-qt-labs-lottieqt-lottieanimation.html This example shows how to automatically start a Lottie animation once it has been successfully loaded. It uses the `onStatusChanged` signal handler to check if the animation `status` is `Ready` before calling the `start()` function. ```qml LottieAnimation { source: "animation.json" autoPlay: false onStatusChanged: { if (status === LottieAnimation.Ready) start(); } } ``` -------------------------------- ### Complete Example .pro File for Third-Party Library Integration Source: https://doc.qt.io/qt-6.5/third-party-libraries.html This is a complete .pro file demonstrating how to set the target name, template, include paths, source files, and library linking for a third-party library. ```qmake TARGET = MyQtApp TEMPLATE = app INCLUDEPATH += 3rdparty/CatWhisperer/include SOURCES += src/main.cpp LIBS += -L"3rdparty/CatWhisperer/lib" -lCatWhisperer ``` -------------------------------- ### Start Dockerized CoAP Test Server Source: https://doc.qt.io/qt-6.5/qtcoap-simplecoapclient-example.html Pulls and starts a Docker container for the Californium CoAP test server. Ensure Docker is installed and running. ```bash docker run --name coap-test-server -d --rm -p 5683:5683/udp -p 5684:5684/udp tqtc/coap-californium-test-server:3.8.0 ``` -------------------------------- ### Configure Qt to Build Examples and Tests Source: https://doc.qt.io/qt-6.5/configure-options.html Shows how to use the -make option with configure to include examples and tests in the build process. ```bash ~/qt-source/configure -make examples -make tests ``` -------------------------------- ### Get Start of Day (Local Time) Source: https://doc.qt.io/qt-6.5/qdate.html Returns the start moment of the day using the system's local time. This is an overloaded function for convenience. ```cpp QDateTime QDate::startOfDay() const ``` -------------------------------- ### Build Configuration for Mass Example Source: https://doc.qt.io/qt-6.5/qtquick3dphysics-mass-mass-pro.html Configures the Qt build system for the mass example, specifying modules, installation paths, source files, and resources. ```qmake QT += quick quick3d target.path = $$[QT_INSTALL_EXAMPLES]/quick3dphysics/mass INSTALLS += target SOURCES += \ main.cpp RESOURCES += \ qml.qrc OTHER_FILES += \ doc/src/*.* ``` -------------------------------- ### Impeller Example CMakeLists.txt Source: https://doc.qt.io/qt-6.5/qtquick3dphysics-impeller-cmakelists-txt.html Configures the build for the Impeller example, including project settings, dependencies on Qt modules, resource compilation, and installation rules. ```cmake # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: BSD-3-Clause cmake_minimum_required(VERSION 3.14) project(example_impeller LANGUAGES CXX) set(CMAKE_AUTOMOC ON) if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/quick3dphysics/${PROJECT_NAME}") find_package(Qt6 REQUIRED COMPONENTS Core Gui Quick Quick3D Quick3DPhysics) qt_add_executable(${PROJECT_NAME} main.cpp ) set_target_properties(${PROJECT_NAME} PROPERTIES WIN32_EXECUTABLE TRUE MACOSX_BUNDLE TRUE ) target_link_libraries(${PROJECT_NAME} PUBLIC Qt::Core Qt::Gui Qt::Quick Qt::Quick3D Qt::Quick3DPhysics ) # Resources: set(qml_resource_files "main.qml" ) qt_add_resources(${PROJECT_NAME} "qml" PREFIX "/" FILES ${qml_resource_files} ) install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) ``` -------------------------------- ### Initialize QHelpEngineCore Source: https://doc.qt.io/qt-6.5/qhelpenginecore.html Initialize the help engine with a collection file and an optional parent object. ```cpp QHelpEngineCore(const QString &_collectionFile_ , QObject *_parent_ = nullptr) ``` -------------------------------- ### Example: Check for Drag Start Source: https://doc.qt.io/qt-6.5/qapplication.html This example demonstrates how to use QApplication::startDragDistance() to determine if a drag and drop operation should be initiated based on the mouse movement. ```cpp if ((startPos - currentPos).manhattanLength() >= QApplication::startDragDistance()) startTheDrag(); ``` -------------------------------- ### Main Application Entry Point Source: https://doc.qt.io/qt-6.5/activeqt-activeqt-qutlook-example.html Sets up the Qt application, instantiates the AddressView, and starts the event loop. This is the main entry point for the Qutlook example. ```cpp #include "addressview.h" #include int main(int argc, char *argv[]) { QApplication a(argc, argv); AddressView view; view.setWindowTitle(QObject::tr("Qt Example - Looking at Outlook")); view.show(); return a.exec(); } ``` -------------------------------- ### Initialize Qt 3D Window and Scene Source: https://doc.qt.io/qt-6.5/qt3d-simple-cpp-example.html Set up the main application window, camera, and camera controller, then display the scene. ```cpp int main(int argc, char* argv[]) { QGuiApplication app(argc, argv); Qt3DExtras::Qt3DWindow view; Qt3DCore::QEntity *scene = createScene(); // Camera Qt3DRender::QCamera *camera = view.camera(); camera->lens()->setPerspectiveProjection(45.0f, 16.0f/9.0f, 0.1f, 1000.0f); camera->setPosition(QVector3D(0, 0, 40.0f)); camera->setViewCenter(QVector3D(0, 0, 0)); // For camera controls Qt3DExtras::QOrbitCameraController *camController = new Qt3DExtras::QOrbitCameraController(scene); camController->setLinearSpeed( 50.0f ); camController->setLookSpeed( 180.0f ); camController->setCamera(camera); view.setRootEntity(scene); view.show(); return app.exec(); } ``` -------------------------------- ### Basic HTTP Server Setup Source: https://doc.qt.io/qt-6.5/qthttpserver-simple-main-cpp.html Sets up a basic HTTP server with a root route that returns 'Hello world'. This is a starting point for any HTTP server application. ```cpp #include #include int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); QHttpServer httpServer; httpServer.route("", []() { return "Hello world"; }); const auto port = httpServer.listen(QHostAddress::Any); if (!port) { qWarning() << QCoreApplication::translate("QHttpServerExample", "Server failed to listen on a port."); return -1; } qInfo().noquote() << QCoreApplication::translate("QHttpServerExample", "Running on http://127.0.0.1:%1/ (Press CTRL+C to quit)") .arg(port); return app.exec(); } ``` -------------------------------- ### Impeller Example Scene Setup Source: https://doc.qt.io/qt-6.5/qtquick3dphysics-impeller-main-qml.html Sets up the main scene for the impeller example, including the physics world, camera, lighting, and various rigid bodies. ```qml // Copyright (C) 2022 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause import QtQuick import QtQuick3D import QtQuick3D.Physics Window { width: 640 height: 480 visible: true title: qsTr("Qt Quick 3D Physics - Impeller") PhysicsWorld { gravity: Qt.vector3d(0, -490, 0) scene: viewport.scene } View3D { id: viewport anchors.fill: parent environment: SceneEnvironment { clearColor: "#d6dbdf" backgroundMode: SceneEnvironment.Color } PerspectiveCamera { position: Qt.vector3d(0, 200, 1000) clipFar: 2000 clipNear: 1 } DirectionalLight { eulerRotation.x: -45 eulerRotation.y: 45 castsShadow: true brightness: 1 shadowFactor: 100 } StaticRigidBody { position: Qt.vector3d(0, -100, 0) eulerRotation: Qt.vector3d(-90, 0, 0) collisionShapes: PlaneShape {} Model { source: "#Rectangle" scale: Qt.vector3d(500, 500, 1) materials: PrincipledMaterial { baseColor: "green" } castsShadows: false receivesShadows: true } } DynamicRigidBody { id: sphere massMode: DynamicRigidBody.CustomDensity density: 0.00001 position: Qt.vector3d(0, 600, 0) property bool inArea: false sendContactReports: true receiveTriggerReports: true onEnteredTriggerBody: { inArea = true } onExitedTriggerBody: { inArea = false } collisionShapes: SphereShape {} Model { source: "#Sphere" materials: PrincipledMaterial { baseColor: sphere.inArea ? "yellow" : "red" } } } TriggerBody { position: Qt.vector3d(0, 350, 0) scale: Qt.vector3d(1, 2, 1) collisionShapes: BoxShape { id: boxShape } Model { source: "#Cube" materials: PrincipledMaterial { baseColor: Qt.rgba(1, 0, 1, 0.2) alphaMode: PrincipledMaterial.Blend } } } StaticRigidBody { position: Qt.vector3d(0, 0, 0) scale: Qt.vector3d(2, 2, 2) receiveContactReports: true collisionShapes: SphereShape {} Model { source: "#Sphere" materials: PrincipledMaterial { baseColor: "blue" } } onBodyContact: (body, positions, impulses, normals) => { for (var normal of normals) { let velocity = normal.times(-700) body.setLinearVelocity(velocity) } } } } } ``` -------------------------------- ### Basic SpotLight Example Source: https://doc.qt.io/qt-6.5/qml-qtquick3d-spotlight.html A simple scene setup with a SpotLight positioned and configured for basic illumination. This example demonstrates the default behavior and basic properties. ```qml import QtQuick import QtQuick3D View3D { anchors.fill: parent PerspectiveCamera { z: 600 } SpotLight { z: 300 brightness: 10 ambientColor: Qt.rgba(0.1, 0.1, 0.1, 1.0) } Model { source: "#Rectangle" scale: Qt.vector3d(10, 10, 10) z: -100 materials: PrincipledMaterial { } } Model { source: "#Sphere" scale: Qt.vector3d(2, 2, 2) materials: PrincipledMaterial { baseColor: "#40c060" roughness: 0.1 } } } ```