Install Qt4-[software and system]

Source: Internet
Author: User
Install Qt4-[software and system]-general Linux technology-Linux programming and kernel information. For details, refer to the following section. Last spring, I wrote a small software program with Qt3. I feel that it is very convenient to use Qt as the interface program in Linux, which is similar to VC in Windows. therefore, when the ubuntu 7.10 system was installed last time, the Qt3 development kit was installed. By the way, how can I install the Qt3 software package? .

# Sudo apt-get install qt3-dev-tools qt3-examples python-qt3 qt3-designer qt3-assistant

Now the Qt version has reached the Qt-4.3.2, recently intends to write a small program with Qt4. Install the following software package on the Internet:

# Sudo apt-get install qt4-dev-tools qt3-examples qt4-designer qt3-assistant python-qt4

The qt3-examples qt3-assistant here, because the corresponding qt4 version apt-get cannot be found, so the previous version is installed. below is a hello world of Qt4, which comes from the first program of C ++ GUI Programming with Qt 4, as follows:

# Include
# Include
Int main (int argc, char * argv [])
{
QApplication app (argc, argv );
QLabel * label = new QLabel ("Hello Qt! ");
Label-> show ();
Return app.exe c ();
}

We can see that the simple hello world and Qt3 have some changes.

Compile the program as follows:
# Qmake-project
Generate the configuration file xxx. pro (where xxx is the project file name)
# Qmake
Generate Makefile automatically
# Make
The following error message is displayed:
Me. cpp: 1: 28: Error: qt4/QApplication: No such file or directory
Me. cpp: 2: 22: Error: qt4/QLabel: No such file or directory
Me. cpp: In function 'int main (int, char **)':
Me. cpp: 5: Error: 'qapplication' not declared in this scope
Me. cpp: 5: Error: expected '; 'before' app'
Me. cpp: 6: Error: 'qlabel' has not been declared in this scope
Me. cpp: 6: Error: 'label' has not been declared in this scope
Me. cpp: 6: Error: expected type-specifier before 'qlabel'
Me. cpp: 6: Error: expected '; 'before' qlabel'
Me. cpp: 8: Error: 'app' has not been declared in this scope
Me. cpp: At global scope:
Me. cpp: 3: Warning: Unused parameter 'argc'
Me. cpp: 3: Warning: Unused parameter 'argv'
Make: *** [me. o] Error 1

Open the Makefile file and find that all the Qt files in it are related to Qt3. Use the qmake-v command to find that qmake version is 3, whereis find the directory where the qmake command is located/usr/bin/qmake

# Ls-l qmake *
Lrwxrwxrwx 1 root 23 2008-01-18 20:53/usr/bin/qmake->/etc/alternatives/qmake
-Rwxr-xr-x 1 root 2052100 2007-10-31 0/ usr/bin/qmake-qt3
-Rwxr-xr-x 1 root 3378140/usr/bin/qmake-qt4
# Ls-l/etc/alternatives/qmake
Lrwxrwxrwx 1 root 18 2008-01-18 20:56/etc/alternatives/qmake->/usr/bin/qmake-qt3

Now it's clear that qmake is a link that points to the qmake-qt3 via alternatives/qmake, and now you want to make qmake A qmake-qt4 by default, as long as you redirect the link
# Sudo rm/etc/alternatives/qmake
# Sudo ln-s/usr/bin/qmake-qt4/etc/alternatives/qmake
Similarly, if you want the designer command to use version 4 by default
# Sudo rm/etc/alternatives/designer
# Sudo ln-s/usr/bin/designer-qt4/etc/alternatives/designer

Now, qmake-project, qmake, and make all the above hello world files will go smoothly.
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.