Đóng gói vật dụng từ cuối cùng có tác dụng tương tự như đóng gói chúng từ đầu, ngoại trừ mỗi widget được đặt ở vị trí có sẵn tiếp theo bắt đầu từ phía dưới. Nút đầu tiên được thêm vào phía dưới là một trong những tạo ra trên đường dây 25 thông qua 27, và được thêm vào của các cuộc gọi đến packEnd () trên dòng 28. | Chapter 6 Menus and Toolbars 127 The method createStatusBar on line 36 calls statusBar to create and install a widget capable of displaying a single line of text. Your program has access to the text of the status bar so it can keep it constantly updated. Unlike the toolbar and the menu bar the status bar cannot be moved to another location. The method createToolBar on line 41 creates a toolbar by calling toolBar on line 43. An ID number is required as an argument because your application can have as many toolbars as you would like. You supply the ID number and if there is no toolbar with that ID one is created and returned. Using the same ID number will always return the same toolbar. For this example a pixmap is used to create a single toolbar button. The toolbar can be moved outside of its parent window. Figure 6-3 shows the result of using the handle at the left end of the toolbar to tear off the menu from its parent window and establish it as its own stand-alone window. Figure 6-3 Tear-off menus and toolbars The method named slotExit on line 47 is called whenever the user selects Exit from the menu. You may need to do some kind of cleanup here and save currently unsaved data but this example simply calls the exit method in the application. The global variable named kapp always contains a pointer to the KApplication object. The slot method named queryClose on line 51 is called when the figure X in the upper right corner of the application s frame is selected. If this slot returns TRUE the application is immediately closed. If it returns FALSE no action will be taken the signal from the X button will be ignored . This is the skeleton of an application. Allowing KTMainWindow to do most of the work your top-level window can be very sophisticated with only a few lines of code. The rest of this chapter describes the details of configuring the menu bar and toolbars and displaying information via the status bar. 128 Part I Getting Started The Menu Bar Basically a menu