Start QtCreator (through the Developpement menu or by typing qtcreator & in the Terminal), then select:
Five file have then been created by QtCreator :
The MainWindow class derives from QMainWindow. It will allow you to implement the functionalities decribed in the next questions. At the moment it doesn't do much more than QMainWindow. To see what happens, compile and run by clicking on the green arrow (bottom left) of QtCreator. Notice the Compilation bar a little hihgher. It is gray during compilation, green if the compilation was successful and red otherwise. Clicking on this bar makes the errors appear (or disappear).
Create a menu bar and a "File" menu containing 3 items for activating the "Open ...", "Save ..." and "Quit ..." commands. Also create a toolbar allowing to activate the same commands. Use QAction and specify appropriate hot keys and tooltips (we will assume that we have three .png files containing the images of the icons of these commands). Finally, change the source code so that the central area of the MainWindow will display a QTextEdit (remember to include the corresponding header and declare variable appropriately). You can now compile and run the program.
Note: QtCreator automatically adds ui->setupUi(this); in the MainWindow constructor. This serves to instantiate the graphical interface created by QtDesigner . As for the moment we do not use it, you will need to comment this line and create a status bar by calling the statusBar() method of the QtMainWindow class.
Download the .png files containing the icon images in a sub-directory of your Qt project (you can for example download these icon files). Make sure that the icons specified in the source code have the same names as the files, then click on:
Declare and implement the openFile(), saveFile() and quitApp () slots. For now they will just display a message (e.g. the name of the slot) on the console (NB: if you use std::cout and std::endl do not forget to include the iostream header. Alternately you can also use qDebug(). Connect the slots to the corresponding actions, then compile and test the program.
Implement the openFile() and saveFile () slots so that each of them open a dialog box. These dialog boxes will serve to select the a file, either for reading the text or for writing it. You will typically use the QFileDialog widget for this purpose. Retrieve the name of the selected file and display it on the console.
Add source code in the openFile () slot to make it read the file selected in the Open dialog box and display its content in the QTextEdit . For this purpose, you can use a QFile and a QTextStream (note that it's easier to read the entire content of the file in a single step). The textual content (a QString) can then be set to the QTextEdit through its setHtml () method. This method assumes the content is in HTML (we could use setPlainText() for plain text).
Conversely, following the same principle, make the saveFile () slot save the content of the QTextEdit widget in the file selected through the Save dialog box. Note: you can use the << operator).
First, make the Quit button to open a QMessageBox (with "Yes" and "No" buttons) allowing the user to ask for confirmation before exiting the application. However, this is not sufficient because the user can also exit the program by clicking on the close button of the window bar (usually a cross, a red button, etc.) Change MainWindow so that this action will have the same effect as when clicking on the Quit button (i.e. open the QMessageBox)
Note: this will require redefining the QWidget::closeEvent() method.