Compile the QtHelloworld program on Ubuntu

Source: Internet
Author: User
Without QtCreatorIDE, I only use my favorite Emacs and command line to create a helloworld project. Install and configure idea in Gtk and QT compiling environments in Ubuntu

Without Qt Creator IDE, I only use my favorite Emacs and command line to create a hello world project.

Install and configure http://www.linuxidc.com/Linux/2013-08/88539.htm in Gtk and QT compiling environment in Ubuntu

Building http://www.linuxidc.com/Linux/2013-07/87576.htm in QT environment in Linux

Ubuntu QT console program cannot run solution and XTerm configuration method http://www.linuxidc.com/Linux/2013-06/86244.htm

Ubuntu 10.04 QT4.7.4 porting detailed http://www.linuxidc.com/Linux/2013-01/77930.htm

Ubuntu 14.04 installation and deployment of Qt5 Development Environment http://www.linuxidc.com/Linux/2014-05/101774.htm

1. Make sure that/usr/bin/qmake points to qmake installed in Qt 5.2.0.

/Usr/bin # mv qmake qmake_bk
/Usr/bin # ln-s/home/likewise-open/CHN/shu6889/Qt5.2.0/5.2.0/gcc_64/bin/qmake./qmake

2. Write the Code:

Create the helloworld directory and add the main. cc file.

# Include
# Include
Int main (int argc, char * argv []) {
QApplication app (argc, argv );
QLabel hello ("

Welcome to my first WikiHow Qt program ");
Hello. setWindowTitle ("My First WikiHow Qt Program ");
Hello. resize (400,400 );
Hello. show ();
Return app.exe c ();
}

3. Create a project file

In the helloworld directory, run the following command:

Qmake-project

Now I get the helloworld. pro file.

######################################## ##############################
# Automatically generated by qmake (3.0 )?? 12? 16 15:49:40 2013
######################################## ##############################
TEMPLATE = app
TARGET = helloworld
INCLUDEPATH + =.
# Input
SOURCES + = main. cc

4. Compile

Run qmake without parameters. In this way, the Makefile file is obtained.

Qmake
Make

-LGL Link error. Install mesa.

Apt-get install libgl1-mesa-dev

However, some new Link errors are returned:

Main. o: In function 'main ':
Main. cc :(. text. startup + 0x27): undefined reference to 'qapplication: QApplication (int &, char **, int )'
Main. cc :(. text. startup + 0x56): undefined reference to 'qlabel: QLabel (QString const &, QWidget *, QFlags )'
Main. cc :(. text. startup + 0x84): undefined reference to 'qwidget: setWindowTitle (QString const &)'
Main. cc :(. text. startup + 0xa9): undefined reference to 'qwidget: resize (QSize const &)'
Main. cc :(. text. startup + 0xb1): undefined reference to 'qwidget: show ()'
Main. cc :(. text. startup + 0xb6): undefined reference to 'qapplication: exec ()'
Main. cc :(. text. startup + 0xc1): undefined reference to 'qlabel ::~ QLabel ()'
Main. cc :(. text. startup + 0xc9): undefined reference to 'qapplication ::~ QApplication ()'
Main. cc :(. text. startup + 0xe5): undefined reference to 'qapplication ::~ QApplication ()'
Main. cc :(. text. startup + 0x106): undefined reference to 'qlabel ::~ QLabel ()'
Main. cc :(. text. startup + 0x118): undefined reference to 'qlabel ::~ QLabel ()'
Collect2: error: ld returned 1 exit status
Make: *** [helloworld] Error 1

Add a line to the helloworld. pro file:

QT + = widgets

Recompile. Okay.

Run the hellowordl program and check the Qt window.

When you switch to Windows for development, you do not need to use the command line for development. Use Qt Creator to open the helloworld. pro file. Some configurations are used by default. Compiled and run successfully.

Qt details: Click here
Qt: Click here

For more information about Ubuntu, see Ubuntu special page http://www.linuxidc.com/topicnews.aspx? Tid = 2

This article permanently updates the link address: Http://www.linuxidc.com/Linux/2014-06/103671.htm

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.