Saturday, June 20, 2015

Circular Fragment Shader with Qt 5

Circular guage in qt can be attained by GLSL sharers. Include this piece of code for your Image source.

ShaderEffect{
                property variant  source: ..
                property real value: ..
                property real thicknessvalue: ..
                property real radiusvalue: ..
                ...

                fragmentShader: "
                                uniform sampler2D source;
                                varying highp vec2 qt_TexCoord0;
                                uniform lowp float qt_Opacity;
                                uniform highp float value;
                                uniform highp float radiusvalue;
                                uniform highp float thicknessvalue;
                                const float kInvPi = 1.0 / 3.141592;
                                void main()
                                {
                                    float bluriness = 1.0;
                                    float radius = radiusvalue; //0.01 to 2.00 (0.90)
                                    float thickness = thicknessvalue; // 0.001 to 1.00
                                    float len = value;  // 0.001 to 0.760;
                                    float offset =  0.37; // Start of Arc
                                    vec2 uv = vec2(qt_TexCoord0.y,  qt_TexCoord0.x);
                                    uv = 2.0 * uv - 1.0;
                                    uv.x *= 1.0;
                                    float d = length( uv );
                                    float angle = atan( uv.x, uv. y ) * kInvPi * 0.5;
                                    angle = fract( angle - offset );
                                    float w = bluriness * fwidth( d );
                                    float circle = smoothstep( radius + w, radius - w, d );
                                    float inner = radius - thickness;
                                    circle -= smoothstep( inner + w, inner - w, d );
                                    float segment = smoothstep( len + 0.002, len, angle );
                                    segment *= smoothstep( 0.0, 0.002, angle );
                                    circle *= mix( segment, 1.0, step( 1.0, len ) );
                                    gl_FragColor = qt_Opacity * texture2D(source, uv) * circle;
                                }"
            }




Sunday, June 14, 2015

Install Ubuntu 14.04 in USB (PWE - Portable Work Environment)

Do you want to create a portable work environment in your pocket? If so install Linux distribution in a portable USB.


For that what you need

1) Ubuntu 14.xx or Windows 8.x
2) USB (formatted with FAT or NTFS)
3) Virtual Box installed
4) Iso image for the Ubuntu xx.xx or any Linux distributions

Here it is achieved by using Ubuntu 14.04 and virtual machine with the same.

Install Virtual Machine:

First you need to install a virtual box 

$ sudo apt-get install virtual box        

After installing and set up the virtual machine, choose the Ubuntu 14.04 iso image which is already downloaded from Ubuntu official site.

Create a new Virtual Machine  load storage for its in settings with the Ubuntu 14.04 iso.

Settings > Storage > Controller:IDE > (Attributes>CD/DVD Drive with ISO).

Do start the VM for Ubuntu 14.04 & Choose "Try Ubuntu".




Note: Some times you may not be able to access the usb stick to be available in your virtual machine. To get access for that install dkms.

$ sudo apt-get install dkms              
$ sudo apt-get install gnome-system-tools

Open "Users and Groups" > "Manage groups" > vboxusers > "Properties" > add to main user or check for the user.


Once you have able to access USB from your virtual machine continue installing your Ubuntu 14.04 on to flash drive.





(Avoid connection to internet or else the entire process will have un-stability on installation and will be longer)


To configure and install in flash drive choose the option "something else" .


Choose /dev/sdb. Choose the usb drive for boot loader installation. Also do the partition on /dev/sdb (fat32)




Don't forget to choose "Ext4journaling file system".

 

 Also don't forget to choose mount point as root '/'.





This will continue to usual Linux installation.  You can boot the system and press "F12" (may vary) to choose the usb device to boot. 

Tuesday, April 3, 2012

Attempt to load Oracle client libraries threw BadImageFormatException. This problem will occur when running in 64 bit mode with the 32 bit Oracle client components installed.

        
         C# connection with Oracle: Every one encounter this issue while you tried to get a connection with oracle using .Net Frame work. You Might have Installed a lot of dependencies, 64 bit, 32 bit packages of both oracle client and .Net frame work, IIS resets etc etc.
When i got stuck with these below errors 


*"The type or namespace name 'OracleClient' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)"
*" Attempt to load Oracle client libraries threw BadImageFormatException.  This problem will occur when running in 64 bit mode with the 32 bit Oracle client components installed."


         I had done google a lot but no use. Every one are busy with installing the 64 and 32 bit packages. At last Verified its cause & Solution.


         I'm explaining it with specifications: 64 bit OS windows 7, 64 bit .Net Framework packages, 64 bit Oracle client Installation packages. With Reference to http://www.codeproject.com/Articles/18692/Instant-Oracle-Using-C . Then you have an Idea about what you are going to achieve. In the above link it says about the c# programming to code and connection, but I faced issue mainly in those two errors. So create a project as like in the above link and proceed to below.


        In the above link says "Be sure to include a reference to System.Data.OracleClient.dll, and place the following at the top of your code along with all the otherusing statements:" from where you start error with.


Solution:


1) You need to include "System.Data.OracleClient.dll" from "C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Data.OracleClient.dll" (Where ever you have installed your .NET framework). By  'Add Reference-> Browse Tab '. But in .NET tab you can't able to find "System.Data.OracleClient.dll".


2) You will get Error when you build as
"The type or namespace name 'OracleClient' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)"
So you need to change Properties->Application->Target FrameWork
as ".NET framework 4" instead of ".NET framework 4 Client".  Then you can see on 'Add Reference' windows in .NET Tab 'System.Data.OracleClient.dll'


3) Then You can build with out errors and run the program, But (a big 'BUT') You will encounter a exception As
" Attempt to load Oracle client libraries threw BadImageFormatException.  This problem will occur when running in 64 bit mode with the 32 bit Oracle client components installed."
Then you need to stop running and change Properties->Build->Platform Target to "Any CPU" instead of x86 or x64.
[To make sure add a reference path "C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Data.OracleClient.dll" (Where ever you have installed your .NET framework).  ]


Everything will work fine.
Cheers!

Thursday, March 29, 2012

Shape QPushButton in your own style Qt

                           Have you ever tried to create your own QPushButton shaped as you like? For example, Have you tried to create a 'L' shaped button or like a 'Enter' shaped button in your keyboad so visualize your software with a unique style? WPF in windows provides a lot of flexibility but it is having its own draw backs. Here Qt is providing flexibility of shaping button as you wish. Masking the shape of a image file, will help you to attain the button as you wish. Lets see the basics how we can do it.


class QMPButton : public QPushButton
{
  Q_OBJECT
  QSize imagesize;
public:
  explicit QMPButton(const QString &_shape,QObject *parent = 0);
signals:
public slots:
};

Here QMPButton is inherited from QPushButton, So We can get properties of QPushButton where ever you are using Object of QMPButton. QMPButton::_shape is the file name of image which we need the shape to be masked with.
 
QMPButton::QMPButton(const QString &_shape,QObject *parent) :  

QPushButton((QPushButton*)parent)

{

  QPixmap pixmap(_shape);

  imagesize = pixmap.size();

  this->setFixedSize(imagesize);

  this->setMask(pixmap.mask());

}

This Initialize and shape the button and fix it where ever you want.
Usage:


QMPButton *mbtton = new QMPButton(ui->lineEdit->text(), NULL);
  mbtton->setText("Ok");

  ui->gridLayout->addWidget(mbtton);


You can customize more by introducing style sheets and images for mouse hover, clicks etc. If you have images according to that shape will suite it more and you can now make unique style for your applications.
As like :

mbtton->setStyleSheet(QString:: 
fromUtf8("QPushButton{border-image: url(:res/pc-enter.png);}\n"
"QPushButton:hover{border-image: url(:res/pc-enter1.png);}\n"
"QPushButton:pressed{border-image: url(:res/pc-enter2.png);}"));

The Point am projecting you is that, button will be active only on the regions of the image not as a whole rectangle!

Output tested in X11 and also in Wayland:



Queries are welcome !

Wednesday, March 28, 2012

Base Thread Class available for your Customization


          I have wandered through many sites to implement thread class, which can be used as generic thread class for specific reuse and user specified thread functions. But I failed to find a class which provide the flexibility (there are many 3rd party thread libraries but implementation is wired and little complicated to use ). But QThread in QT4 framework is more easy and reliable to use. So here Am explaining how to Implement a thread class like QThread. I didn't meant QThread was written in the manner described below but this class can be used similar to a QThread class.
You are familiar with pthread_create(), pthread_join(), pthread_exit() etc Check it here . Normally you need to pass the thread Id, thread attributes, function pointer and arguments as void pointer in to  POSIX thread create function . Am Using Basic thread as POSIX thread itself, for create join etc etc.

class mPthread
{
public:
    mPthread(); // Plain constructor but you can provide arguments if necessary
    pthread_t threadId; //Common Pthread ID for single instance will help you to save ur face.
    pthread_attr_t threadAttr; // if needed
    virtual void run(); // this is a base class means it can be inherited and run() can be redefined.
    void start(); //key function for the thread call.
private:
    static void *mThreadFunction(void *arg); //this is the function pointer passing in to pthread_create().
};

/*this function can be re-implemented in its child class */

void mPthread::run()
{
    for(int i=0; i<10;i++)
    {
        cout<<": In Base Class :"<<endl;
        sleep(1);
    }
}
/*this function will start the thread from the user call.*/
void mPthread::start()
{
    pthread_attr_t      attr;
    pthread_attr_init(&attr);
    int ret = pthread_create(&threadId,&attr,mThreadFunction,this);
    cout<<"ret thread:"<<ret<<endl;
}
/*this is the pthread function pointer*/
void *mPthread::mThreadFunction(void *arg)
{
    m_this = arg;
    mPthread* thisObj = (mPthread*)arg;
    thisObj->is_running = true;
    thisObj->run();
    thisObj->is_running = false;
    return NULL;
}

The base class having a start function which will help you to start the thread. If you want to use this class you just need to simply inherit it in your own class to handle the thread. sample implementation is given below.

class threads : public mPthread
{
public:
    threads();
    void run();//this is the run() function with the provision to be redefined. :)
};
void threads::run()
{
    for(int i=0; i<10;i++)
    {
        cout<<":User Run:"<<endl;
        sleep(1);
    }
}
int main()
{
 threads *th = new threads();
 th->start(); // this start will help you to start the thread. out put will be your run function.
}
output:
:User Run:
:User Run:
:User Run:
:User Run:
:User Run:
:User Run:
:User Run:
:User Run:
:User Run:
:User Run:

If run function is not implimented in inherited class, then output will be .
: In Base Class :
: In Base Class :
: In Base Class :
: In Base Class :
: In Base Class :
: In Base Class :
: In Base Class :
: In Base Class :
: In Base Class :
: In Base Class :


Extra features like Thread detach , exit etc can also implement in the base class, be careful in using the common class object thread_id for all the above purpose.
Feel free to ask here, for any more explanation.



Windows Package & deployment


Windows Package & deployment
It is just an out line how we can create a setup package using Microsoft visual studio 2008. I am just trying to create a MSI - a windows installing package for a particular executable. So from the beginning iam trying to explain with screen-shots.
I : Get your executable (eg: BuisnessPjt.exe) and open this in dependency walker (http://www.dependencywalker.com/). This will help you to trace out which all *.dll files are needed for the executable to work. Avoid System files from the list and copy all the third party dll files to a folder along with the executable. If the executable work just by double clicking on it, then you have got 99% dlls needed for the executable to work stand alone.



II : Now its the time to create a setup (Microsoft installation package- MSI  )
1) Microsoft visual studio 2008 Open>>File>>New Project . This will help you to create a MSI package. You can give your specified path & create Solution.

2) Under the MSI Solution You will get
* Application Folder: Here under this you need to add files needed for the packaging. Executable, dlls, Icons, Readme.txt etc like what ever you want to come under program files (programfiles/testapplication )folder.
* Users's Desktop : You can provide links in this folder to the installed program in programs file folder @ desktop.
* User's Program menu: You can provide links in this folder to the installed program in programs file folder @ Start>>Program menu.
 So add files to Application Folder.


2) Add all files including executables and dlls from the folder as like given in first picture. Create a link or short cut for the exe and drag and drop to User's Desktop and Users Program menu.

3) Created Short cut and dragged to Users Desktop.


4) You can Set Icon for the desktop Short cut. Set it from its property window at right side.

5)Build the solution.



*** After creation of Set Up package, its installation 
 



Any more Doubts or suggestions feel free to ask here. Adding pages or for your custom Installation interface, try for 3rd Party MSI packaging applications  eg: http://www.purepackaging.com/ but you can also Introduce DLLs embedded in its way of installation.










Thursday, April 28, 2011

Little Technical C, C++, QT

Qt (pronounced officially as cute, though more commonly as Q.T. ) is a cross-platform application framework that is widely used for developing application software with a graphical user interface (GUI) (in which cases Qt is referred to as a widget toolkit), and also used for developing non-GUI programs such as command-line tools and consoles for servers.

#include 
 
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QLabel label("Hello, world!");
    label.show();
    return app.exec();
}
#qmake -project
#qmake
#make/gmake/nmake - as needed by OS and compiler environment


You can free to share or ask OOPS here oops!!