Use Qt and KDevelopDesigner to develop a Linux Gui

Source: Internet
Author: User
Use Qt and KDevelopDesigner to develop the Linux graphical interface-general Linux technology-Linux programming and kernel information. The following is a detailed description. Use Qt to generate a graphical interface. One method is to use KDevelop Designer to design the interface, compile and run the interface using command lines, and the other method is to design the interface using Qt3 Designer and KDevelop: c/C ++ or KDevelop: KDE/C ++ for compiling and running. The complete process of the example is as follows:

1. Open KDevelop Designer.
2, File ---> New ---> Main Window, use the default settings.
3. Save it to the/root/qt directory.
4,
[Root @ localhost qt] # ll
-Rw-r -- 1 root 18452 Oct 9 13:49 form2.ui
[Root @ localhost qt] # touch hello. cpp
[Root @ localhost qt] # vim hello. cpp
[Root @ localhost qt] # cat hello. cpp
# Include
# Include
# Include

Main (int argc, char * argv [])
{

QApplication app (argc, argv );
Form2 * fr = new Form2;
Fr-> show ();
App. setMainWidget (fr );
Return app.exe c ();
}
[Root @ localhost qt] # qmake-project
[Root @ localhost qt] # ll
Total 40
-Rw-r -- 1 root 18452 Oct 9 13:49 form2.ui
-Rw-r -- 1 root 219 Oct 9 13:57 hello. cpp
-Rw-r -- 1 root 309 Oct 9 :59 qt. pro
[Root @ localhost qt] # mv qt. pro hello. pro
[Root @ localhost qt] # ll
Total 40
-Rw-r -- 1 root 18452 Oct 9 13:49 form2.ui
-Rw-r -- 1 root 219 Oct 9 13:57 hello. cpp
-Rw-r -- 1 root 309 Oct 9 13:59 hello. pro
[Root @ localhost qt] # qmake
[Root @ localhost qt] # ll
-Rw-r -- 1 root 18452 Oct 9 13:49 form2.ui
-Rw-r -- 1 root 219 Oct 9 13:57 hello. cpp
-Rw-r -- 1 root 309 Oct 9 13:59 hello. pro
-Rw-r -- 1 root 2076 Oct 9 13:59 form2.h
-Rw-r -- 1 root 3402 Oct 9 13:59 Makefile

The qmake command generates the form2.h header file, which contains the Form2 class declaration.

[Root @ localhost qt] # make
[Root @ localhost qt] # ll
Total 940
-Rw-r -- 1 root 29531 Oct 9 13:59 form2.cpp
-Rw-r -- 1 root 2076 Oct 9 13:59 form2.h
-Rw-r -- 1 root 188712 Oct 9 13:59 form2.o
-Rw-r -- 1 root 18452 Oct 9 13:49 form2.ui
-Rwxr-xr-x 1 root 321718 Oct 9 hello
-Rw-r -- 1 root 219 Oct 9 13:57 hello. cpp
-Rw-r -- 1 root 109088 Oct 9 :59 hello. o
-Rw-r -- 1 root 309 Oct 9 13:59 hello. pro
-Rw-r -- 1 root 3402 Oct 9 13:59 Makefile
-Rw-r -- 1 root 4721 Oct 9 13:59 moc_form2.cpp
-Rw-r -- 1 root 193144 Oct 9 moc_form2.o
[Root @ localhost qt] #./hello, you can see the graphic interface.

Example 2: hello world graphic window,
[Root @ localhost ~] # Mkdir/tmp/feifei
[Root @ localhost ~] # Cd/tmp/feifei
[Root @ localhost feifei] touch hello. cpp
[Root @ localhost feifei] qmake-project
[Root @ localhost feifei] mv qt. pro hello. pro
[Root @ localhost feifei] qmake
[Root @ localhost feifei] make
[Root @ localhost feifei]./run hello to see the graphic interface.

[Root @ localhost feifei] # ll
Total 176
-Rwxr-xr-x 1 root 71883 10-09 hello
-Rw-r -- 1 root 227 10-09 hello. cpp
-Rw-r -- 1 root 83532 10-09 hello. o
-Rw-r -- 1 root 286 10-09 hello. pro
-Rw-r -- 1 root 2983 10-09 Makefile
[Root @ localhost feifei] # cat hello. cpp
# Include
# Include

Int main (int argc, char * argv [])
{
QApplication app (argc, argv );
QLabel * label = new QLabel ("Hello worl! ", 0 );
App. setMainWidget (label );
Label-> show ();
Return app.exe c ();
}
[Root @ localhost feifei] #

Example 3: Compile and run KDevelop: KDE/C ++:
1. Open Qt3 Designer
2, File ---> New ---> C ++ project, save to/root/qt2
3. File ---> New ---> C ++ Main File (main. cpp). Save the File according to the default settings. The main. cpp editing page is displayed.
4. Open KDevelop: KDE/C ++
5. Project --> Import exiting project, and select the saved directory/root/qt2 to confirm.
6. Build ---> Build project,
7. Build ---> Execute Main program. The graphic interface is displayed after running the program.

Note: This method is only applicable to Qt3 Designer, but not KDevelop Designer. However, it can be configured to support C ++ editing.

The prompt information is as follows:
There is no plugin for editing C ++ code installed.
Note: Plugins are not available in static Qt configurations.

The above has been tested in Qt3 and Qt4. For more information, see "C ++ GUI QT3 programming".
Related Article

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.