Install Qt4 and use Qt4 in Ubuntu

Source: Internet
Author: User
Although the local machine is installed with Gnome Ubuntu, you can also develop Qt programs. If you download and compile Qt4 normally, it will take a long time. Therefore, use apt-get to install Qt4. Run: $ sudoapt-getinstalllibqt4-devlibqt4-debuglibqt4-guilibqt4-sqlqt4-dev-toolsqt4-docqt4-designerqt4-qtconfi

Although the local machine is installed with Gnome Ubuntu, you can also develop Qt programs. If you download and compile Qt4 normally, it will take a long time. Therefore, use apt-get to install Qt4.

Run:

$ Sudo apt-get install libqt4-dev libqt4-debug libqt4-gui libqt4-sql qt4-dev-tools qt4-doc qt4-designer

The system automatically installs and sets the environment. This will be faster. If you compile the source code directly, it will take a very long time to install it.

Compile an example program:

# Include
# Include

Int main (int argc, char * argv [])
{
QApplication app (argc, argv );

QPushButton hello ("Hello, man! ");
Hello. resize (100, 30 );

Hello. show ();
Return app.exe c ();
}


Then run:

$ Qmake-project
$ Qmake
$ Make
$./Project Name

As follows:

Isp @ hitisp :~ /Qtsrc $ vim QtHello. cpp
Isp @ hitisp :~ /Qtsrc $ qmake-project
Isp @ hitisp :~ /Qtsrc $ qmake
Isp @ hitisp :~ /Qtsrc $ make
G ++-c-pipe-g-Wall-W-D_REENTRANT-DQT_GUI_LIB-DQT_CORE_LIB-I/usr/share/qt4/mkspecs/linux-g ++-I. -I/usr/include/qt4/QtCore-I/usr/include/qt4/QtCore-I/usr/include/qt4/QtGui-I/usr/include/qt4/QtGui -I/usr/include/qt4-I. -I. -I. -o QtHello. o QtHello. cpp
G ++-o qtsrc QtHello. o-L/usr/lib-lQtGui-lQtCore-lpthread
Isp @ hitisp :~ /Qtsrc $ ls
Makefile QtHello. cpp QtHello. o qtsrc. pro
Isp @ hitisp :~ /Qtsrc $./qtsrc


The running result is a small window with only one button titled project name.

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.