How to Create Your First Qt Program on Ubuntu Linux

Method 1 of 1:

Qt 4.8 SDK Compilation Instructions

  1. How to Create Your First Qt Program on Ubuntu Linux Picture 1
    For this exercise we are going to open up a terminal on Ubuntu Linux and issue the following command which will create the main directory for a Qt program.
    1. Type/Copy/Paste: mkdir QtHelloWorld
  2. How to Create Your First Qt Program on Ubuntu Linux Picture 2
    Change into your QtHelloWorld directory by issuing the following command
    1. Type/Copy/Paste: cd QtHelloWorld
    2. This is very important to make sure you are in the correct directory when creating your Qt program.
  3. How to Create Your First Qt Program on Ubuntu Linux Picture 3
    While we are in the QtHelloWorld directory, we are going to create our Qt Program source code file
    1. Type/Copy/Paste: nano main.cpp
    2. or
    3. Type/Copy/Paste: gedit main.cpp
    4. This command will create the main.cpp file for the Qt program
  4. How to Create Your First Qt Program on Ubuntu Linux Picture 4
    Now add the following lines in the code box below to your main.cpp source code file.
  1. Type/Copy/Paste:
#include #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.exec(); } 
  1. Save the file as main.cpp and exit
    1. Make sure you are in the QtHelloWorld directory before you enter the following commands below to build and compile the file.
  2. Type/Copy/Paste: qmake -project
    1. This will create the Qt project file
  3. Type/Copy/Paste: qmake
    1. This will create the Qt make file
  4. Type/Copy/Paste: make
    1. This will compile the Qt make file on your system into an executable program. At this point, providing that there are no errors the file should compile into an executable program.
  5. Finally execute your program by running the Qt executable. Use the command ./ to run your executable file or type the name of the executable program on the terminal line.
  6. Type/Copy/Paste: ./QtHelloWorld
3.5 ★ | 2 Vote

May be interested

  • How to Install Windows from UbuntuPhoto of How to Install Windows from Ubuntu
    this wikihow teaches you how to install windows 10 on a pc that's already running ubuntu linux. before you get started, make sure you've already purchased a windows license and product key. don't worry if you don't have windows install...
  • How to Install Android on Ubuntu Linux with Eclipse IDEPhoto of How to Install Android on Ubuntu Linux with Eclipse IDE
    this document will prepare an overview of the steps you will take to install and configure android on your ubuntu linux system. you must have oracle java jdk or openjdk on your system before installing android sdk. openjdk (aka open java...
  • How to Upgrade Oracle Java on Ubuntu LinuxPhoto of How to Upgrade Oracle Java on Ubuntu Linux
    this document is intended to assist with the upgrade of the many new release versions of oracle java jdk/jre on ubuntu linux. every so often, due to bug fixes and security issues oracle releases updates to their version of the java...
  • How to Solve Incorrect Password ...Try Again Error in UbuntuPhoto of How to Solve Incorrect Password ...Try Again Error in Ubuntu
    this short article will show you how solve 'incorrect password ...try again' error in ubuntu 13.04 raring ringtail. you get this error mostly when you trying to run some software on your system that need root password. why is that? it's...
  • How to Enable Oracle Java in Your Web Browsers on Ubuntu LinuxPhoto of How to Enable Oracle Java in Your Web Browsers on Ubuntu Linux
    this document covers enabling 32-bit and 64-bit oracle java browser plugin in 32-bit ubuntu linux and 64-bit ubuntu linux. for the two most popular web browsers for ubuntu linux at this time, which are google chrome and mozilla firefox....
  • How to Install Ubuntu ServerPhoto of How to Install Ubuntu Server
    this wikihow teaches you how to install ubuntu server on a windows computer. ubuntu server is a free, linux-based server operating system that you can use to host your web services. open the ubuntu server download page. go to...