// Copyright (C) 2022 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause #include "textfinder.h" //! [1] #include "./ui_textfinder.h" #include #include //! [1] //! [3] TextFinder::TextFinder(QWidget *parent) : QWidget(parent) , ui(new Ui::TextFinder) { ui->setupUi(this); loadTextFile(); } //! [3] TextFinder::~TextFinder() { delete ui; } //! [0] void TextFinder::loadTextFile() { QFile inputFile(":/input.txt"); inputFile.open(QIODevice::ReadOnly); QTextStream in(&inputFile); QString line = in.readAll(); inputFile.close(); ui->textEdit->setPlainText(line); QTextCursor cursor = ui->textEdit->textCursor(); cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor, 1); } //! [0] //! [2] void TextFinder::on_findButton_clicked() { QString searchString = ui->lineEdit->text(); ui->textEdit->find(searchString, QTextDocument::FindWholeWords); } //! [2]