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

  • Following many other Linux employees, Ubuntu stopped providing 32-bit ISO ImagesFollowing many other Linux employees, Ubuntu stopped providing 32-bit ISO Images
    ubuntu declares that it will stop providing the iso installer for os that the new version starting with ubuntu 17.0 (artful aardvark) will be released on october 19.
  • Setting up Ubuntu virtual machine with Hyper-V Quick Create on Windows 10Setting up Ubuntu virtual machine with Hyper-V Quick Create on Windows 10
    how to use hyper-v quick create and install ubuntu virtual hard disk to set up ubuntu linux virtual machine
  • Install and use 7 ZIP on Ubuntu LinuxInstall and use 7 ZIP on Ubuntu Linux
    if you are a windows user and you have ever sent/received large files online, you probably have not heard of the 7 zip file compression tool. installing 7 zip on windows is quite simple, so what about on ubuntu linux. the article below tipsmake will guide you how to install and use 7 zip on ubuntu linux.
  • 5 best Ubuntu-based Linux distributions of all time5 best Ubuntu-based Linux distributions of all time
    ubuntu, a debian-based linux operating system, has been around since 2004; since then, some great distributions based on ubuntu's source code have been created.
  • Why is Ubuntu LTS preferred over regular distros?Why is Ubuntu LTS preferred over regular distros?
    ubuntu is one of the most widely used linux distributions among software developers and other content creators. ubuntu is also used for many servers around the globe.
  • How to use DNS over TLS on Ubuntu LinuxHow to use DNS over TLS on Ubuntu Linux
    you can use dns in which all dns queries are processed through the encrypted tls (transport layer secure) protocol. however, most operating systems do not work with dns over tls.
  • How to install VPN on UbuntuHow to install VPN on Ubuntu
    encryption of internet use on linux makes a lot of sense. in today's article, tipsmake.com will read with you how to install a vpn on ubuntu, the most popular linux distribution.
  • 10 new features of Linux Ubuntu 19.0410 new features of Linux Ubuntu 19.04
    the following article summarizes the top 10 new features of ubuntu 19.04 'disco dingo'. let tipsmake.com find out what they are and how much ubuntu 19.04 can surprise you!
  • How to Uninstall Ubuntu SoftwareHow to Uninstall Ubuntu Software
    this wikihow teaches you how to uninstall software from a computer running ubuntu linux, as well as how to uninstall ubuntu from your computer. if your computer is running both linux and a different operating system, you can erase the...
  • How to Install Ubuntu in WindowsHow to Install Ubuntu in Windows
    this wikihow teaches you how to install and run ubuntu linux on your windows computer's desktop. you'll use a free program called virtualbox to do so; this will allow you to run ubuntu without having to replace your current operating...