All about programming in GNU/LINUX

ART OF APP BUILDING IN GNU/LINUX using QT and System Programming

ART OF APP BUILDING IN GNU/LINUX-2:Creating a window with username and time-date info(combining system programming and QT)

 

 

Image

 

Here it is the second post of the series “The Art of app building in GNU/LINUX”.One of the powerful feature of QTCREATOR is that it can interpret HTML codes,in short its HTML aware.This property is used to set the colour and font of the text.
this this post we’ll create a simple app for GNU/LINUX, A basic window displaying User name and the time-date info,here goes the tutorial , happy coding , happy hacking ..

Create a Empty Qt project as shown in the reference video .Add a C++ source file as illustrated in the video, write this piece of into it and run .

 

#include<QApplication>
#include<QLabel>
#include<time.h>
#include<unistd.h>
#include<pwd.h>
#include<string.h>
int main(int argc,char *argv[])
{
    char *buff,*buff1;
    buff=new char [100];
    buff1=new char [1000];
    time_t ticks;
    ticks=time(NULL);
    buff=ctime(&ticks);//buff now contains the date and time details
    struct passwd *pwd;
    pwd=getpwuid(getuid());//to get the usr name
    QApplication app(argc,argv);
    strcat(buff1,”<font color=blue><h2>HI “);
    strcat(buff1,pwd->pw_name);//obtaining the user name
    strcat(buff1,”</h2></font>”);

    strcat(buff1,buff);
/*only one string is supposed to be passed onto Qlabel to display it in the window
  so the strings are concatenated to form one big string with HTML code for font and
  colour with user name   and date-time information*/

    QLabel *label1=new QLabel(buff1);

    label1->showNormal();
    return app.exec();
}


ART OF APP BUILDING IN GNU/LINUX-1:CREATING LAYOTS , SIGNALS AND SLOTS , TABS AND BUDDIES USING QT

End result of the tutorial

QT CREATOR is a very simple , yet powerful tool to create Graphical User Interfaces .But development of effective Application in any operating system is possible only with the help of System programming in that respective environment .In the series of videos to follow , i will take you through the fascinating world of APP making in GNU/LINUX combining System programming  in GNU/LINUX using C and QT creator to creator to GUI using C++.Yes, as you would be knowing by now , the prerequisites are C ,C++ , some knowledge about GNU/LINUX environment,passion to develop apps for GNU/LINUX   and lots and lots of imagination!!!So the process of App-building in any environment is not just about applying the Logic , Its an ART!!Here is the first tutorial of the series which just involves basic concepts of creating GUI using QT.

The preferred OS is UBUNTU 12.04 .To Install QT CREATOR, Just go to SOFTWARE CENTER  or type in “sudo apt-get install qtcreator” from terminal