\section{KGeneric\-Factory$<$ Product, Parent\-Type $>$ Class Template Reference}
\label{classKGenericFactory}\index{KGenericFactory@{KGenericFactory}}
This template provides a generic implementation of a {\bf KLib\-Factory}{\rm (p.\,\pageref{classKLibFactory})} , for use with shared library components.  


{\tt \#include $<$kgenericfactory.h$>$}

Inheritance diagram for KGeneric\-Factory$<$ Product, Parent\-Type $>$:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=118pt]{classKGenericFactory__inherit__graph}
\end{center}
\end{figure}
Collaboration diagram for KGeneric\-Factory$<$ Product, Parent\-Type $>$:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=118pt]{classKGenericFactory__coll__graph}
\end{center}
\end{figure}
\subsection*{Public Member Functions}
\begin{CompactItemize}
\item 
{\bf KGeneric\-Factory} (const char $\ast$instance\-Name=0)\label{classKGenericFactory_a0}

\item 
{\bf KGeneric\-Factory} (const {\bf KAbout\-Data} $\ast$data)
\end{CompactItemize}
\subsection*{Protected Member Functions}
\begin{CompactItemize}
\item 
virtual {\bf QObject} $\ast$ {\bf create\-Object} ({\bf QObject} $\ast${\bf parent}, const char $\ast${\bf name}, const char $\ast${\bf class\-Name}, const {\bf QString\-List} \&args)
\end{CompactItemize}


\subsection{Detailed Description}
\subsubsection*{template$<$class Product, class Parent\-Type = QObject$>$ class KGeneric\-Factory$<$ Product, Parent\-Type $>$}

This template provides a generic implementation of a {\bf KLib\-Factory}{\rm (p.\,\pageref{classKLibFactory})} , for use with shared library components. 

It implements the pure virtual create\-Object method of {\bf KLib\-Factory}{\rm (p.\,\pageref{classKLibFactory})} and instantiates objects of the specified class (template argument) when the class name argument of create\-Object matches a class name in the given hierarchy.

In case you are developing a KParts component, skip this file and go directly to {\bf KParts::Generic\-Factory} .

Note that the class specified as template argument needs to provide a certain constructor: \begin{itemize}
\item If the class is derived from {\bf QObject} then it needs to have a constructor like: {\tt My\-Class( {\bf QObject} $\ast$parent, const char $\ast$name, const {\bf QString\-List} \&args );} \item If the class is derived from {\bf QWidget} then it needs to have a constructor like: {\tt My\-Widget( {\bf QWidget} $\ast$parent, const char $\ast$name, const {\bf QString\-List} \&args);} \item If the class is derived from {\bf KParts::Part} then it needs to have a constructor like: {\tt My\-Part( {\bf QWidget} $\ast$parent\-Widget, const char $\ast$widget\-Name, {\bf QObject} $\ast$parent, const char $\ast$name, const {\bf QString\-List} \&args );} \end{itemize}
The args {\bf QString\-List} passed to the constructor is the args string list that the caller passed to KLib\-Factory's create method.

In addition upon instantiation this template provides a central {\bf KInstance}{\rm (p.\,\pageref{classKInstance})} object for your component, accessible through the static instance() method. The instance\-Name argument of the KGeneric\-Factory constructor is passed to the {\bf KInstance}{\rm (p.\,\pageref{classKInstance})} object.

The creation of the {\bf KInstance}{\rm (p.\,\pageref{classKInstance})} object can be customized by inheriting from this template class and re-implementing the virtual create\-Instance method. For example it could look like this: 

\footnotesize\begin{verbatim}     KInstance *MyFactory::createInstance()
     {
         return new KInstance( myAboutData );
     }
\end{verbatim}
\normalsize


Example of usage of the whole template: 

\footnotesize\begin{verbatim}     class MyPlugin : public KParts::Plugin
     {
         Q_ OBJECT
     public:
         MyPlugin( QObject *parent, const char *name,
                   const QStringList &args );
         ...
     };

     K_EXPORT_COMPONENT_FACTORY( libmyplugin, KGenericFactory&lt;MyPlugin&gt; )
\end{verbatim}
\normalsize
 



Definition at line 173 of file kgenericfactory.h.

\subsection{Constructor \& Destructor Documentation}
\index{KGenericFactory@{KGeneric\-Factory}!KGenericFactory@{KGenericFactory}}
\index{KGenericFactory@{KGenericFactory}!KGenericFactory@{KGeneric\-Factory}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}template$<$class Product, class Parent\-Type = QObject$>$ {\bf KGeneric\-Factory}$<$ Product, Parent\-Type $>$::{\bf KGeneric\-Factory} (const {\bf KAbout\-Data} $\ast$ {\em data})\hspace{0.3cm}{\tt  [inline]}}\label{classKGenericFactory_a1}


\begin{Desc}
\item[Since:]3.3 \end{Desc}




Definition at line 183 of file kgenericfactory.h.

\subsection{Member Function Documentation}
\index{KGenericFactory@{KGeneric\-Factory}!createObject@{createObject}}
\index{createObject@{createObject}!KGenericFactory@{KGeneric\-Factory}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}template$<$class Product, class Parent\-Type = QObject$>$ virtual {\bf QObject}$\ast$ {\bf KGeneric\-Factory}$<$ Product, Parent\-Type $>$::create\-Object ({\bf QObject} $\ast$ {\em parent}, const char $\ast$ {\em name}, const char $\ast$ {\em class\-Name}, const {\bf QString\-List} \& {\em args})\hspace{0.3cm}{\tt  [inline, protected, virtual]}}\label{classKGenericFactory_b0}


Creates a new object. 

The returned object has to be derived from the requested classname.

It is valid behavior to create different kinds of objects depending on the requested {\tt class\-Name}. For example a koffice library may usually return a pointer to Ko\-Document. But if asked for a \char`\"{}QWidget\char`\"{}, it could create a wrapper widget, that encapsulates the Koffice specific features.

This function is called by {\bf create()}{\rm (p.\,\pageref{classKLibFactory_a2})} \begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em parent}]the parent of the {\bf QObject}, 0 for no parent \item[{\em name}]the name of the {\bf QObject}, 0 for no name \item[{\em class\-Name}]the name of the class \item[{\em args}]a list of arguments \end{description}
\end{Desc}


Implements {\bf KLib\-Factory} {\rm (p.\,\pageref{classKLibFactory_b0})}.

Definition at line 189 of file kgenericfactory.h.

The documentation for this class was generated from the following file:\begin{CompactItemize}
\item 
kgenericfactory.h\end{CompactItemize}
