Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 5

Qt-interest Archive, April 2007
Writing for a Shared Library and loading into third party programs


Message 1 in thread

Hi,
	I use a statistical software called R (see http://www.r- 
project.org/). The software has the ability to load shared libraries  
(via dyn.load - see http://www.stat.psu.edu/~dhunter/R/html/base/html/ 
dynload.html).

	I have some code written using QT (see below), which I'm trying to  
load into R via dyn.load
	Howevr i get the following error
	" Error in dyn.load(x, as.logical(local), as.logical(now)):
		unable to load shared library "/home/sguha/l/l.so':
	/home/sguha/tmp/l/l.so : undefined symbol: _ZTV5myWid


	If i remove Q_OBJECT from the class defn, the dll loads properly,  
but on calling it i get "Object::connect: No such slot QObject::mn()"

	I would appreciate any pointers in this regard
	Saptarshi


	*****This is the code:(very bad stuff, just messing around)******
	#include <QApplication>
#include <QPushButton>
#include <QTimer>
#include <QObject>


class myWid: public QObject
{

public:
   myWid(){ v=0;}
public slots:
   int mn(void);
private:
   int v;
};

   int myWid::mn(void)
{
   printf("Hey");
   return(0);
}

int main(int argc, char *argv[])
{
   QApplication app(argc, argv);

   QPushButton hello("Hello world!");
   QTimer *t=new QTimer();
   myWid m;
   m.connect(t, SIGNAL(timeout()),SLOT(mn()));
   hello.resize(100, 30);
   t->start(0);
    hello.show();

    //return app.exec();
}


	****And how i compile it******

g++ -c -m64 -pipe -O2 -Wall -fPIC -W  -D_REENTRANT  -DQT_NO_DEBUG - 
DQT_GUI_LIB -DQT_CORE_LIB -D
QT_SHARED -I../../mine/mkspecs/linux-g++-64 -I. -I../../mine/include/ 
QtCore -I../../mine/includ
e/QtCore -I../../mine/include/QtGui -I../../mine/include/QtGui - 
I../../mine/include -I. -I. -I.
-o x.o x.cc
g++ -m64 -Wl,-rpath,/home/sguha/mine/lib -shared -o l.so x.o    -L/ 
home/sguha/mine/lib -L/usr/l
ocal/lib64 -lQtGui -L/home/sguha/tmp/qt-x11-opensource-src-4.2.2/lib - 
L/usr/X11R6/lib64 -lpng -
lSM -lICE -L/home/sguha/mine/lib -lXi -lXrender -lXrandr -lXfixes - 
lXcursor -lXinerama -lfreety
pe -lfontconfig -lXext -lX11 -lQtCore -lz -lm -lglib-2.0 -ldl -lpthread


Saptarshi Guha | sapsi@xxxxxxxxx | http://www.stat.purdue.edu/~sguha



Message 2 in thread

Saptarshi Guha schrieb:
> Hi,
> ...
> If i remove Q_OBJECT from the class defn, the dll loads properly, but on
> calling it i get "Object::connect: No such slot QObject::mn()"

Just to make sure: did you also compile the moc_yourClass.cpp (the moc
generated file) into your plugin?

Cheers, Oliver

--
 [ signature omitted ] 

Message 3 in thread

Hi,
	Thanks for responding.
When i initially ran qmake -project and then qmake (to generate the  
Makefile) **no** moc file was created.
Nor did i write one.  There is a l.pro file.
	I've been using PyQT and have not ventured into this area of QT.  
With the moc file absent am i missing something?
	
	Regards
	Saptarsho

	
Saptarshi Guha | sapsi@xxxxxxxxx | http://www.stat.purdue.edu/~sguha


On Apr 20, 2007, at 1:00 PM, Till Oliver Knoll wrote:

> Saptarshi Guha schrieb:
>> Hi,
>> ...
>> If i remove Q_OBJECT from the class defn, the dll loads properly,  
>> but on
>> calling it i get "Object::connect: No such slot QObject::mn()"
>
> Just to make sure: did you also compile the moc_yourClass.cpp (the moc
> generated file) into your plugin?
>
> Cheers, Oliver
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx  
> with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/

--
 [ signature omitted ] 

Message 4 in thread

Saptarshi Guha schrieb:
> Hi,
> ..
> With the moc file absent am i missing something?

Yes! The Q_OBJECT macro expands into code which calls the auto-generated
code (e.g. the Qt object meta-information and the actual signal/slot
mechanism). It's probably exactly those symbols which you are missing
when trying to dynamically load your plugin.

When you have listed your *.h in a *.pro (HEADERS += YourClass.h) the
qmake tool should actually take care of the moc step and link the
generated moc_YourClass.cpp into the final *.so (or executable).

If you run your own makefile make sure you run the moc compiler over
your *.h and compile/link the generated file into your *.so (and don't
forget to do so each time you change the *.h file!).

Cheers, Olvier

--
 [ signature omitted ] 

Message 5 in thread

Hi,
	I appreciate your help. I'll work on this.
	Thanks
	Saptarshi Guha


On Apr 20, 2007, at 1:11 PM, Till Oliver Knoll wrote:

> Saptarshi Guha schrieb:
>> Hi,
>> ..
>> With the moc file absent am i missing something?
>
> Yes! The Q_OBJECT macro expands into code which calls the auto- 
> generated
> code (e.g. the Qt object meta-information and the actual signal/slot
> mechanism). It's probably exactly those symbols which you are missing
> when trying to dynamically load your plugin.
>
> When you have listed your *.h in a *.pro (HEADERS += YourClass.h) the
> qmake tool should actually take care of the moc step and link the
> generated moc_YourClass.cpp into the final *.so (or executable).
>
> If you run your own makefile make sure you run the moc compiler over
> your *.h and compile/link the generated file into your *.so (and don't
> forget to do so each time you change the *.h file!).
>
> Cheers, Olvier
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx  
> with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/

--
 [ signature omitted ] 

Message 6 in thread

Hi,
	Olvier: Thanks! I managed to get it working and no errors (on both  
OS X and Linux - the delights of cross platform and Qt), loading  
smoothly into R.

	This brings me to my main problem right now.
	***What I want:
	I intend to write a shared library for R, which when called will  
accept some plotting commands. These commands (i.e draw_circle) will  
be drawn in a window.
	**However**, when i ran a simple program, the app.exec_() takes the  
control away from R, instead however, I wish to the window to be open  
but R itself should still be able to respond to events.

	e.g dyn.load(mydll)
	< after which, the input in R is waiting for me close the window  
which my shared library created).

	R is not aware of QT. So how can i process events for the window i  
created, but return control to the calling program.	

	I've seen similar situations on the web but they didn't seem to  
solve it.

	Everyones advice appreciated.
	Rgds
	Saptarshi

Saptarshi Guha | sapsi@xxxxxxxxx | http://www.stat.purdue.edu/~sguha

On Apr 20, 2007, at 1:11 PM, Till Oliver Knoll wrote:

> Saptarshi Guha schrieb:
>> Hi,
>> ..
>> With the moc file absent am i missing something?
>
> Yes! The Q_OBJECT macro expands into code which calls the auto- 
> generated
> code (e.g. the Qt object meta-information and the actual signal/slot
> mechanism). It's probably exactly those symbols which you are missing
> when trying to dynamically load your plugin.
>
> When you have listed your *.h in a *.pro (HEADERS += YourClass.h) the
> qmake tool should actually take care of the moc step and link the
> generated moc_YourClass.cpp into the final *.so (or executable).
>
> If you run your own makefile make sure you run the moc compiler over
> your *.h and compile/link the generated file into your *.so (and don't
> forget to do so each time you change the *.h file!).
>
> Cheers, Olvier
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx  
> with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/

--
 [ signature omitted ] 

Message 7 in thread

Hi,
I think you mean I have to run the moc? How do i go about it?
Thanks for your time.
I'm just running make.
Saptarshi Guha | sapsi@xxxxxxxxx | http://www.stat.purdue.edu/~sguha

On Apr 20, 2007, at 1:00 PM, Till Oliver Knoll wrote:

> Saptarshi Guha schrieb:
>> Hi,
>> ...
>> If i remove Q_OBJECT from the class defn, the dll loads properly,  
>> but on
>> calling it i get "Object::connect: No such slot QObject::mn()"
>
> Just to make sure: did you also compile the moc_yourClass.cpp (the moc
> generated file) into your plugin?
>
> Cheers, Oliver
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx  
> with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/

--
 [ signature omitted ]