Chapter 2 call exit
In the previous chapter, we learned how to use QT designer. In this chapter, we added some slightly complex functions.
Now we have made some preparations. As we said last time, we 'd better create a separate folder for every QT program,
In this way, we can more easily use the tools provided by QT for us, such as qmake.
[Root @ localhost root] # mkdir/root/designertutorial
[Root @ localhost root] # cd/root/designertutorial
Open the QT designer and enter: designer in the command line, as shown below:
[Root @ localhost designertutorial] # Designer &
[3] 16544
[Root @ localhost designertutorial] #
The "QT designer-New/Open" dialog box is displayed. This is a new dialog box,
Select the first "C ++ Project" in the dialog box, click "OK", and change the name. Here we change it to tutorial2.pro to save,
By default, it is saved to the folder we just created/root/designertutorial
In this way, a *. Pro file is created. Next we will create another dialog box.
Open the new dialog box from File> new in the menu bar, and select the second one: Dialog,
And then save it to the created Folder/root/designertutorial.
At this time, a from1 will appear in your QT designer.
Change the caption in the window in the lower-right corner. The original content "form1" is changed to "my second QT desiger Program-call and exit ",
Name, the original content "form1" is changed to "form_main"
We can see that the title bar Text of the window has changed to "form1" and "my second QT desiger program -- call to exit", isn't it?
Click the Pushbutton in the toolbox above the left window (the icon marked with OK)
Select a proper size with the mouse. Double-click the Pushbutton,
We can change the words displayed on the button.
Here we replace the words "pushbutton1" with "Exit my program", and then select OK.
Now we can see that the tag on the button will change to "Exit my program.
Change the name in the window "Property Editor" in the lower-right corner. Change the original content "pushbutton1" to "pbtnclose"
Now we want to close our application by clicking the "Exit my program" button while the program is running,
So what should we do?
Maybe you have already thought of adding a signal and a slot for it. Is that true?
Congratulations! You have learned the core content of QT.
Click F3 (or select edit-> connections from the menu bar), and then click the "Exit my program" button.
Now we can see the dialog of view and edit connection. Select clicked in signal. In slot, select
Select close (). Select form_main in reciever. Then select OK.
We are almost done. Save. If you want to see what the applet looks like.
You can use Ctrl + T to view the preview. click the button to see if the window is closed, right?
At this time, we only need a small main. cpp to compile. Similarly, our QT designer can generate main. cpp for us.
Open the new dialog box from File> new in the menu bar, and select the last: C ++ main-file (main. cpp ).
And then save it to the created Folder/root/designertutorial.
Now let's compile our program.
Generate the MAKEFILE file:
[Root @ localhost designertutorial] # qmake
Compile:
[Root @ localhost designertutorial] # Make
/Usr/lib/qt-3.1/bin/UIC form_main.ui-o. UI/form_main.h
G ++-C-pipe-wall-w-O2-March = i386-mcpu = i686-g-dglx_glxext_legacy-fno-use-cxa-atexit-fno-exceptions tions-dqt_no_debug- i/usr/lib/qt-3.1/mkspecs/default-I. -I/usr/lib/qt-3.1/include-I. UI/-I. MOC/-o. OBJ/main. O main. CPP
/Usr/lib/qt-3.1/bin/UIC form_main.ui-I form_main.h-o. UI/form_main.cpp
G ++-C-pipe-wall-w-O2-March = i386-mcpu = i686-g-dglx_glxext_legacy-fno-use-cxa-atexit-fno-exceptions tions-dqt_no_debug- i/usr/lib/qt-3.1/mkspecs/default-I. -I/usr/lib/qt-3.1/include-I. UI/-I. MOC/-o. OBJ/form_main.o. UI/form_main.cpp
/Usr/lib/qt-3.1/bin/MOC. UI/form_main.h-o. MOC/moc_form_main.cpp
G ++-C-pipe-wall-w-O2-March = i386-mcpu = i686-g-dglx_glxext_legacy-fno-use-cxa-atexit-fno-exceptions tions-dqt_no_debug- i/usr/lib/qt-3.1/mkspecs/default-I. -I/usr/lib/qt-3.1/include-I. UI/-I. MOC/-o. OBJ/moc_form_main.o. MOC/moc_form_main.cpp
G ++-O tutorial. OBJ/main. o. OBJ/form_main.o. OBJ/moc_form_main.o-L/usr/lib/qt-3.1/lib-L/usr/x11r6/lib-lqt-MT-lxext-lx11-LM
[Root @ localhost designertutorial] #./tutorial
[Root @ localhost designertutorial] # ls
Form_main.ui main. cpp makefile tutorial tutorial2.pro
We can see that this is our executable program,
Run:
[Root @ localhost designertutorial] #./tutorial
Click the button to see if the window is closed. Isn't that what we expect?
Summary:
Here we learned how to use QT designer in Linux and how to add a component signal.
It's also easy, isn't it?
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.