Tuesday, September 6, 2016

Dynamic memory allocator: new in C++

In c++ we will use new operator to allocate memory dynamically . In this post we will know how this process happens and what are the steps involved while using new. Basic syntax for new is
new [placemenet-params] typename;
This expression will allocate the memory available from the free store and returns the pointer to the object of type 'typename'. And in case of class, struct types it will allocate memory and intialise the object then retun the pointer to the object 'typename'.

Saturday, July 2, 2016

Object Slicing in C++ with example

What is Object Slicing? 
When an instance of derived class  is copied to base class object by value , part of members associated with derived object will be lost(sliced) . Here base class object discards the data related to the derived class because base class object don't have information about the derived members

When we copy derived obj by value to base obj,  the base class copy constructor /assignment operator will call (copy constructor will call at assigning object at the time of declaration (or) pass by value argument to function and assignment operator will call when assigning object after declarion), so base class don't have information about the derived members to copy.  This means the base copy/assignment will copy members related to base class only.

The following sample c++ code will explain the above description.

Wednesday, June 8, 2016

Some Useful My Sql Queries for beginners

My Sql is a popularly used Relational Database Management System.  Database is used store and retrieve data efficiently with the proven algorithms. Here i'm providing some sql commands which are useful for beginners in my sql queries.

Here information_schema is the default database comes with Mysql installation.

>To check the engine used for the table - mytable

Thursday, May 26, 2016

Maria DB Storage Engines and Alogorithms used for Indexing

Maria DB is a Open source database and is a replacement for My SQL data base after My Sql (Sun Micro Systems) has been acquired by Oracle.

Database can have multiple tables and each table will use one storage engine, and we can use different storage engines for different tables in the database.

In this article i'm discussing about the storage engines of Maria DB. There are many storage engines that supports Maria DB, and these are pluggable engines.

To see the available storage engines in maria db, execute the following query

MariaDB [(none)]> show storage engines;  (or)
MariaDB [(none)]> show engines;
And for all these storage differ from one another with the following properties..

Thursday, May 12, 2016

Qt C++ to Qml Communication using qmlRegisterUncreatableType()

In this article i will discuss about how to access the C++ class  enum types and attributes in qml file using Qt c++ qmlRegisterUncreatableType() template function.

qmlRegisterUncreatableType() will register the c++ class type (derived from QObject) as the non-instantiable type with QML type system. So we can not create object for the class in qml file, but we can use the properties ans enumerated types belongs to this class in qml file.

To access the enum values in qml , we have to make it available to meta-object system with the following macro, Otherwise we cannot access in qml file.

To Register the c++ type with qml type system
 qmlRegisterUncreatableType("ModuleName/uri", MajorVersion, MinorVersion, "QmlName", "message");

Here i'm providing the sample code to demonstrate the use of qmlRegisterUncreatableType() to access c++ class attributes and enum types.

Saturday, May 7, 2016

Bit Operations: Qt Example

In this post i'm going to show you some bit operations with &, |, <<, >>, ~ using Qt example. This example include operations like set a particular bit in the given number, clear bit, check bit is set or not and to check whether the number is even or odd.

Following demonstrates the psuedo code of the operations.

> To Set a bit in the given number : perform Betwise OR (|) operation with  1 left shift(<<) by index of the bit to set
     num = num | (1<<index);

>To clear a bit in the given number: perform Betwise AND (&) operation with the inverted(~) 1 left shift(<<) by index of the bit to clear
    num = num & ~(1<<index);

Tuesday, May 3, 2016

'Cannot find -lGL' error while building the Qt widget application in Linux OS?

Hi all,

Did any one get "Cannot find -lGL" error while building the Qt widget application in Ubuntu operating system? Qt installer provides compiler, debugger, make and other tools for the development. But when you want to develop Qt graphical based application it requires Open GL libraries.

Most of the Linux OS will not provide Open GL libraries as default. To continue building Qt graphical applications just install this libraries.

For Ubuntu use the following command

Friday, June 28, 2013

Anonymous Unions in C++

Unions in C++ are special type of classes. We can declare member functions and variables with in the union in c++ (all 'C' features of union remain same). 
But in the unions all the data members share the same memory location.

    Union members are public by default as like structures.

     Anonymous unions are the special type unions with the no name and so we can not create object for that union. All the member data in the anonymous unions share same memory location. We can directly access the these members without any dot operator with in the block where these unions declared.