Tuesday, September 7, 2010

Factory Design Pattern

The Factory Design Pattern is maybe the most used pattern in modern languages like Java and C#. Most probably if you are searching for factory design pattern on the internet most of the results are about Factory Method and Abstract Factory.

We use it when we want to:
  • creates objects without exposing the instantiation logic to the client.
  • refers to the newly created object through a common interface





class DBConnector : public QObject

{
Q_OBJECT
public:
DBConnector(QObject* parent=0);

~DBConnector();

virtual bool OpenConnection(QString aDatabaseName) = 0;

QSqlQuery GetData(QString aSqlQuery);

bool WriteData(QString aSqlQuery);

void commit();

void cleanUp();

protected:

QSqlDatabase* m_pDatabase;

QSqlQuery* m_pQuery;

signals:

void ConnectionErrorSignal(QString);

void QueryErrorSignal(QString);

};


class SqliteDBConnector : public DBConnector

{

public:

SqliteDBConnector();

bool OpenConnection(QString aDatabaseName);

};


bool DBManager::CreateDBConnectors()
{
DBConnector m_pMainDBConnector = new SqliteDBConnector();

return true;
}

Friday, February 22, 2008

How to change the application icon?

I dont mean the icon that appear in the title bar but i meam the icon 
that appear in the windows explorer.
first Open notepad.
2- Type: IDI_ICON1 ICON DISCARDABLE "icon.ico"
     Note: ”icon.ico is the name of the icon you want to use. ”
3- Save it as icon.rc
     Note: When saving, be sure that there is no .txt extention in the filename, it should be a .rc. You      can change the filename to whatever filename you want.
4-Open your project. The *.pro file.
5- Add this line : RC_FILE=icon.rc
     Note: “icon.rc is the name of the .rc you previously created”
6- Save.
7- Place your desired icon to the folder where your project (*.pro) was located.
8- Finally, build/rebuild your project.

Sunday, December 30, 2007

how to build Qt4.3.2 with msvc2005 ?

hi, i consumed approximately one month to build Qt source with msvc2005 and
integrate it with msvc2005. there is my experiment to do that, and it was succeed.

1- I extracted the Qt source in (c:\Qt\4.3.2)
2- I added the PATH to the system environment as follows
- right click on my computer -> properties -> advanced->Environment variables-> new
- variable name = PATH
- variable value = c:\Qt\4.3.2\bin
3- I configured Qt as follows
- start -> All programs->visual studio 2005->visual studio tools->visual studio 2005 command prompt
- C:\Program Files\Microsoft Visual Studio 8\VC> cd\
- c:\>cd qt
- c:\qt>cd 4.3.2
- write (configure –platform win32-msvc2005 –debug-and-release –fast –prefix c:\Qt\4.3.2) in the cmd window.
4- After configuring Qt then build it by typing nmake in the command prompt.
5- Then I execute Qt visual studio integration program.
6- Then in visual studio Tools->options->Qt->builds and click add write Qt version (e.g Qt-4.3.2) and the directory where Qt is installed( e.g c:\Qt\4.3.2).
7- Then I added QTDIR to the system and user environment as follows
- right click on my computer -> properties -> advanced->Environment variables-> new
variable name = QTDIR
variable value = c:\qt\4.3.2

8- Then in visual studio tools-> options->projects and solutions-> vc++ directories-> include files I added
$(QTDIR)\include
$(QTDIR)\include\Qt
$(QTDIR)\include\QtCore
$(QTDIR)\include\QtGui
$(QTDIR)\include\QtNetwork
$(QTDIR)\include\QtSvg
$(QTDIR)\include\QtXml
$(QTDIR)\include\Qt3Support
$(QTDIR)\include\ActiveQt
and in library files I added
$(QTDIR)\lib
and in source files i added
$(QTDIR)\src
9- Then I started to make a project just as follows
file -> new->project->Qt projects->Qt Applecation
10- Then I compiled it as follows
build->build solution
11- Then execute the exe

now it is working fine.