From c6540cb6e41aea6b4152109cade9aa145884a8f6 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Mon, 15 May 2023 12:24:50 +0200 Subject: Doc cleanup: remove old gettingStarted tutorial, move doc file The Qt getting started tutorial is based on the "notepad" example files in this directory, the gettingStarted/gsQt files are completely unused and not referenced in documentation. Pick-to: 6.5 Change-Id: If8caebd2c8359c81f94f72ef40a1cf92a021a83f Reviewed-by: Safiyyah Moosa Reviewed-by: Axel Spoerl --- examples/widgets/tutorials/CMakeLists.txt | 1 - .../tutorials/gettingStarted/CMakeLists.txt | 1 - .../tutorials/gettingStarted/gettingStarted.pro | 4 - .../tutorials/gettingStarted/gsQt/CMakeLists.txt | 8 - .../widgets/tutorials/gettingStarted/gsQt/gsqt.pro | 7 - .../gettingStarted/gsQt/part1/CMakeLists.txt | 36 -- .../tutorials/gettingStarted/gsQt/part1/main.cpp | 15 - .../tutorials/gettingStarted/gsQt/part1/part1.pro | 8 - .../gettingStarted/gsQt/part2/CMakeLists.txt | 36 -- .../tutorials/gettingStarted/gsQt/part2/main.cpp | 27 -- .../tutorials/gettingStarted/gsQt/part2/part2.pro | 8 - .../gettingStarted/gsQt/part3/CMakeLists.txt | 36 -- .../tutorials/gettingStarted/gsQt/part3/main.cpp | 61 --- .../tutorials/gettingStarted/gsQt/part3/part3.pro | 8 - .../gettingStarted/gsQt/part4/CMakeLists.txt | 36 -- .../tutorials/gettingStarted/gsQt/part4/main.cpp | 73 --- .../tutorials/gettingStarted/gsQt/part4/part4.pro | 8 - .../gettingStarted/gsQt/part5/CMakeLists.txt | 36 -- .../tutorials/gettingStarted/gsQt/part5/main.cpp | 99 ---- .../tutorials/gettingStarted/gsQt/part5/part5.pro | 8 - examples/widgets/tutorials/gettingstartedqt.qdoc | 504 --------------------- .../tutorials/notepad/gettingstartedqt.qdoc | 504 +++++++++++++++++++++ examples/widgets/tutorials/tutorials.pro | 2 +- 23 files changed, 505 insertions(+), 1021 deletions(-) delete mode 100644 examples/widgets/tutorials/gettingStarted/CMakeLists.txt delete mode 100644 examples/widgets/tutorials/gettingStarted/gettingStarted.pro delete mode 100644 examples/widgets/tutorials/gettingStarted/gsQt/CMakeLists.txt delete mode 100644 examples/widgets/tutorials/gettingStarted/gsQt/gsqt.pro delete mode 100644 examples/widgets/tutorials/gettingStarted/gsQt/part1/CMakeLists.txt delete mode 100644 examples/widgets/tutorials/gettingStarted/gsQt/part1/main.cpp delete mode 100644 examples/widgets/tutorials/gettingStarted/gsQt/part1/part1.pro delete mode 100644 examples/widgets/tutorials/gettingStarted/gsQt/part2/CMakeLists.txt delete mode 100644 examples/widgets/tutorials/gettingStarted/gsQt/part2/main.cpp delete mode 100644 examples/widgets/tutorials/gettingStarted/gsQt/part2/part2.pro delete mode 100644 examples/widgets/tutorials/gettingStarted/gsQt/part3/CMakeLists.txt delete mode 100644 examples/widgets/tutorials/gettingStarted/gsQt/part3/main.cpp delete mode 100644 examples/widgets/tutorials/gettingStarted/gsQt/part3/part3.pro delete mode 100644 examples/widgets/tutorials/gettingStarted/gsQt/part4/CMakeLists.txt delete mode 100644 examples/widgets/tutorials/gettingStarted/gsQt/part4/main.cpp delete mode 100644 examples/widgets/tutorials/gettingStarted/gsQt/part4/part4.pro delete mode 100644 examples/widgets/tutorials/gettingStarted/gsQt/part5/CMakeLists.txt delete mode 100644 examples/widgets/tutorials/gettingStarted/gsQt/part5/main.cpp delete mode 100644 examples/widgets/tutorials/gettingStarted/gsQt/part5/part5.pro delete mode 100644 examples/widgets/tutorials/gettingstartedqt.qdoc create mode 100644 examples/widgets/tutorials/notepad/gettingstartedqt.qdoc diff --git a/examples/widgets/tutorials/CMakeLists.txt b/examples/widgets/tutorials/CMakeLists.txt index 6aef3f657b..548c96270a 100644 --- a/examples/widgets/tutorials/CMakeLists.txt +++ b/examples/widgets/tutorials/CMakeLists.txt @@ -3,5 +3,4 @@ add_subdirectory(widgets) add_subdirectory(modelview) -add_subdirectory(gettingStarted) qt_internal_add_example(notepad) diff --git a/examples/widgets/tutorials/gettingStarted/CMakeLists.txt b/examples/widgets/tutorials/gettingStarted/CMakeLists.txt deleted file mode 100644 index 42cac47b96..0000000000 --- a/examples/widgets/tutorials/gettingStarted/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -add_subdirectory(gsQt) diff --git a/examples/widgets/tutorials/gettingStarted/gettingStarted.pro b/examples/widgets/tutorials/gettingStarted/gettingStarted.pro deleted file mode 100644 index 3e37725410..0000000000 --- a/examples/widgets/tutorials/gettingStarted/gettingStarted.pro +++ /dev/null @@ -1,4 +0,0 @@ -TEMPLATE = subdirs -SUBDIRS += dir_gsqt - -dir_gsqt.file = gsQt/gsqt.pro diff --git a/examples/widgets/tutorials/gettingStarted/gsQt/CMakeLists.txt b/examples/widgets/tutorials/gettingStarted/gsQt/CMakeLists.txt deleted file mode 100644 index a0fd350393..0000000000 --- a/examples/widgets/tutorials/gettingStarted/gsQt/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -qt_internal_add_example(part1) -qt_internal_add_example(part2) -qt_internal_add_example(part3) -qt_internal_add_example(part4) -qt_internal_add_example(part5) diff --git a/examples/widgets/tutorials/gettingStarted/gsQt/gsqt.pro b/examples/widgets/tutorials/gettingStarted/gsQt/gsqt.pro deleted file mode 100644 index 320f3c3ee4..0000000000 --- a/examples/widgets/tutorials/gettingStarted/gsQt/gsqt.pro +++ /dev/null @@ -1,7 +0,0 @@ -TEMPLATE = subdirs - -SUBDIRS = part1 \ - part2 \ - part3 \ - part4 \ - part5 diff --git a/examples/widgets/tutorials/gettingStarted/gsQt/part1/CMakeLists.txt b/examples/widgets/tutorials/gettingStarted/gsQt/part1/CMakeLists.txt deleted file mode 100644 index d9db469b15..0000000000 --- a/examples/widgets/tutorials/gettingStarted/gsQt/part1/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(getting_started_part1 LANGUAGES CXX) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tutorials/gettingStarted/gsQt/part1") - -find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) - -qt_standard_project_setup() - -qt_add_executable(getting_started_part1 - main.cpp -) - -set_target_properties(getting_started_part1 PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(getting_started_part1 PRIVATE - Qt6::Core - Qt6::Gui - Qt6::Widgets -) - -install(TARGETS getting_started_part1 - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/widgets/tutorials/gettingStarted/gsQt/part1/main.cpp b/examples/widgets/tutorials/gettingStarted/gsQt/part1/main.cpp deleted file mode 100644 index ef8c6ed1b8..0000000000 --- a/examples/widgets/tutorials/gettingStarted/gsQt/part1/main.cpp +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include - -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - - QTextEdit textEdit; - textEdit.show(); - - return app.exec(); -} - diff --git a/examples/widgets/tutorials/gettingStarted/gsQt/part1/part1.pro b/examples/widgets/tutorials/gettingStarted/gsQt/part1/part1.pro deleted file mode 100644 index 391606bfd7..0000000000 --- a/examples/widgets/tutorials/gettingStarted/gsQt/part1/part1.pro +++ /dev/null @@ -1,8 +0,0 @@ - -QT += widgets -SOURCES = main.cpp - -# install -target.path = $$[QT_INSTALL_EXAMPLES]/widgets/tutorials/gettingStarted/gsQt/part1 -INSTALLS += target - diff --git a/examples/widgets/tutorials/gettingStarted/gsQt/part2/CMakeLists.txt b/examples/widgets/tutorials/gettingStarted/gsQt/part2/CMakeLists.txt deleted file mode 100644 index 93749d31c5..0000000000 --- a/examples/widgets/tutorials/gettingStarted/gsQt/part2/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(getting_started_part2 LANGUAGES CXX) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tutorials/gettingStarted/gsQt/part2") - -find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) - -qt_standard_project_setup() - -qt_add_executable(getting_started_part2 - main.cpp -) - -set_target_properties(getting_started_part2 PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(getting_started_part2 PRIVATE - Qt6::Core - Qt6::Gui - Qt6::Widgets -) - -install(TARGETS getting_started_part2 - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/widgets/tutorials/gettingStarted/gsQt/part2/main.cpp b/examples/widgets/tutorials/gettingStarted/gsQt/part2/main.cpp deleted file mode 100644 index 722d7889d0..0000000000 --- a/examples/widgets/tutorials/gettingStarted/gsQt/part2/main.cpp +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include - -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - - QTextEdit *textEdit = new QTextEdit; - QPushButton *quitButton = new QPushButton("&Quit"); - - QObject::connect(quitButton, &QPushButton::clicked, - qApp, &QApplication::quit); - - QVBoxLayout *layout = new QVBoxLayout; - layout->addWidget(textEdit); - layout->addWidget(quitButton); - - QWidget window; - window.setLayout(layout); - - window.show(); - - return app.exec(); -} - diff --git a/examples/widgets/tutorials/gettingStarted/gsQt/part2/part2.pro b/examples/widgets/tutorials/gettingStarted/gsQt/part2/part2.pro deleted file mode 100644 index e7422e4a31..0000000000 --- a/examples/widgets/tutorials/gettingStarted/gsQt/part2/part2.pro +++ /dev/null @@ -1,8 +0,0 @@ - -QT += widgets -SOURCES = main.cpp - -# install -target.path = $$[QT_INSTALL_EXAMPLES]/widgets/tutorials/gettingStarted/gsQt/part2 -INSTALLS += target - diff --git a/examples/widgets/tutorials/gettingStarted/gsQt/part3/CMakeLists.txt b/examples/widgets/tutorials/gettingStarted/gsQt/part3/CMakeLists.txt deleted file mode 100644 index 28aee65426..0000000000 --- a/examples/widgets/tutorials/gettingStarted/gsQt/part3/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(getting_started_part3 LANGUAGES CXX) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tutorials/gettingStarted/gsQt/part3") - -find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) - -qt_standard_project_setup() - -qt_add_executable(getting_started_part3 - main.cpp -) - -set_target_properties(getting_started_part3 PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(getting_started_part3 PRIVATE - Qt6::Core - Qt6::Gui - Qt6::Widgets -) - -install(TARGETS getting_started_part3 - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/widgets/tutorials/gettingStarted/gsQt/part3/main.cpp b/examples/widgets/tutorials/gettingStarted/gsQt/part3/main.cpp deleted file mode 100644 index 5424dc3caa..0000000000 --- a/examples/widgets/tutorials/gettingStarted/gsQt/part3/main.cpp +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include - -class Notepad : public QWidget -{ - Q_OBJECT - -public: - Notepad(); - -private slots: - void quit(); - -private: - QTextEdit *textEdit; - QPushButton *quitButton; - -}; - -Notepad::Notepad() -{ - textEdit = new QTextEdit; - quitButton = new QPushButton(tr("Quit")); - - connect(quitButton, &QPushButton::clicked, - this, &Notepad::quit); - - QVBoxLayout *layout = new QVBoxLayout; - layout->addWidget(textEdit); - layout->addWidget(quitButton); - - setLayout(layout); - - setWindowTitle(tr("Notepad")); -} - -void Notepad::quit() -{ - QMessageBox messageBox; - messageBox.setWindowTitle(tr("Notepad")); - messageBox.setText(tr("Do you really want to quit?")); - messageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); - messageBox.setDefaultButton(QMessageBox::No); - if (messageBox.exec() == QMessageBox::Yes) - qApp->quit(); -} - -int main(int argc, char **argv) -{ - QApplication app(argc, argv); - - Notepad notepad; - notepad.show(); - - return app.exec(); -} - -#include "main.moc" - diff --git a/examples/widgets/tutorials/gettingStarted/gsQt/part3/part3.pro b/examples/widgets/tutorials/gettingStarted/gsQt/part3/part3.pro deleted file mode 100644 index 1577848de5..0000000000 --- a/examples/widgets/tutorials/gettingStarted/gsQt/part3/part3.pro +++ /dev/null @@ -1,8 +0,0 @@ - -QT += widgets -SOURCES = main.cpp - -# install -target.path = $$[QT_INSTALL_EXAMPLES]/widgets/tutorials/gettingStarted/gsQt/part3 -INSTALLS += target - diff --git a/examples/widgets/tutorials/gettingStarted/gsQt/part4/CMakeLists.txt b/examples/widgets/tutorials/gettingStarted/gsQt/part4/CMakeLists.txt deleted file mode 100644 index a64eca5a31..0000000000 --- a/examples/widgets/tutorials/gettingStarted/gsQt/part4/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(getting_started_part4 LANGUAGES CXX) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tutorials/gettingStarted/gsQt/part4") - -find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) - -qt_standard_project_setup() - -qt_add_executable(getting_started_part4 - main.cpp -) - -set_target_properties(getting_started_part4 PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(getting_started_part4 PRIVATE - Qt6::Core - Qt6::Gui - Qt6::Widgets -) - -install(TARGETS getting_started_part4 - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/widgets/tutorials/gettingStarted/gsQt/part4/main.cpp b/examples/widgets/tutorials/gettingStarted/gsQt/part4/main.cpp deleted file mode 100644 index de6436add4..0000000000 --- a/examples/widgets/tutorials/gettingStarted/gsQt/part4/main.cpp +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include - -class Notepad : public QMainWindow -{ - Q_OBJECT - -public: - Notepad(); - -private slots: - void load(); - void save(); - -private: - QTextEdit *textEdit; - - QAction *loadAction; - QAction *saveAction; - QAction *exitAction; - - QMenu *fileMenu; -}; - -Notepad::Notepad() -{ - loadAction = new QAction(tr("&Load"), this); - saveAction = new QAction(tr("&Save"), this); - exitAction = new QAction(tr("E&xit"), this); - - connect(loadAction, &QAction::triggered, - this, &Notepad::load); - connect(saveAction, &QAction::triggered, - this, &Notepad::save); - connect(exitAction, &QAction::triggered, - qApp, &QApplication::quit); - - fileMenu = menuBar()->addMenu(tr("&File")); - fileMenu->addAction(loadAction); - fileMenu->addAction(saveAction); - fileMenu->addSeparator(); - fileMenu->addAction(exitAction); - - textEdit = new QTextEdit; - setCentralWidget(textEdit); - - setWindowTitle(tr("Notepad")); -} - -void Notepad::load() -{ - -} - -void Notepad::save() -{ - -} - -int main(int argc, char **argv) -{ - QApplication app(argc, argv); - - Notepad notepad; - notepad.show(); - - return app.exec(); -}; - -#include "main.moc" - diff --git a/examples/widgets/tutorials/gettingStarted/gsQt/part4/part4.pro b/examples/widgets/tutorials/gettingStarted/gsQt/part4/part4.pro deleted file mode 100644 index 086fac69e9..0000000000 --- a/examples/widgets/tutorials/gettingStarted/gsQt/part4/part4.pro +++ /dev/null @@ -1,8 +0,0 @@ - -QT += widgets -SOURCES = main.cpp - -# install -target.path = $$[QT_INSTALL_EXAMPLES]/widgets/tutorials/gettingStarted/gsQt/part4 -INSTALLS += target - diff --git a/examples/widgets/tutorials/gettingStarted/gsQt/part5/CMakeLists.txt b/examples/widgets/tutorials/gettingStarted/gsQt/part5/CMakeLists.txt deleted file mode 100644 index 7d5a4f737c..0000000000 --- a/examples/widgets/tutorials/gettingStarted/gsQt/part5/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(getting_started_part5 LANGUAGES CXX) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tutorials/gettingStarted/gsQt/part5") - -find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) - -qt_standard_project_setup() - -qt_add_executable(getting_started_part5 - main.cpp -) - -set_target_properties(getting_started_part5 PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(getting_started_part5 PRIVATE - Qt6::Core - Qt6::Gui - Qt6::Widgets -) - -install(TARGETS getting_started_part5 - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/widgets/tutorials/gettingStarted/gsQt/part5/main.cpp b/examples/widgets/tutorials/gettingStarted/gsQt/part5/main.cpp deleted file mode 100644 index 037f1771a1..0000000000 --- a/examples/widgets/tutorials/gettingStarted/gsQt/part5/main.cpp +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include - -class Notepad : public QMainWindow -{ - Q_OBJECT - -public: - Notepad(); - -private slots: - void open(); - void save(); - -private: - QTextEdit *textEdit; - - QAction *openAction; - QAction *saveAction; - QAction *exitAction; - - QMenu *fileMenu; -}; - -Notepad::Notepad() -{ - openAction = new QAction(tr("&Load"), this); - saveAction = new QAction(tr("&Save"), this); - exitAction = new QAction(tr("E&xit"), this); - - connect(openAction, &QAction::triggered, - this, &Notepad::open); - connect(saveAction, &QAction::triggered, - this, &Notepad::save); - connect(exitAction, &QAction::triggered, - qApp, &QApplication::quit); - - fileMenu = menuBar()->addMenu(tr("&File")); - fileMenu->addAction(openAction); - fileMenu->addAction(saveAction); - fileMenu->addSeparator(); - fileMenu->addAction(exitAction); - - textEdit = new QTextEdit; - setCentralWidget(textEdit); - - setWindowTitle(tr("Notepad")); -} - -void Notepad::open() -{ - QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "", - tr("Text Files (*.txt);;C++ Files (*.cpp *.h)")); - - if (!fileName.isEmpty()) { - QFile file(fileName); - if (!file.open(QIODevice::ReadOnly)) { - QMessageBox::critical(this, tr("Error"), tr("Could not open file")); - return; - } - QTextStream in(&file); - textEdit->setText(in.readAll()); - file.close(); - } -} - -void Notepad::save() -{ - - QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), "", - tr("Text Files (*.txt);;C++ Files (*.cpp *.h)")); - - if (!fileName.isEmpty()) { - QFile file(fileName); - if (!file.open(QIODevice::WriteOnly)) { - // error message - } else { - QTextStream stream(&file); - stream << textEdit->toPlainText(); - stream.flush(); - file.close(); - } - } -} - -int main(int argc, char **argv) -{ - QApplication app(argc, argv); - - Notepad notepad; - notepad.show(); - - return app.exec(); -} - -#include "main.moc" - diff --git a/examples/widgets/tutorials/gettingStarted/gsQt/part5/part5.pro b/examples/widgets/tutorials/gettingStarted/gsQt/part5/part5.pro deleted file mode 100644 index 12378f305a..0000000000 --- a/examples/widgets/tutorials/gettingStarted/gsQt/part5/part5.pro +++ /dev/null @@ -1,8 +0,0 @@ -QT += widgets -requires(qtConfig(filedialog)) -SOURCES = main.cpp - -# install -target.path = $$[QT_INSTALL_EXAMPLES]/widgets/tutorials/gettingStarted/gsQt/part5 -INSTALLS += target - diff --git a/examples/widgets/tutorials/gettingstartedqt.qdoc b/examples/widgets/tutorials/gettingstartedqt.qdoc deleted file mode 100644 index 152bf8c114..0000000000 --- a/examples/widgets/tutorials/gettingstartedqt.qdoc +++ /dev/null @@ -1,504 +0,0 @@ -// Copyright (C) 2022 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only - -/*! - \example tutorials/notepad - \title Getting Started Programming with Qt Widgets - \brief A tutorial for Qt Widgets based notepad application. - - In this topic, we teach basic Qt knowledge by implementing a simple - Notepad application using C++ and the \l{Qt Widgets} module. The - application is a small text editor which allows you to create a text - file, save it, print it, - or reopen and edit it again. You can also set the font to be used. - - \image notepad1.png "Notepad application" - - \include examples-run.qdocinc - - \section1 Creating the Notepad Project - - Setting up a new project in Qt Creator is aided by a wizard that - guides you step-by-step through the project creation process. The - wizard prompts you to enter the settings needed for that particular - type of project and creates the project for you. - - \note The UI text in Qt Creator and the contents of the generated files - depend on the Qt Creator version that you use. - - \image notepad2.png "Qt Creator New Project dialog" - - To create the Notepad project, select \uicontrol File > - \uicontrol {New Project} > \uicontrol {Application (Qt)} > - \uicontrol {Qt Widgets Application} > \uicontrol Choose, and follow the - instructions of the wizard. In the \uicontrol{Class Information} dialog, - type \e Notepad as the class name and select \uicontrol QMainWindow - as the base class. - - \image notepad3.png "Class Information Dialog" - - The \uicontrol {Qt Widgets Application} wizard creates a project that contains - a main source file and a set of files that specify a user interface - (Notepad widget): - - \list - \li CMakeLists.txt - the project file. - \li main.cpp - the main source file for the application. - \li notepad.cpp - the source file of the notepad class of the - Notepad widget. - \li notepad.h - the header file of the notepad class for the - Notepad widget. - \li notepad.ui - the UI form for the Notepad widget. - \endlist - - The files come with the necessary boiler plate code for you to be able to - build and run the project. We will take a closer look at the file contents - in the following sections. - - \b{Learn More} - - \table - \header - \li About - \li Here - \row - \li Using Qt Creator - \li \l{Qt Creator Manual}{Qt Creator} - \row - \li Creating other kind of applications with Qt Creator - \li \l{Qt Creator: Tutorials}{Qt Creator Tutorials} - \endtable - - - \section1 Main Source File - - The wizard generates the following code in the main.cpp file: - - \quotefromfile tutorials/notepad/main.cpp - \skipto "notepad.h" - \printuntil } - - We will go through the code line by line. The following lines include - the header files for the Notepad widget and QApplication. All Qt classes - have a header file named after them. - - \quotefromfile tutorials/notepad/main.cpp - \skipto notepad.h - \printuntil QApplication - - The following line defines the main function that is the entry point - for all C and C++ based applications: - - \printline main - - The following line creates a QApplication object. This object manages - application-wide resources and is necessary to run any Qt program - that uses Qt Widgets. It constructs an application object with \c argc - command line arguments run in \c argv. (For GUI applications that - do not use Qt Widgets, you can use QGuiApplication instead.) - - \skipuntil { - \printuntil QApplication - - The following line creates the Notepad object. This is the object for - which the wizard created the class and the UI file. The user interface - contains visual elements that are called \c widgets in Qt. Examples - of widgets are text edits, scroll bars, labels, and radio buttons. A - widget can also be a container for other widgets; a dialog or a main - application window, for example. - - \printline Notepad - - The following line shows the Notepad widget on the screen in its own - window. Widgets can also function as containers. An example of this - is QMainWindow which often contains several types of widgets. Widgets - are not visible by default; the function \l{QWidget::}{show()} makes - the widget visible. - - \printline w.show - - The following line makes the QApplication enter its event loop. When - a Qt application is running, events are generated and sent to the - widgets of the application. Examples of events are mouse presses - and key strokes. - - \printline a.exec - - \b{Learn More} - - \table - \header - \li About - \li Here - \row - \li Widgets and Window Geometry - \li \l{Window and Dialog Widgets} - \row - \li Events and event handling - \li \l{The Event System} - \endtable - - \section1 Designing a UI - - The wizard generates a user interface definition in XML format: notepad.ui. - When you open the notepad.ui file in Qt Creator, it automatically - opens in the integrated Qt Designer. - - When you build the application, Qt Creator launches the Qt - \l{User Interface Compiler (uic)} that reads the .ui file and creates - a corresponding C++ header file, ui_notepad.h. - - \section2 Using Qt Designer - - The wizard creates an application that uses a QMainWindow. It has - its own layout to which you can add a menu bar, dock widgets, toolbars, - and a status bar. The center area can be occupied by any kind of widget. - The wizard places the Notepad widget there. - - To add widgets in Qt Designer: - - \list 1 - \li In the Qt Creator \uicontrol Edit mode, double-click the notepad.ui - file in the \uicontrol Projects view to launch the file in the integrated - Qt Designer. - \li Drag and drop widgets Text Edit (QTextEdit) to the form. - \li Press \key {Ctrl+A} (or \key {Cmd+A}) to select the widgets and click - \uicontrol {Lay out Vertically} (or press \key {Ctrl+L}) to apply a vertical - layout (QVBoxLayout). - \li Press \key {Ctrl+S} (or \key {Cmd+S}) to save your changes. - \endlist - - The UI now looks as follows in Qt Designer: - - \image notepad4.png - - You can view the generated XML file in the code editor: - - \quotefromfile tutorials/notepad/notepad.ui - - \printuntil QMenuBar - \dots - - The following line contains the XML declaration, which specifies the - XML version and character encoding used in the document: - - \code - - \endcode - - The rest of the file specifies an \c ui element that defines a - Notepad widget: - - \code - - \endcode - - The UI file is used together with the header and source file of the - Notepad class. We will look at the rest of the UI file in the later - sections. - - \section2 Notepad Header File - - The wizard generated a header file for the Notepad class that has the - necessary #includes, a constructor, a destructor, and the Ui object. - The file looks as follows: - - \quotefromfile tutorials/notepad/notepad.h - \skipto #include - \printuntil ~Notepad(); - \skipto private: - \printuntil }; - - The following line includes QMainWindow that provides a main application - window: - - \quotefromfile tutorials/notepad/notepad.h - \skipto #include - \printuntil > - - The following lines declare the Notepad class in the Ui namespace, - which is the standard namespace for the UI classes generated from - .ui files by the \c uic tool: - - \skipto Ui { - \printuntil } - - The class declaration contains the \c Q_OBJECT macro. It must come - first in the class definition, and declares our class as a QObject. - Naturally, it must also inherit from QObject. A QObject adds several - abilities to a normal C++ class. Notably, the class name and slot - names can be queried at runtime. It is also possible to query a slot's - parameter types and invoke it. - - \skipto class Notepad - \printuntil Q_OBJECT - - The following lines declare a constructor that has a default argument - called \c parent. - The value 0 indicates that the widget has no parent (it is a top-level - widget). - - \printuntil explicit - - The following line declares a virtual destructor to free the resources - that were acquired by the object during its life-cycle. According to - the C++ naming convention, destructors have the same name as the class - they are associated with, prefixed with a tilde (~). In QObject, - destructors are virtual to ensure that the destructors of derived - classes are invoked properly when an object is deleted through a - pointer-to-base-class. - - \printuntil ~Notepad(); - - The following lines declare a member variable which is a pointer to - the Notepad UI class. A member variable is associated with a specific - class, and accessible for all its methods. - - \skipto private: - \printuntil }; - - \section2 Notepad Source File - - The source file that the wizard generated for the Notepad class looks - as follows: - - \quotefromfile tutorials/notepad/notepad.cpp - \skipto #include "notepad.h" - \printuntil ui->setupUi(this); - \skipto } - \printuntil } - - The following lines include the Notepad class header file that was - generated by the wizard and the UI header file that was generated - by the \c uic tool: - - \quotefromfile tutorials/notepad/notepad.cpp - \skipto #include "notepad.h" - \printuntil #include "ui_notepad.h" - - The following line defines the \c {Notepad} constructor: - - \printuntil Notepad::Notepad - - The following line calls the QMainWindow constructor, which is - the base class for the Notepad class: - - \printuntil QMainWindow - - The following line creates the UI class instance and assigns it to - the \c ui member: - - \printline ui(new - - The following line sets up the UI: - - \printuntil ui->setupUi(this) - - In the destructor, we delete the \c ui: - - \skipto Notepad::~Notepad - \printuntil } - - \section2 Project File - - The wizard generates the following project file, \c CMakeLists.txt, for - us: - - \quotefile tutorials/notepad/CMakeLists.txt - - The project file specifies the source, header, and UI files included in - the project. - - \b{Learn More} - - \table - \header - \li About - \li Here - \row - \li Using Qt Designer - \li \l{Qt Designer Manual} - \row - \li Layouts - \li \l{Layout Management}, - \l{Widgets and Layouts}, - \l{Layout Examples} - \row - \li The widgets that come with Qt - \li \l{Qt Widget Gallery} - \row - \li Main windows and main window classes - \li \l{Application Main Window}, - \l{Main Window Examples} - \row - \li QObjects and the Qt Object model (This is essential to - understand Qt) - \li \l{Object Model} - \row - \li qmake and the Qt build system - \li \l{qmake Manual} - \endtable - - \section1 Adding User Interaction - - - To add functionality to the editor, we start by adding menu items - and buttons on a toolbar. - - Click on "Type Here", and add the options New, Open, Save, Save as, - Print and Exit. This creates 5 lines in the Action Editor below. - To connect the actions to slots, right-click an action and select - \uicontrol {Go to slot} > \uicontrol triggered(), and complete the - code for that given slot. - - If we also want to add the actions to a toolbar, we can assign an - icon to each QAction, and then drag the QAction to the toolbar. You - assign an icon by entering an icon name in the Icon property of the - action concerned. When the QAction has been dragged to the toolbar, - clicking the icon will launch the associated slot. - - Complete the method \c newDocument(): - - \quotefromfile tutorials/notepad/notepad.cpp - \skipto newDocument() - \printuntil } - - The \c currentFile variable is a global variable containing the file - presently being edited, and \c clear() clears the text buffer. - The \c currentFile variable is defined in the private part of notepad.h: - - \quotefromfile tutorials/notepad/notepad.h - \skipto private: - \printuntil currentFile; - - \section2 Opening a file - - In \c notepad.ui, right click on \c actionOpen and select - \uicontrol {Go to Slot}. - - Complete method \c open(). - - \quotefromfile tutorials/notepad/notepad.cpp - \skipto open() - \printuntil file.close - \printuntil } - - - \c QFileDialog::getOpenFileName opens a dialog enabling you to select - a file. QFile object \c myfile has the selected \c file_name as - parameter. We store the selected file also into the global variable - \c currentFile for later purposes. We open the file with \c file.open - as a readonly text file. If it cannot be opened, a warning is issued, - and the program stops. - - We define a QTextStream \c instream for parameter \c myfile. - The contents of file \c myfile is copied into QString \c text. - \c setText(text) fills the buffer of our editor with \c text. - - \section2 Saving a file - - We create the method for saving a file in the same way as for - \l {Opening a file}, by right clicking on \c actionSave, and - selecting \uicontrol {Go to Slot}. - - \skipto Notepad::save - \printuntil file.close - \printuntil } - - QFile object \c myfile is linked to global variable \c current_file, - the variable that contains the file we were working with. - If we cannot open \c myfile, an error message is issued and the - method stops. We create a QTextStream \c outstream. The contents - of the editor buffer is converted to plain text, and then written - to \c outstream. - - \section2 Saving a file under another name - - \skipto Notepad::saveAs - \printuntil file.close - \printuntil } - - This is the same procedure as for \l {Saving a file}, the only - difference being that here you need to enter a new file name for - the file to be created. - - - \section2 Printing a File - - If you want to use print functionalities, you need to add - \c PrintSupport to the project file: - - \quotefromfile tutorials/notepad/CMakeLists.txt - \skipto find_package(Qt6 - \printuntil ) - - In \c notepad.cpp, we declare a QPrinter object called \c printDev: - - \quotefromfile tutorials/notepad/notepad.cpp - \skipto void Notepad::print() - \printuntil } - - We launch a printer dialog box and store the selected printer in - object \c printDev. If we clicked on \c Cancel and did not select - a printer, the methods returns. The actual printer command is given - with \c ui->textEdit->print with our QPrinter object as parameter. - - \section2 Select a Font - - \skipto Notepad::selectFont - \printuntil } - - We declare a boolean indicating if we did select a font with - QFontDialog. If so, we set the font with \c ui->textEdit->setFont(myfont). - - \section2 Copy, Cut, Paste, Undo, and Redo - - If you select some text, and want to copy it to the clipboard, - you call the appropriate method of \c ui->textEdit. The same counts - for cut, paste, undo, and redo. - - This table shows the method name to use. - - \table - \header - \li Task - \li Method called - \row - \li Copy - \li ui->textEdit->copy() - \row - \li Cut - \li ui->textEdit->cut() - \row - \li Paste - \li ui->textEdit->paste() - \row - \li Undo - \li ui->textEdit->undo() - \row - \li Redo - \li ui->textEdit->redo() - \endtable - - \b{Learn More} - - \table - \header - \li About - \li Here - \row - \li MDI applications - \li QMdiArea, - \l{MDI Example} - \row - \li Files and I/O devices - \li QFile, QIODevice - \row - \li tr() and internationalization - \li \l{Qt Linguist Manual}, - \l{Writing Source Code for Translation}, - \l{Internationalization with Qt} - \endtable - - \include cli-build-cmake.qdocinc cli-build-cmake -*/ diff --git a/examples/widgets/tutorials/notepad/gettingstartedqt.qdoc b/examples/widgets/tutorials/notepad/gettingstartedqt.qdoc new file mode 100644 index 0000000000..152bf8c114 --- /dev/null +++ b/examples/widgets/tutorials/notepad/gettingstartedqt.qdoc @@ -0,0 +1,504 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only + +/*! + \example tutorials/notepad + \title Getting Started Programming with Qt Widgets + \brief A tutorial for Qt Widgets based notepad application. + + In this topic, we teach basic Qt knowledge by implementing a simple + Notepad application using C++ and the \l{Qt Widgets} module. The + application is a small text editor which allows you to create a text + file, save it, print it, + or reopen and edit it again. You can also set the font to be used. + + \image notepad1.png "Notepad application" + + \include examples-run.qdocinc + + \section1 Creating the Notepad Project + + Setting up a new project in Qt Creator is aided by a wizard that + guides you step-by-step through the project creation process. The + wizard prompts you to enter the settings needed for that particular + type of project and creates the project for you. + + \note The UI text in Qt Creator and the contents of the generated files + depend on the Qt Creator version that you use. + + \image notepad2.png "Qt Creator New Project dialog" + + To create the Notepad project, select \uicontrol File > + \uicontrol {New Project} > \uicontrol {Application (Qt)} > + \uicontrol {Qt Widgets Application} > \uicontrol Choose, and follow the + instructions of the wizard. In the \uicontrol{Class Information} dialog, + type \e Notepad as the class name and select \uicontrol QMainWindow + as the base class. + + \image notepad3.png "Class Information Dialog" + + The \uicontrol {Qt Widgets Application} wizard creates a project that contains + a main source file and a set of files that specify a user interface + (Notepad widget): + + \list + \li CMakeLists.txt - the project file. + \li main.cpp - the main source file for the application. + \li notepad.cpp - the source file of the notepad class of the + Notepad widget. + \li notepad.h - the header file of the notepad class for the + Notepad widget. + \li notepad.ui - the UI form for the Notepad widget. + \endlist + + The files come with the necessary boiler plate code for you to be able to + build and run the project. We will take a closer look at the file contents + in the following sections. + + \b{Learn More} + + \table + \header + \li About + \li Here + \row + \li Using Qt Creator + \li \l{Qt Creator Manual}{Qt Creator} + \row + \li Creating other kind of applications with Qt Creator + \li \l{Qt Creator: Tutorials}{Qt Creator Tutorials} + \endtable + + + \section1 Main Source File + + The wizard generates the following code in the main.cpp file: + + \quotefromfile tutorials/notepad/main.cpp + \skipto "notepad.h" + \printuntil } + + We will go through the code line by line. The following lines include + the header files for the Notepad widget and QApplication. All Qt classes + have a header file named after them. + + \quotefromfile tutorials/notepad/main.cpp + \skipto notepad.h + \printuntil QApplication + + The following line defines the main function that is the entry point + for all C and C++ based applications: + + \printline main + + The following line creates a QApplication object. This object manages + application-wide resources and is necessary to run any Qt program + that uses Qt Widgets. It constructs an application object with \c argc + command line arguments run in \c argv. (For GUI applications that + do not use Qt Widgets, you can use QGuiApplication instead.) + + \skipuntil { + \printuntil QApplication + + The following line creates the Notepad object. This is the object for + which the wizard created the class and the UI file. The user interface + contains visual elements that are called \c widgets in Qt. Examples + of widgets are text edits, scroll bars, labels, and radio buttons. A + widget can also be a container for other widgets; a dialog or a main + application window, for example. + + \printline Notepad + + The following line shows the Notepad widget on the screen in its own + window. Widgets can also function as containers. An example of this + is QMainWindow which often contains several types of widgets. Widgets + are not visible by default; the function \l{QWidget::}{show()} makes + the widget visible. + + \printline w.show + + The following line makes the QApplication enter its event loop. When + a Qt application is running, events are generated and sent to the + widgets of the application. Examples of events are mouse presses + and key strokes. + + \printline a.exec + + \b{Learn More} + + \table + \header + \li About + \li Here + \row + \li Widgets and Window Geometry + \li \l{Window and Dialog Widgets} + \row + \li Events and event handling + \li \l{The Event System} + \endtable + + \section1 Designing a UI + + The wizard generates a user interface definition in XML format: notepad.ui. + When you open the notepad.ui file in Qt Creator, it automatically + opens in the integrated Qt Designer. + + When you build the application, Qt Creator launches the Qt + \l{User Interface Compiler (uic)} that reads the .ui file and creates + a corresponding C++ header file, ui_notepad.h. + + \section2 Using Qt Designer + + The wizard creates an application that uses a QMainWindow. It has + its own layout to which you can add a menu bar, dock widgets, toolbars, + and a status bar. The center area can be occupied by any kind of widget. + The wizard places the Notepad widget there. + + To add widgets in Qt Designer: + + \list 1 + \li In the Qt Creator \uicontrol Edit mode, double-click the notepad.ui + file in the \uicontrol Projects view to launch the file in the integrated + Qt Designer. + \li Drag and drop widgets Text Edit (QTextEdit) to the form. + \li Press \key {Ctrl+A} (or \key {Cmd+A}) to select the widgets and click + \uicontrol {Lay out Vertically} (or press \key {Ctrl+L}) to apply a vertical + layout (QVBoxLayout). + \li Press \key {Ctrl+S} (or \key {Cmd+S}) to save your changes. + \endlist + + The UI now looks as follows in Qt Designer: + + \image notepad4.png + + You can view the generated XML file in the code editor: + + \quotefromfile tutorials/notepad/notepad.ui + + \printuntil QMenuBar + \dots + + The following line contains the XML declaration, which specifies the + XML version and character encoding used in the document: + + \code + + \endcode + + The rest of the file specifies an \c ui element that defines a + Notepad widget: + + \code + + \endcode + + The UI file is used together with the header and source file of the + Notepad class. We will look at the rest of the UI file in the later + sections. + + \section2 Notepad Header File + + The wizard generated a header file for the Notepad class that has the + necessary #includes, a constructor, a destructor, and the Ui object. + The file looks as follows: + + \quotefromfile tutorials/notepad/notepad.h + \skipto #include + \printuntil ~Notepad(); + \skipto private: + \printuntil }; + + The following line includes QMainWindow that provides a main application + window: + + \quotefromfile tutorials/notepad/notepad.h + \skipto #include + \printuntil > + + The following lines declare the Notepad class in the Ui namespace, + which is the standard namespace for the UI classes generated from + .ui files by the \c uic tool: + + \skipto Ui { + \printuntil } + + The class declaration contains the \c Q_OBJECT macro. It must come + first in the class definition, and declares our class as a QObject. + Naturally, it must also inherit from QObject. A QObject adds several + abilities to a normal C++ class. Notably, the class name and slot + names can be queried at runtime. It is also possible to query a slot's + parameter types and invoke it. + + \skipto class Notepad + \printuntil Q_OBJECT + + The following lines declare a constructor that has a default argument + called \c parent. + The value 0 indicates that the widget has no parent (it is a top-level + widget). + + \printuntil explicit + + The following line declares a virtual destructor to free the resources + that were acquired by the object during its life-cycle. According to + the C++ naming convention, destructors have the same name as the class + they are associated with, prefixed with a tilde (~). In QObject, + destructors are virtual to ensure that the destructors of derived + classes are invoked properly when an object is deleted through a + pointer-to-base-class. + + \printuntil ~Notepad(); + + The following lines declare a member variable which is a pointer to + the Notepad UI class. A member variable is associated with a specific + class, and accessible for all its methods. + + \skipto private: + \printuntil }; + + \section2 Notepad Source File + + The source file that the wizard generated for the Notepad class looks + as follows: + + \quotefromfile tutorials/notepad/notepad.cpp + \skipto #include "notepad.h" + \printuntil ui->setupUi(this); + \skipto } + \printuntil } + + The following lines include the Notepad class header file that was + generated by the wizard and the UI header file that was generated + by the \c uic tool: + + \quotefromfile tutorials/notepad/notepad.cpp + \skipto #include "notepad.h" + \printuntil #include "ui_notepad.h" + + The following line defines the \c {Notepad} constructor: + + \printuntil Notepad::Notepad + + The following line calls the QMainWindow constructor, which is + the base class for the Notepad class: + + \printuntil QMainWindow + + The following line creates the UI class instance and assigns it to + the \c ui member: + + \printline ui(new + + The following line sets up the UI: + + \printuntil ui->setupUi(this) + + In the destructor, we delete the \c ui: + + \skipto Notepad::~Notepad + \printuntil } + + \section2 Project File + + The wizard generates the following project file, \c CMakeLists.txt, for + us: + + \quotefile tutorials/notepad/CMakeLists.txt + + The project file specifies the source, header, and UI files included in + the project. + + \b{Learn More} + + \table + \header + \li About + \li Here + \row + \li Using Qt Designer + \li \l{Qt Designer Manual} + \row + \li Layouts + \li \l{Layout Management}, + \l{Widgets and Layouts}, + \l{Layout Examples} + \row + \li The widgets that come with Qt + \li \l{Qt Widget Gallery} + \row + \li Main windows and main window classes + \li \l{Application Main Window}, + \l{Main Window Examples} + \row + \li QObjects and the Qt Object model (This is essential to + understand Qt) + \li \l{Object Model} + \row + \li qmake and the Qt build system + \li \l{qmake Manual} + \endtable + + \section1 Adding User Interaction + + + To add functionality to the editor, we start by adding menu items + and buttons on a toolbar. + + Click on "Type Here", and add the options New, Open, Save, Save as, + Print and Exit. This creates 5 lines in the Action Editor below. + To connect the actions to slots, right-click an action and select + \uicontrol {Go to slot} > \uicontrol triggered(), and complete the + code for that given slot. + + If we also want to add the actions to a toolbar, we can assign an + icon to each QAction, and then drag the QAction to the toolbar. You + assign an icon by entering an icon name in the Icon property of the + action concerned. When the QAction has been dragged to the toolbar, + clicking the icon will launch the associated slot. + + Complete the method \c newDocument(): + + \quotefromfile tutorials/notepad/notepad.cpp + \skipto newDocument() + \printuntil } + + The \c currentFile variable is a global variable containing the file + presently being edited, and \c clear() clears the text buffer. + The \c currentFile variable is defined in the private part of notepad.h: + + \quotefromfile tutorials/notepad/notepad.h + \skipto private: + \printuntil currentFile; + + \section2 Opening a file + + In \c notepad.ui, right click on \c actionOpen and select + \uicontrol {Go to Slot}. + + Complete method \c open(). + + \quotefromfile tutorials/notepad/notepad.cpp + \skipto open() + \printuntil file.close + \printuntil } + + + \c QFileDialog::getOpenFileName opens a dialog enabling you to select + a file. QFile object \c myfile has the selected \c file_name as + parameter. We store the selected file also into the global variable + \c currentFile for later purposes. We open the file with \c file.open + as a readonly text file. If it cannot be opened, a warning is issued, + and the program stops. + + We define a QTextStream \c instream for parameter \c myfile. + The contents of file \c myfile is copied into QString \c text. + \c setText(text) fills the buffer of our editor with \c text. + + \section2 Saving a file + + We create the method for saving a file in the same way as for + \l {Opening a file}, by right clicking on \c actionSave, and + selecting \uicontrol {Go to Slot}. + + \skipto Notepad::save + \printuntil file.close + \printuntil } + + QFile object \c myfile is linked to global variable \c current_file, + the variable that contains the file we were working with. + If we cannot open \c myfile, an error message is issued and the + method stops. We create a QTextStream \c outstream. The contents + of the editor buffer is converted to plain text, and then written + to \c outstream. + + \section2 Saving a file under another name + + \skipto Notepad::saveAs + \printuntil file.close + \printuntil } + + This is the same procedure as for \l {Saving a file}, the only + difference being that here you need to enter a new file name for + the file to be created. + + + \section2 Printing a File + + If you want to use print functionalities, you need to add + \c PrintSupport to the project file: + + \quotefromfile tutorials/notepad/CMakeLists.txt + \skipto find_package(Qt6 + \printuntil ) + + In \c notepad.cpp, we declare a QPrinter object called \c printDev: + + \quotefromfile tutorials/notepad/notepad.cpp + \skipto void Notepad::print() + \printuntil } + + We launch a printer dialog box and store the selected printer in + object \c printDev. If we clicked on \c Cancel and did not select + a printer, the methods returns. The actual printer command is given + with \c ui->textEdit->print with our QPrinter object as parameter. + + \section2 Select a Font + + \skipto Notepad::selectFont + \printuntil } + + We declare a boolean indicating if we did select a font with + QFontDialog. If so, we set the font with \c ui->textEdit->setFont(myfont). + + \section2 Copy, Cut, Paste, Undo, and Redo + + If you select some text, and want to copy it to the clipboard, + you call the appropriate method of \c ui->textEdit. The same counts + for cut, paste, undo, and redo. + + This table shows the method name to use. + + \table + \header + \li Task + \li Method called + \row + \li Copy + \li ui->textEdit->copy() + \row + \li Cut + \li ui->textEdit->cut() + \row + \li Paste + \li ui->textEdit->paste() + \row + \li Undo + \li ui->textEdit->undo() + \row + \li Redo + \li ui->textEdit->redo() + \endtable + + \b{Learn More} + + \table + \header + \li About + \li Here + \row + \li MDI applications + \li QMdiArea, + \l{MDI Example} + \row + \li Files and I/O devices + \li QFile, QIODevice + \row + \li tr() and internationalization + \li \l{Qt Linguist Manual}, + \l{Writing Source Code for Translation}, + \l{Internationalization with Qt} + \endtable + + \include cli-build-cmake.qdocinc cli-build-cmake +*/ diff --git a/examples/widgets/tutorials/tutorials.pro b/examples/widgets/tutorials/tutorials.pro index 5f6da54b2a..d9dbbd2860 100644 --- a/examples/widgets/tutorials/tutorials.pro +++ b/examples/widgets/tutorials/tutorials.pro @@ -1,2 +1,2 @@ TEMPLATE = subdirs -SUBDIRS += widgets modelview gettingStarted notepad +SUBDIRS += widgets modelview notepad -- cgit v1.2.1