Wednesday, February 17, 2010

Dark Knight - My Qt Creator Dark Color scheme

Here is my own Dark color scheme for Qt Creator. I have named it as Dark Knight. :P

See the screenshot below.


To use this color scheme, download this XML file and follow following steps.

How to install:
  1. Goto the Qt Creator setting directory, which is

    Documents and Settings\ <user name> \Application Data\Nokia\qtcreator
    under Microsoft Windows XP (replace <user name> with your login name)

    and

    ~/.config/Nokia\qtcreator
    under Linux.
  2. Goto the directory named styles.
  3. Place the downloaded XML file in this directory.

How to change the color scheme in Qt Creator:

  1. Goto Fonts & Colors settings.
    (To open, go through Tools->Options->Text Editor->Font & Colors)
  2. Scroll down and select the new color scheme named Dark Knight.
  3. Press OK.
  4. Enjoy. :)
Note: As Qt Creator is in active development, above mentioned steps may not work with future version of Qt Creator.

I hope you people like it. Suggestions & comments are welcome.

Technorati tags: , , .

Friday, February 12, 2010

How To: Compile MICO-CORBA in SUN Solaris

Here are the steps to download, build and install the MICO COBRA under SUN Solaris machine.

  1. Download MICO CORBA.
  2. Open the terminal window in the directory where you kept the downloaded archive file.
  3. Extract the content of the downloaded archive.

    gzip -dc mico-*.tar.gz | tar -xf –

    And if you are using GNU tar utility (if not installed already, get it from SUN Freeware website.) then

    tar -zxvf mico-*.tar.gz



  4. Run the configure script.

    You can set many parameters through the command line arguments to the configure script. Such parameters are, install directory, Qt directory etc. Check INSTALL.txt file for more information on the list of command line arguments.

    Here are my arguments to the configure script

    ./configure --with-qt=/sect/package/qt/ --prefix=/sect/package/mico-corba/

    Here I have enabled the support for Qt (which is installed in =/sect/package/qt/ directory) and I have indicated that I am planning to install MICO into /sect/package/mico-corba directory.

    Read INSTALL.txt for more information on this.

    Note: When I used one of configure script argument named --enable-final switch, I ended with compilation errors under Solaris. If you are also getting compilation errors, Check if you have used this switch. As per document this switch won’t work under HP-UX. I guess this is applicable to all Unices.

  5. Run the make tool.
    Issue make command for this.
    make
    or if you have GNU make installed (or install it from SUN Freeware website)
    gmake

  6. Install the MICO CORBA
    Issue the following command in terminal to install MICO to configured directory(if any set while configure script) or to the default directory.
    make install
    or
    gmake install

  7. Update the environmental variables to include MICO install directory.
    Before you can compile, link and execute your first CORBA application, you need to setup the environmental variables correctly.

    Add /sect/package/mico-corba to your PATH environment variable.
    In Bash
    PATH=$pATH:/sect/pckage/mico-corba/bin
    And in csh
    setenv PATH /sect/package/mico-corba/bin:$PATH

    Also modify LD_LIBRARY_PATH to properly link with MICO libraries.
    LD_LIBRARY_PATH=$LD_LIBRARY_PAT:/sect/package/mico-corba/lib

    If required modify the Bash Profile file to set these environment variable at start-up.

    Or you can run Solaris crle command once and add MICO lib directory in it.(Recommended method)

    crle -u -l /sect/package/mico-corba/lib


That's all.

Please leave a comment if this post was useful to you!

Saturday, November 28, 2009

Qt: The best way to set the Application version

Whenever we develop any application one of the basic stuff which we need to decide is the application version number. Historically the application version number format is one of the hot topics where many lengthy wars/debates have happened.

This post is NOT about the application version number format to use, instead in this post I would be concentrating how to set and use the application version number information in a Qt project.

If this post is on any use to you, please leave a comment. :)

First way: Defining the version information within the application source code

The application version can be set as through the string constant or preprocessor Macro defined in some header file.

I have used this method many times before.

Also, here once you create the QApplication object, you can set this application version to QApplication object and ignore this constant/Macro defined from then on. Whenever you need the application version you can directly get it from qApp global QApplication object.

You can use following APIs

  • QString applicationVersion()
  • void setApplicationVersion(const QString & version)
Second way: Defining the version information within the Qt project file.

You can use Qt QMake Macro named VERSION to define the Application version.

Eg:

VERSION = 1.0

The good thing with this QMake Macro is that, it automatically creates the .rc file under Microsoft Windows and you can see the application version number from Windows Explorer by right clicking on the executable.

Eg:

AppVersion

What I do is that, I use preprocessor Macro defined through Qt project file to pass application version number to code.

Eg:

# The application version
VERSION = 1.0

# Define the preprocessor macro to get the application version in our application.
DEFINES += APP_VERSION=\\\"$$VERSION\\\"

Note: \\\" is important! Without them, the Macro is taken as a double constant instead of string constant.

Now use the Macro APP_VERSION in your code just like any other preprocessor Macro.

Eg:
    QApplication app(argc, argv);

    // Setting the Application version
    app.setApplicationVersion(APP_VERSION);

Similarly you can set the Application date also.

You can browse the sample Qt project @ My Google code page.

Technorati tags: , , .

Wednesday, October 28, 2009

C++ Gyan of the day: Friend class and Inheritance

Check if the following code snippet is proper.


/*
 * Copyright (C) 2009 Raghavendra Nayak
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

// Program to explain the Friend class and inheritance

#include <iostream>
#include <cstdlib>

////////////////////////////////////////////////////////////////////////////////

class someClass {
public:
    void printData() {
        std::cout<<"The value of m_data is "<<m_data;
    }
private:
    int m_data;

    // declare BaseClass as the friend class to this class
    friend class BaseClass;
};

////////////////////////////////////////////////////////////////////////////////

class BaseClass {
public:
    /// @brief The BaseClass constructor.
    BaseClass() {
        std::cout<<"In BaseClass constructor.\n"
                 <<"Setting the m_data to 10.\n";
        // set m_data to 10
        m_someClassObject.m_data = 10;
        // print the set value using printData method.
        m_someClassObject.printData();
    }
protected:
    someClass m_someClassObject;
};

////////////////////////////////////////////////////////////////////////////////

class DerivedClass : public BaseClass {
public:
    /// @brief The DerivedClass constructor.
    DerivedClass() {
        std::cout<<"In DerivedClass constructor.\n"
                 <<"Setting the m_data to 20.\n";
        // set m_data to 20
        m_someClassObject.m_data = 20;
        // print the set value using printData method.
        m_someClassObject.printData();
    }
};

int main(int /*argc*/, char */*argv*/[])
{
    DerivedClass derivedClassObject;

    return EXIT_SUCCESS;
}

If you try to compile this, you will end up with compilation errors. the reason is in the comments.

Technorati tags: .

Thursday, June 18, 2009

A big sigh of relief

After 1.5 years, finally launchpad team has fixed the bug with launchpad which I had filed in launchpad itself.

Well, I cannot explain the feeling of relief you get, when you finally see the bug reported by you being marked as fixed!!

Time for a nice dinner and some sleep.. drink!

Links:

Tuesday, May 12, 2009

C Language: Program to check given character string for palindrome

A palindrome is a word, phrase, number or other sequence of units that can be read the same way in either direction. Eg: Katak, 121 etc

Following C program shows the simple way check, if the given character string is a palindrome or not.

Following code is available under GNU General Public License v3 or above.

/*
 * Copyright (c) 2009 Raghavendra Nayak
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

/*
 * C program to reverse given string, and to check whether it is a palindrome.
 */

#include <stdio.h>
#include <string.h>

/**
 * @brief function to return the given string length.
 * @param[in] string the input string.
 * @return the string length.
 */
unsigned int get_string_length(const char *string)
{
    int i;
    int string_length = 0;

    for (i = 0; string[i] != 0 && string[i] != '\n'; ++i)
        ++string_length;
    return string_length;
}

/**
 * @brief function to reverse the given string.
 * @param[in] string the input string.
 * @param[out] rev_string the reversed string would be placed in this variable.
 * @return none.
 */
void reverse(const char *in_string, char *rev_string)
{
    int i, j;
    unsigned int length;

    length = get_string_length(in_string);

    for (i = length-1, j = 0; i >= 0; --i, ++j)
        rev_string[j] = in_string[i];

    /* mark the end of string */
    rev_string[j] = 0;
}

int main()
{
    const int max_size = 100;
    int string_length = 0;

    char string[max_size];
    char reverse_string[max_size];

    printf("\nPlease enter input string: ");
    /* Note: we are not using gets, because gets is deprecated and can be
       dangerous. */
    fgets(string, max_size, stdin);

    /* remove any new line from input string,
       if fgets has put '\n' at the end of string */
    string_length = get_string_length(string);
    string[string_length] = 0;

    /* get the reversed string */
    reverse(string, reverse_string);

    /* now compare */
    if (!strcmp(string, reverse_string)) {
        printf("\nEntered string = %s, reversed string = %s."
               "\n%s = %s, hence %s is a palindrome.\n",
               string, reverse_string, string, reverse_string, string);
    } else {
        printf("\nEntered string = %s, reversed string = %s."
               "\n%s != %s, hence %s is not a palindrome.\n",
               string, reverse_string, string, reverse_string, string);
    }
    return 0;
}

Links:

Sunday, April 19, 2009

How To: Create your own local SVN repository in GNU/Linux

This article tell you about creating your own local SVN repository in your GNU/Linux box.

Even though I personally like git, I like the SVN's idea of having all your code safe somewhere in a remote server!

I personally do a lot of coding, and several times I have lost my precious programs/codes due to some stupid mistakes I did or because I don't backup my code very often. Keeping a plain backup your code is a pain, having you to maintain several copies of them, based on their version.

Hence, several times I felt that, oh God, if at all I had my own SVN server somewhere?

So, today finally tried to create my own SVN server, and voila, in less than 5 minutes, my own SVN server was up and running! I never had thought that creating your own SVN server was a such easy task.

If you people are looking for the same, this article is for you!

Here is a step by step procedure to create your own SVN server.

  1. Install SVN package.

    You need to have subversion package installed.

    If you don't have it, install it using command

    sudo apt-get install subversion
  2. Create a SVN repository.

    Next step is to create a SVN repository. First decide where you want to store your repository data? I kept my SVN repository in my home directory, so that it also gets backed up with my home directory backup. So, You can also do the same or store your SVN repository in any other place of your choice.

    Use following command to create your own SVN repository in your home directory.

    svnadmin create ~/my_svn_repo
    This command will create a directory named 'my_svn_repo in' your home directory, with SVN's repository data inside it.

    If you want to store your SVN repository somewhere else, replace

    '~/my_svn_repo'
    with your selected directory path.

  3. Change the SVN configuration for repository access.

    You need to configure the SVN to tell it about the read and write access to your repository.

    For this goto 'conf' directory present inside your SVN repository directory.

    cd ~/my_svn_repo/conf
    now open the file named svnserve.conf

    vi svnserve.conf
    OR

    gedit svnserve.conf
    and edit the file.

    un-comment following lines (remove # from the beginning of the line.)

    anon-access = read
    auth-access = write

    These lines tell about the read and write access to your SVN repository. 'anon-access = read' means anonymous users can read your SVN data.

    The possible values are 'read', 'write' and 'none'. The default value 'read' should be OK, as its a local repository. However, if your machine is in a network, you may want to change it to 'none' . ie;

    anon-access = none
    The second line 'auth-access = write' tells about the access rights of the authorized users. The default value of 'write' should be OK and it means authorized users can read/write back the data to the SVN repository.

    Below are some possible configurations;

    • The default configuration

      # anonymous users can only read the repository
      anon-access = read

      # authenticated users can both read and write
      auth-access = write

    • Restricted configuration

      # anonymous users aren't allowed
      anon-access = none

      # authenticated users can both read and write
      auth-access = write

  4. Configure the Authorization.

    un-comment following lines from the 'svnserve.conf' file opened in previous step.

    password-db = passwd
    This tells the SVN to read the user name and password from the file named 'passwd'.

  5. Setup the username and password.

    Open the file name 'passwd' present inside 'conf' directory of your SVN repository directory.

    Now un-comment the following lines.

    harry = harryssecret
    sally = sallyssecret

    This line tells the authorized user's name ans password. You can also add your username and password to this list. like

    raghu = mypassword
    or use existing username and password such as 'sally' and 'billy', oops.. 'harry'.

  6. Start the daemon process.

    Now enter following command to start the SVN daemon process.

    svnserve -d --root ~/my_svn_repo/
that's it. you can now checkout your own local SVN repository like any other SVN repository. Just use following URL to access your local SVN repository.

svn://localhost
example:

svn co svn://localhost my_svn_works
Creating SVN directory structure:(optional)

Like the SVN's general convention, I recommend you to create 3 different directories. They are trunk, tags and branches.

use following command to create them

svn mkdir branches tags trunk
now commit them to SVN.

svn commit
Making your SVN daemon process to start automatically with system.

The steps given above will start the daemon process, however if you restart your system, again you need to manually start the daemon process. Otherwise you can add a script to start the daemon process automatically with your system.

For this, You need to add a script to your /etc/init.d/

use following command to do it

echo "svnserve -d --root /home/raghunayak/my_svn_repo/" >> run_svnd && chmod +x run_svnd && sudo mv run_svnd /etc/init.d && sudo update-rc.d run_svnd defaults
In this command replace '/home/raghunayak/my_svn_repo' with with your SVN repository path.

To remove this startup script enter following command.

sudo update-rc.d -f run_svnd remove && sudo rm /etc/init.d/run_svnd
If you like this article, please leave a comment.. :)

New Category - Tech Recipe

I have just created a new post category named Tech Recipes. From today on wards I would be posting some new articles under this category.

In this category I would be asking some technical questions to you people, with the answer. The questions are most likely to be programming language related, with some exceptions. I hope these questionnaire would be very useful to the people, who are preparing for interviews or just want to improve their hold in programming languages.

So, Keep watching this space for more on this..



Technorati :

Del.icio.us : ,

Zooomr : ,

Flickr : ,

Wednesday, April 15, 2009

New License

I have changed the license used for sample codes. Most of the new sample codes are now released under more permissive MIT license, rather than copyleft GNU license.

I hope this change would help many people.

- Raghu Nayak

Update:
I have again changed the code license. I have re-licensed all my programs/source code under GNU General Public License version 3 or above (at your option).

Reasons or motivations behind this change:

  1. Freedoms of the user:
    I actually spend a lot of effort while coding or programming, and I really want my effort to be useful to someone! At the same time, I really don't want someone to take my code and convert it into a proprietary trap, thereby killing all user freedoms. I really want to protect the basic rights or the freedoms of the user, and this can be ensured only with GNU GPL.
  2. The recent acquisition of SUN Microsystem by Oracle had a strong influence on my decision. I really Thank GOD that, MySQL code is available under GNU GPL. So, even if Oracle kills it, somebody will fork it.
  3. This article, which I saw in GNU website.
So, I am sorry to all those who wanted to integrate use my code with their proprietary code. I am sorry, but this action was necessary to protect the basic freedom, on which I have strong belief.

- Raghu Nayak

Monday, April 13, 2009

CMake: Detecting Platform/Operating Systems, Compiler Information

I was searching for this information from last three days. Finally I found the CMake syntax to write the platform specific code inside CMakeLists.txt.

Detecting the Operating System:

CMake actually defines several variables to identify the platform information. These variables will be assigned with the values based on the platform, operating system etc.

For example, In CMake version 2.6 following Variables are present to identify the Operating System Type.

UNIX
     is TRUE on all UNIX-like OS's, including Apple OS X and CygWin
WIN32
     is TRUE on Windows, including CygWin
APPLE
     is TRUE on Apple systems. Note: Having this variable value set to TRUE does not necessarily mean that Operating System is Mac OS X. It only means that in the C/C++ header file __APPLE__ Macro is defined. Use the alternate method of detecting Operating System type, mentioned below instead.

For GNU/Linux: There is NO Variable for GNU/Linux. ie; IF(LINUX) does NOT work. Use the alternative method mentioned below instead.

Alternative method to detect to Operating System:

CMake version 2.6 defines 2 different variables, which can be used to detect the Operating System preciously. They are,

CMAKE_SYSTEM

     the complete system name, e.g. "Linux-2.4.22", "FreeBSD-5.4-RELEASE" or "Windows 5.1"
CMAKE_SYSTEM_NAME
     the short system name, e.g. "Linux", "FreeBSD" or "Windows"

These variables can be used to detect the Operating System.

Example:

IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# Mac OS X specific code
     SET(OperatingSystem "Mac OS X")
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")


for detecting Mac OS X

and for Linux

IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
# Linux specific code
     SET(OperatingSystem "Linux")
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")


Detecting the compiler:

Following variables can be used to detect the compilers.

MINGW
     is TRUE when using the MinGW compiler in Windows
MSYS
     is TRUE when using the MSYS developer environment in Windows
BORLAND
     is TRUE on Windows when using a Borland compiler
WATCOM
     is TRUE on Windows when using the Open Watcom compiler
MSVC, MSVC_IDE, MSVC60, MSVC70, MSVC71, MSVC80, CMAKE_COMPILER_2005, MSVC90
     Microsoft compiler
CMAKE_COMPILER_IS_GNUCC
     is TRUE if the compiler is a variant of gcc
CMAKE_COMPILER_IS_GNUCXX
     is TRUE if the compiler is a variant of g++
CYGWIN
     is TRUE on Windows when using the CygWin version of cmake

Detecting the System Processor:

Following variable can be used to detect the processor family.

CMAKE_SYSTEM_PROCESSOR
     the processor name (e.g. "Intel(R) Pentium(R) M processor 2.00GHz")

Example usage:

IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
     # Mac OS X specific code
     SET(OperatingSystem "Mac OS X")

     IF(${CMAKE_SYSTEM_PROCESSOR } MATCHES "Intel")
         # Intel Mac OS X specific code
         SET(Processor "Intel")
     ENDIF(${CMAKE_SYSTEM_PROCESSOR } MATCHES "Intel")

ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")


Links: