qt-interest@trolltech.com
[Top] [All Lists]

Trying to create plugins

Subject: Trying to create plugins
From: Sumit Nagpal
Date: Mon, 25 Oct 2004 13:35:47 -0700
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);
}

Now my problem is that when I create a new class in library, the
application crashes while showing the mainwindow with following stack trace.
But if the instatiation in the library is of a standard Qt widget(here
QTextBrowser), it works. Please suggest.


#0  0x403b348f in QObject::inherits () from /QT/lib/libqt-mt.so.3
#1  0x403b3a3a in objSearch () from /QT/lib/libqt-mt.so.3
#2  0x403b3d3d in QObject::queryList () from /QT/lib/libqt-mt.so.3
#3  0x404bae2d in QMainWindow::setUpLayout () from /QT/lib/libqt-mt.so.3
#4  0x404bbd09 in QMainWindow::triggerLayout () from /QT/lib/libqt-mt.so.3
#5  0x404c225f in QMenuBar::show () from /QT/lib/libqt-mt.so.3
#6  0x403f300f in QWidget::showChildren () from /QT/lib/libqt-mt.so.3
#7  0x403f29d0 in QWidget::show () from /QT/lib/libqt-mt.so.3
#8  0x404bb38f in QMainWindow::show () from /QT/lib/libqt-mt.so.3


Regards
Sumit Nagpal

--
List archive and information: http://lists.trolltech.com/qt-interest/

<Prev in Thread] Current Thread [Next in Thread>