(E) Find dialogΒΆ
Goal: I will learn to create a simple dialog using Qt Designer, and to understand the signals & slots mechanism of Qt.
Instructions:
Create a new project: student/11/find_dialog/
.
Create the new project according to to the instructions in the previous material sections.
Your task is to use Qt Designer to implement a dialog that looks like the figure below.
You can write the name of the file, from which you will
search for certain words, into the
lineEdit component, located next to the label Find from file
.
Similarly, you can write the word you want to search for into the
lineEdit component, located next to the label Find what
.
When you click the Find
button, the given word will be searched for
from the given file.
You can use the textBrowser component (located below the
Search status
label) to print the information on whether the file
was found or not.
If the file was found, you can print the information on whether the
target word was found or not.
You are only allowed to print exactly one of the following texts:
File not found
File found
Word not found
Word found
The program prints File not found
, if the given file cannot be found.
If the file can be found but the user gives no word to search for
(i.e. the word is empty or its length is zero), the program prints
File found
.
If the file can be found and if the given word is non-empty, the program
prints one of the two remaining choices according to the fact, whether
the word occurs in the file or not.
You can use the Match case
checkbox to define whether or not
capitalization matters.
Therefore, this choice has also effect on which of the two last choices the
program prints.
You need not store the made choice into a boolean
variable,
since the class QCheckBox
has the function isChecked
, which returns
the made choice.
You can close the MainWindow with the Close
button.
Instruction to pass automated tests
Use the following object names for lineEdit widgets:
fileLineEdit
and keyLineEdit
.
For these widgets, use the signal editingFinished
.
For buttons, use the object names:
findPushButton
and closePushButton
.
For the remaining widgets, use the object names:
textBrowser
and matchCheckBox
.
Tips for completing the assignment:
- A good place to start is to construct the user interface.
- Anyway, you can use similar steps to those described in the BMI (body mass index) exercise.
- You can implement opening a file, as well as reading and closing it in a usual way (graphical user interfaces require no changes in thes actions).
- You can implement string search in any way you wish, it is enough to
use e.g. the method
find
fromstring
class. - Recall that as a default, the program will be compiled into a
build-
directory. So, for testing purposes, you can move the input data file to this same directory.
A+ presents the exercise submission form here.