PDA

View Full Version : how to link library in Qt( like gcc -l command)



dzh1121
10th June 2010, 05:34
Dear All,

I working on a small project, I've finished the logical part of the programming in X11 on Linux.

I've designed an interface by Qt.

But when compiling, seems that I cannot link my target library.

As this: in gcc, I can write as:
$gcc -o whiteBoard `pkg-config --cflags --libs xi` whiteBoard.c
( or simply $gcc -o whiteBoard -lXi whiteBoard.c)

But how to link this library ( Xi to be exact) in Qt????

I've googled it, but failed.
Any suggestion would be greatly welcomed.

dzh1121
10th June 2010, 06:07
BTW, i've tried to add the -lXi to the end of the LIBS.

as well as at the end of command line in #########Compile Part##########

But, seems that the program still gives me the XI Event, but I'm expecting the XI2 Event.
See /usr/include/X11/extensions folder for XI.h and XI2.h file.

Thanks

dzh1121
10th June 2010, 06:13
Further, I've tried to add the LIBS += xi but compiler error occurs. (this time, the -lXi is already added in the make file.)

saying that xi library can't be found.( nor with the Xi)

what's the reason?

aamer4yu
10th June 2010, 06:17
is your library in path ?
LIBS += xi.lib will tell to add a library,, where it can find it depends on the path.

Also did you re run qmake on the project ?

saa7_go
10th June 2010, 06:52
you can read some information about XI2 in this site (http://who-t.blogspot.com/2009/05/xi2-recipes-part-1.html).

dzh1121
10th June 2010, 07:28
Yes, I do.
I do read them carefully, and tried their code, and design my own code.
The thing is that, the same code do not generate same event, for example, for part4.c .
I've compile them, and run. by
$gcc -o part4 `pkg-config --cflags --libs xi` part4.c
$./part4

The program could return the XI2 Event( defined in file XI2.h)

But in Qt, I've tried to capture the xEvent in x11Event() function.
But after testing, the eventType would only be those defined in X.h, such as KeyRelease, ButtonRelease etc.) GenericEvent could never captured.

But in example code, part4.c would return them as GenericEvent, and thus we can further verify them as XI_KeyPress, ButtonRealse or others according to their evtype)

FYI, X.h and XI.h, and XI2.h are in the folder /usr/include/X11. (seems that you should install the dev and header package in Synapic manager by searching libX11)

Thanks again for you reply.

dzh1121
10th June 2010, 07:36
is your library in path ?
LIBS += xi.lib will tell to add a library,, where it can find it depends on the path.

Also did you re run qmake on the project ?

if I run qmake again, the make file would generate again. and the appended -lXi on LIBS line in make file would disappear.

And further, on the command line, gcc -lXi do not need the path, (and thus I think it may also not need the parth in makefile. also, I'm not 100% sure about whether it is the /usr/lib/libXi.so file)

Thanks again for your reply.

dzh1121
10th June 2010, 07:45
is your library in path ?
LIBS += xi.lib will tell to add a library,, where it can find it depends on the path.

Also did you re run qmake on the project ?

I've tried LIBS += /usr/lib/libXi.so, but gives same result.

I do appreciate your help.
Thanks

saa7_go
10th June 2010, 08:29
how about adding this to your .pro:



CONFIG += link_pkgconfig
PKGCONFIG += xi


and maybe you need to read this (http://doc.qt.nokia.com/4.6/qwidget.html#x11Event) and this (http://doc.qt.nokia.com/4.6/qapplication.html#x11EventFilter).

wysota
10th June 2010, 14:02
Add the following into the .pro file:
LIBS += -lXi
.. and run qmake and make.

dzh1121
10th June 2010, 21:09
Add the following into the .pro file:
LIBS += -lXi
.. and run qmake and make.
Thanks. what I've add is :

LIBS += -lXi
# added to make sure that -lXi is included(including link file and its path)
LIBS += /usr/lib/libXi.so

So, seems that can't receiving the GenericEvent may not because the lack of linking file.
But then what's reason? That's quite weird ?
(my professor says that probably because Qt filt some Event.
But I don't think that.
I'm trying to figure it out, but still no success. :confused:

dzh1121
10th June 2010, 21:34
Thanks.
On my system, I've tested, `pkg-config --cflags --libs xi` would give -lXi as its result.
So, for example,
$gcc -o part4 `pkg-config --cflags --libs xi` part4.c
has the same effect as
$gcc -o part4 -lXi part4.c

Further, x11EventFilter() is for the classes inherited from QApplication,
Since my program inheried from QMainWindow(which inherited from QWidget.), So, I only inplemented the x11Event(XEvent * e) function.

in this function, I first test the e->type, but none could be GenericEvent.
(just now, I've tried to copy the code in while() part, and paste them to X11Event(), but still no luck.(No Generic Event could be found) :confused:
Any suggestioin?

Thanks

wysota
10th June 2010, 21:43
Thanks. what I've add is :

LIBS += -lXi
# added to make sure that -lXi is included(including link file and its path)
LIBS += /usr/lib/libXi.so
The last line doesn't make sense, you only need the first one.


So, seems that can't receiving the GenericEvent may not because the lack of linking file.
But then what's reason? That's quite weird ?
(my professor says that probably because Qt filt some Event.
How are you trying to receive the event?

dzh1121
10th June 2010, 23:32
Well, according to the definition of X11Event (http://doc.qt.nokia.com/4.6/qwidget.html#x11Event),
I suppose that the parameter XEvent should be the same with the XEvent mentioned in the part4.c (http://people.freedesktop.org/~whot/xi2-recipes/) file.
But seems that it is not.
(but there is no reason,) :confused:

wysota
11th June 2010, 02:06
Can we see the relevant code of yours? Please also say what you need the native event for. One more thing - the docs say the events will only be delivered to the widget when it is native (meaning it's not an alien) - did you disable alien support for it?

dzh1121
11th June 2010, 20:40
Goal is to capture the XI2 event for multiple cursor( for different mouse/keyboard)
Here's some relevant code. (I've check the has_xi2 for my display, and set the event mask in the MainWindow's constructor.


bool MainWindow::x11Event(XEvent * e)
{
XEvent ev = *e;
XGenericEventCookie *cookie = &ev.xcookie; //&e->xcookie;
if(cookie->type != GenericEvent || cookie->extension != xi_opcode || !XGetEventData(dpy, cookie) ){
printf("No GenericEvent Type is found in X11Event, return ******************* \n");
return false;
}
printf("EVENT TYPE %d \n", cookie->evtype);
switch(cookie->evtype){
case XI_RawMotion:
print_rawmotion((XIRawEvent *)cookie->data);
break;
case XI_Enter:
case XI_Leave:
print_enterleaveevent((XIEnterEvent *)cookie->data);
break;
default:
print_deviceEvent((XIDeviceEvent *)cookie->data);
break;
}
return false;
}


If needed, I can send more code to your email.

BTW, what do you mean that the event is native. would you please show me the document you've seen?

Thanks

wysota
11th June 2010, 20:52
Goal is to capture the XI2 event for multiple cursor( for different mouse/keyboard)
Here's some relevant code. (I've check the has_xi2 for my display, and set the event mask in the MainWindow's constructor.
So what's the problem exactly? It seems Qt has nothing to do with your situation. For instance I don't think it supports more than one input focus at the same time.


BTW, what do you mean that the event is native. would you please show me the document you've seen?
By native event I mean an event generated by the native API (X11 in this case) and not Qt.

How do you intend to use the extra information provided by XInput2?

dzh1121
11th June 2010, 21:38
Thanks for your reply.
On Ubuntu 10.04, I've already have 2 cursor, each for one mouse.
My problem is that, I expect GenericEvent( in X.h file), so I can transfer them to XI2( in XI2.h file) defined event.
But now, all event type is the the ones defined in X.h, like KeyPress, ButtonRelease, but never GenericEvent.

in the simpliest command line program, I can get the XI2 event.
But for the program in Qt, only the X2 event could be received. (see my sample code of X11Event() )
but I've check XI2 ,and my Qt program tells me that
XI2 supported. Server provides version 2.0.

For everything related to event capture is the same.
So as the beginning, I thought it maybe the link file problem.(but now, it seems not.)

For your second question, all my event is native, from X11 Event, for sure. [just they are not the extention case(XI2)]

wysota
11th June 2010, 21:52
For your second question, all my event is native, from X11 Event, for sure. [just they are not the extention case(XI2)]
That's of course not true :) If that were the case, Qt wouldn't be working as everything in it is driven by Qt originating events. Only what goes to x11event() is a native event. I think your problem might be that Qt simply doesn't forward these kinds of events to the widget. I think you should be reimplementing QApplication::x11EventFilter() instead.

dzh1121
11th June 2010, 22:38
:D wow, really??
You know, I had thought that since X11Event is virtual, we do not need to reimplement them.
And QWidget::x11Event() would have all the event type.
Seems you are right.
I'll test it now.

BTW, should I inherit QApplication for my QMainWindow?(currently, it inherits from QWidget).

wysota
11th June 2010, 22:43
You know, I had thought that since X11Event is virtual, we do not need to reimplement them.
Hmm... when some method is virtual it usually means it is meant to be reimplemented...


And QWidget::x11Event() would have all the event type.
Only events that are meant for this particular widget will be forwarded to it. Of course unless the widget is alien, then it won't get any native events.


BTW, should I inherit QApplication for my QMainWindow?(currently, it inherits from QWidget).
I will not answer this question but instead send you back to the docs to compare QApplication and QWidget classes and think whether one can substitute the other as a super class of QMainWindow.

dzh1121
18th June 2010, 09:32
wysota,

Thanks for all your replies.

As I still did not figure how to receive the original Xlib event in Qt. ( It should be able to, but I just cann't work it out.)
As you said, x11EventFilter() maybe the reason.
Although I still did not make it.

Now, my current solution is using a C program to receive XEvent and send that event into a java client.( still stuck by a problem to find the WindowID of java GUI.)
But, anyway, thank again.

Thanks for all your effor, all your instruction and etc.

With regards.

Tiger