Qt-designer tutorial 1-helloworld

Source: Internet
Author: User
Tags qt designer
Chapter 1 Hello world! Okay. Now let's learn how to use QT designer to design our QT application.
Now let's make some preparations. 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 test] # mkdir/root/designertutorial1
[Root @ localhost test] # cd/root/designertutorial1 then open QT designer and enter designer directly on the command line, as shown below:
[Root @ localhost designertutorial1] # Designer &
[3] 16544
[Root @ localhost designertutorial1] # The "QT designer-New/Open" dialog box is displayed. This is a new dialog box,
You can open it from File> new in the menu bar.
Select the first "C ++ Project" in the dialog box, click OK, and change the name. Here we change to tutorial1.pro to save the changes,
By default, it is saved to the folder/root/designertutorial1 we just created so that we can create a *. Pro file. 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/designertutorial1.
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 first QT desiger program ",
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" to "my first QT desiger program", 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 "Hello World !", Then select OK.
Now we can see that the tag on the button has changed to "Hello World !" Now.
Change the name in the window "Property Editor" in the lower-right corner, and change the original content "pushbutton1" to "pbtnhello", which is basically complete. Save. If you want to see what the applet looks like.
You can use Ctrl + T to view the preview. 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/designertutorial1. Now let's compile our program.
Generate the MAKEFILE file:
[Root @ localhost designertutorial1] # qmake
Compile:
[Root @ localhost designertutorial1] # Make
/Usr/lib/qt-3.1/bin/UIC form1.ui-o. UI/form1.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 form1.ui-I form1.h-o. UI/form1.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/form1.o. UI/form1.cpp
/Usr/lib/qt-3.1/bin/MOC. UI/form1.h-o. MOC/moc_form1.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_form1.o. MOC/moc_form1.cpp
G ++-O tutorial1. OBJ/main. o. OBJ/form1.o. OBJ/moc_form1.o-L/usr/lib/qt-3.1/lib-L/usr/x11r6/lib-lqt-MT-lxext-lx11-LM
[Root @ localhost designertutorial1] # ls
Form1.ui form1.ui ~ Main. cpp makefile tutorial1 tutorial1.pro
We can see that tutorial1 is our executable program,
Run:
[Root @ localhost designertutorial1] #./tutorial1
 
Success. Summary:
Here we learned how to use QT designer in Linux,
I also learned how to compile the QT program. It's very simple, isn't it?

 

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.