All about programming in GNU/LINUX

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();
}

Advertisements

2 responses

  1. Nice…

    June 28, 2012 at 1:04 pm

    • Thank you very much!!do follow the series for a great tour on developing apps in GNU/LINUX 🙂

      June 28, 2012 at 1:17 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s