|
|
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);
> }
>
> 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/
--
Erik Kaffehr erik.kaffehr@xxxxxxxxxx alt. ekr@xxxxxx
Mariebergsvägen 53 +46 155 219338 (home)
S-611 66 Nyköping +46 155 263515 (office)
Sweden -- Message sent using 100% recycled electrons --
--
List archive and information: http://lists.trolltech.com/qt-interest/
|
|