Archive for the ‘Hacks’ Category

How to use Qt’s .pro file variable in C++ code

Thursday, July 28th, 2011

So today my colleague ask me ” I have a variable VERSION in .pro file (qmake project file) I want to use that variable in my C++ code, How to do that?”

After a little search on Google I figured that we have export project files variable as a macro for C/C++ code and it very easy.

As the per problem we want VERSION variable in C++ code. So in  project file we write

DEFINES += VERSION=\\\"$$VERSION\\\"

and in C/C++ code just

qDebug()<< VERSION ;

this is just a awesome.

Good News About KDE!!

Friday, December 31st, 2010

In my last post I mention about the disappointment I got because of No KDE day at Foss.in/2010.

But here’s the GOOD NEWS instead of KDE day we all (Kde developer’s team Kde India ) decided to have a KDE conference in India hurry!! :) .

Team KdeIndia

Photo credit Dinesh Sai

So we have First Ever KDE conference in India details are as follow:

Website : http://conf.kde.in

When:  9 – 13 March.

Where : R V College Of Engineering,
R V Vidyanikethan Post,
Mysore Road,
Bengaluru – 560004,
Karnataka, India

So lock your calendars, apply for leaves and get prepare for the event!

All are welcome from newbies to Old contributors.

See you there Enjoy :) .

Process state check using bash script

Sunday, September 19th, 2010

After a long time :) .
well recently I came across a situation where my server application use to crash randomly, so to keep it alive all the time I wrote a small bash scrip, well I know, I have to check my Server application code and fix it but that was the demo time so 1st make it work as it is then we will fix the corner cases ;) .

but bash script was a fun..

This is how my script looks


#!/bin/sh

while true; do

# If process is not running we will get only 1 else 1 + number of instances
check=`ps ax| grep -c TCPServer`
if [ "$check" -lt 2 ]; then

echo "not running"
# Start the server again
cd ~/TCPServer/
./TCPServer > /dev/null 2>&1 &
else
echo "running"

fi

sleep 1m

done

Installing Qt for Symbian SDK 4.6.2 on Linux

Saturday, March 20th, 2010

As we all know now Qt can run on Symbian Phones but there is one problem all SDK’s and Tool chain of this officially supports windows.

So how about people like us(who’s default OS is Linux) cant we develop for Symbian using Qt?

In answer to this question I found many articles/blogpost how to install Qt for Symbian on Linux but this is the one which work for me http://lizardo.wordpress.com/2010/02/18/installing-qt-for-symbian-sdk-4-6-2-on-linux/ .

I followed this post every thing was perfect except 2 things

1) creating .sis(the Symbian executable) file.

2) creating installer.sis(the Symbian executable installer) file.

and i figured out how to do that too.

I re-witting the basic installation from http://lizardo.wordpress.com/2010/02/18/installing-qt-for-symbian-sdk-4-6-2-on-linux/ . plus my Hacks/Tricks .

Tool-Chain:

Download all required files to a single directory (e.g. “~/downloads”):

For building the native tools from gnupoc, you will need:

  • the GCC C/C++ compilers
  • development files for zlib
  • development files for openssl

On Ubuntu, you can install these using the following command:

sudo apt-get install build-essential zlib1g-dev libssl-dev

Installation

First, install GnuPoc + S60 SDK + the Open C/C++ plugin:

./gnupoc_1.15_installer_v2.sh \
<download-dir> \
<gnupoc-dir>\
<x.y>

Replace <download-dir> with the location of all files downloaded in previous section (e.g. “~/downloads”), <gnupoc-dir> with the destination directory for GnuPoc and the SDK files (e.g. “~/gnupoc”) and <x.y> (Note that this is not the directory) with the SDK version you want to install (e.g. “3.1″ or “5.0″). Note that both directories must have absolute paths.

If installation was successful, you should see an output like:

Installation has finished. Before using the GnuPoc SDK, run these commands on the console:

export PATH=<gnupoc-dir>/bin:$PATH
export EPOCROOT=<gnupoc-dir>/symbian-sdks/5.0/ # trailing “/” is required!

(These commands must be run again every time a new console is opened.)

Run the commands as instructed on the message. Next, install Qt for Symbian:

./qt_for_symbian_4.6.2_linux_installer_v3.sh \
<download-dir> \
<qt-s60-dir>

Replace <download-dir> with the location of all files downloaded in previous section (e.g. “~/downloads”), and <qt-s60-dir> with the destination directory for the Qt files (e.g. “~/gnupoc/qt-4.6.2″). Note that both directories must have absolute paths.

If installation was successful, you should see an output like:
Installation has finished. Before using the Qt for Symbian SDK, run this command on the console:

export PATH=<qt-s60-dir>/bin:$PATH
unset QMAKESPEC    # make sure there is no QMAKESPEC variable set

(This command must be run again every time a new console is opened.)

Before using Qt for Symbian, you should run the command as instructed on the message above.

Usage example

Install Nokia Smart Installer :

  1. Unzip Nokia Smart Installer  on top of your installed Qt for Symbian folder in <qt-s60-dir>

To test the installation, I will describe how to build the “colliding mice” example.

  1. cd into the example source:
  2. cd <qt-s60-dir>/examples/graphicsview/collidingmice/

  3. Now build the example and generate the SIS file
  4. qmake
    make debug-gcce
    make sis
    make installer_sis

Chnages/Hack/Tricks

You will notice that when  you do make installer_sis
there is some error related to “createpackage.bat” file this is batch file what we have to do is open

Makefile

search for ok_installer_sis:

and change createpackage.bat to createpackage.sh

createpackage.sh is already there just that its not getting reflected in Makefile .

and now if you do make installer_sis you will get collidingmice_installer.sis

I have also created one bash function as follow:

function qtsis {
export PATH=<gnupoc-dir>/bin:$PATH
export EPOCROOT=<gnupoc-dir>/symbian-sdks/5.0/ # trailing "/" is required!
export PATH=<qt-s60-dir>/bin:$PATH
unset QMAKESPEC    # make sure there is no QMAKESPEC variable set
}

Add this function in your .bashrc file with proper path which you get after installation.

and do source ~/.bashrc

now when ever you want to compile your qt code for Symbian 1st execute qtsis command on your terminal then other qt commands :)

A few notes:

  • Make sure Qt is installed on the device before installing Qt applications. The easiest way to install it is to copy the “qt_installer.sis” package found under <qt-s60-dir> over bluetooth and open the received message to begin the installation.
  • Only the “debug-gcce” (if you are using the GCCE toolchain AKA “CodeSourcery toolchain”) or “debug-armv5″ (if you are using RVCT) will work, because the current Qt releases only ship debug versions of the libraries

enjoy :)

My 1st Open-Source contribution

Tuesday, January 12th, 2010

Long time since I made a blog post … My new year started with a bang .. completing one item from my own wish list i.e contribute to a Open-Source project.

I have started contributing to KDE Kate. My 1st patch accepted for BUG No. 184055 which is now in kde 4.4 :) . Hurray …

About the fix:
Problem : Previously in Kate’s document view the last added file was not getting sorted as per the given sorting option.
Solution: Whenever user open the file call the document views sorting.

* for more details  here is the bug description .

To download patch click here.

Though it was really small bug fix it was really a good learning experience. I will try to be consistent with contributing to KDE :) .

All credit goes to Pradeepto and Prashanth for encouraging and guiding me :) . Thanks guys.

Python CSV Hack!

Wednesday, December 9th, 2009

This is just a simple hack I did today morning.

This is to calculate my total internet data usages.

From my ISP Reliance Netconnect Broadband + I get one CSV file with all the details, and to view this I don’t have any spreadsheet viewer kinda thing installed on my system, so how to calculate the usages?

I wrote small python script to do so, this is about it how it works.

contents of CSV file looks something like this :

Date Of Access,Time Of Access,Session Duration,Data Upload(KBs),Data Download(KBs),Total Data Transferred(KBs)
22-10-2009, 07:36:58,2623,1060.50390625,7934.458984375,8994.962890625
22-10-2009, 19:47:34,13675,22826.49609375,344230.265625,367056.76171875
22-10-2009, 23:35:29,229,24.2666015625,33.56640625,57.8330078125
22-10-2009, 23:39:18,13792,838.701171875,11057.255859375,11895.95703125
23-10-2009, 03:32:53,14839,18841.23046875,104978.8837890625,123820.1142578125
23-10-2009, 20:47:20,292,117.1015625,647.9287109375,765.0302734375
23-10-2009, 20:52:12,233,226.669921875,2429.98828125,2656.658203125
23-10-2009, 03:32:49,4,0,0,0
23-10-2009, 20:56:08,22657,57322.56640625,939251.0869140625,996573.6533203125
24-10-2009, 03:13:45,1399,145.619140625,287.9228515625,433.5419921875
24-10-2009, 03:37:03,4745,199.060546875,289.611328125,488.671875
24-10-2009, 19:40:46,3172,799.1708984375,5288.591796875,6087.7626953125

Basically divided into 6 Fields ie.
Date Of Access  | Time Of Access | Session Duration  | Data Upload(KBs) | Data Download(KBs) | Total Data Transferred(KBs)
separated by “,” (comma) .

Here my required field is Total Data Transferred(KBs), thats the last field.

means I need to add last field of each row.

the python scrip for the same is:
# Open file
f = open("tel.csv")

# Read all lines in list called lines
lines = f.readlines()

# Initialize variable to store the total
total = 0.0

""" Remove the 1st line from the lines list as
it's the header which we don't require"""

lines.pop(0)

for i in lines:

""" Split each line on ","(comma)
so that you will get all the 6 fields for that line as list"""

i = i.split(",")

""" Take the last value, convert it to float
and add it to the total variable"""

total += float(i[-1])

# Print the total in Kb
print "total data uses in Kb: " + total
# Print the total in Mb
print "total data uses in Mb: " + total/1024
# Print the total in Gb
print "total data uses in Gb: " + (total/1024)/1024

Happy Hacking !!