|
|
Hi,
I suspect the following problems in your code; both of
which I guess you would have given a thought to
1. Since you have Q_OBJECT macro; the moc output for
the champak class should also be compiled along
with
the plugin. Because Q_OBJECT declares many
functions; which if not implemented makes Champak
and incomplete class which cannot be initialized.
2. I would suggest using extern "C" { .. } for
declaring the prototype for getWidget() method.
Regards,
Prashanth
--- Sumit Nagpal <sumit@xxxxxxxxxxxxxxxxx> wrote:
> Thanks Erik! This really is a better way than the
> "dlopen" to add plugin.
>
> Actually I was able to get the pointer to my object
> using "dlopen" but
> my problem is a bit different.
>
> I want to create a widget, inside my main window,
> which is defined in
> my plugin library.
> When this widget is a standard QT widget, there is
> no problem, It is
> visible in the main window.
> But if I inherit a standard QT widget and then try
> to show it in main
> window it crashes.
> (please see the code in my mail below)
>
> The only reason I can think of is that Qt::show is
> unaware about the
> inheritence hierarchy of my inherited widget, hence
> it crashes while
> showing it.
>
> Any idea ?
>
> Thanks
> Sumit Nagpal
>
>
> Erik Kaffehr wrote:
>
> >Hi!
> >
> >I don't have time to elaborate on the code, but we
> have used this in a project
> >and it worked reasonably well.... Might give you
> some ideas.
> >
> >Regards
> >
> >Erik
> >
> >
> >int ct_read_plugins (QString plugin_directory)
> >{
> > FUN fun_addr;
> >
> > int counter = 0;
> >
> > QString class_name;
> > QString file_name;
> > QString fun_name;
> >
> > QLibrary *library;
> >
> > QFile file (plugin_directory + "/.plugins");
> >
> > if (!file.open (IO_ReadOnly))
> > {
> > std::cerr << "*** ERROR: Could not open list of
> plugins " << file.name()
> ><< std::e
> >ndl;
> > return -1;
> > }
> >
> > QTextStream stream (&file);
> >
> > while (!stream.eof())
> > {
> > /* get class name, file name and name of
> createfunction */
> > class_name = stream.readLine ();
> > file_name = plugin_directory + "/" +
> class_name;
> > fun_name = "create" + class_name;
> >
> > /* open plugin file */
> > library = new QLibrary (file_name);
> > library->load ();
> >
> > if (library->isLoaded () == false)
> > {
> > QMessageBox::information (0, "Read Plugins",
> "Could not open " +
> >file_name, QMes
> >sageBox::Yes);
> > std::cerr << "Error opening '" << file_name
> << "'" << std::endl;
> > continue;
> > }
> >
> > // QMessageBox::information (0, "Read
> Plugins", "Open " + file_name,
> >QMessageBo
> >x::Yes);
> > library->setAutoUnload (false);
> > /* get address of createfunction */
> > fun_addr = FUN (library->resolve (fun_name));
> >
> > if (fun_addr == NULL)
> > {
> > QMessageBox::information (0, "Read Plugins",
> "Could not find " +
> >fun_name, QMess
> >ageBox::Yes);
> > std::cerr << "Error finding symbol '" <<
> fun_name << "'" << std::endl;
> > continue;
> > }
> > else
> > {
> > /* add class to list of adapters */
> > CTFactory::getInstance()->addItem (
> > new CTObjectCreatorEntry (fun_addr),
> > class_name.ascii(),
> > CTBaseObj::tr(class_name).ascii());
> >
> > std::cout << "ct_read_plugins (): added
> plugin: " << class_name <<
> >std::endl;
> >
> > counter++;
> > }
> > }
> >
> > file.close ();
> >
> > return counter;
> >}
> >
> >
> >
> >Monday 25 October 2004 22.35 skrev Sumit Nagpal:
> >
> >
> >>Hi All,
> >>
> >>I am trying some plugin stuff in QT.
> >>I have an application which reads some libraries
> and tries to instatiate
> >>some widgets defined in the libraries.
> >>Each library has 'getWidget' function(Factory
> Method) which creates a
> >>widget inside the
> >>mainwindow like below.
> >>
> >>CODE in library------------>
> >>
> >>#include <qtextbrowser.h>
> >>
> >>class champak:public QTextBrowser
> >>{
> >> Q_OBJECT
> >> public:
> >> champak(QWidget *parent=0,const char
> *name=0);
> >>};
> >>
> >>
> >>champak *modSch;
> >>//QTextBrowser *modSch; <---This Works
> >>
> >>void *getWidget*(QWidget* parent)
> >>{
> >> modSch = new champak(parent);
> >> //modSch = new QTextBrowser(parent) <---This
> works
> >> cout<<"modSch = "<<modSch<<endl;
> >>}
> >>
> >>champak::champak(QWidget *parent,const char
> *name):QTextBrowser(parent,0)
> >>{
> >> //
> >>}
> >>
> >>
> >>CODE in main------------>
> >>
> >>void *handle = dlopen("lib.so",RTLD_NOW);
> >>if(!handle){
> >> cout<<"Cudnt open lib
> "<<endl<<dlerror()<<endl;
> >>}else{
> >> void (*sym)(QWidget*);
> >> typedef void (*myFunc)(QWidget*);
> >> sym = (myFunc)
> dlsym(handle,"getWidget__FP7QWidget"); //right now i
> >>am just hardcoding it
> >> char *dlerr = dlerror();
> >> if(dlerr){
> >> cout<<"Cudnt open sym
> "<<endl<<dlerr<<endl;
> >> }else{
> >> (sym)(*mainWindow*);
> >> }
> >> dlclose(handle);
> >>}
> >>
>
=== message truncated ===
__________________________________
Do you Yahoo!?
Yahoo! Mail Address AutoComplete - You start. We finish.
http://promotions.yahoo.com/new_mail
--
List archive and information: http://lists.trolltech.com/qt-interest/
|
|