Page 1 of 2 12 LastLast
Results 1 to 20 of 22

Thread: how to link library in Qt( like gcc -l command)

  1. #1
    Join Date
    Jun 2010
    Posts
    21
    Thanks
    7
    Qt products
    Qt4

    Question how to link library in Qt( like gcc -l command)

    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.

  2. #2
    Join Date
    Jun 2010
    Posts
    21
    Thanks
    7
    Qt products
    Qt4

    Red face Re: how to link library in Qt( like gcc -l command)

    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

  3. #3
    Join Date
    Jun 2010
    Posts
    21
    Thanks
    7
    Qt products
    Qt4

    Default Re: how to link library in Qt( like gcc -l command)

    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?

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to link library in Qt( like gcc -l command)

    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 ?

  5. The following user says thank you to aamer4yu for this useful post:

    dzh1121 (10th June 2010)

  6. #5
    Join Date
    Jun 2010
    Location
    Salatiga, Indonesia
    Posts
    160
    Thanks
    11
    Thanked 32 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    1

    Default Re: how to link library in Qt( like gcc -l command)

    you can read some information about XI2 in this site.

  7. The following user says thank you to saa7_go for this useful post:

    dzh1121 (10th June 2010)

  8. #6
    Join Date
    Jun 2010
    Posts
    21
    Thanks
    7
    Qt products
    Qt4

    Default Re: how to link library in Qt( like gcc -l command)

    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.
    Last edited by dzh1121; 10th June 2010 at 06:41. Reason: some typo

  9. #7
    Join Date
    Jun 2010
    Posts
    21
    Thanks
    7
    Qt products
    Qt4

    Default Re: how to link library in Qt( like gcc -l command)

    Quote Originally Posted by aamer4yu View Post
    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.

  10. #8
    Join Date
    Jun 2010
    Posts
    21
    Thanks
    7
    Qt products
    Qt4

    Default Re: how to link library in Qt( like gcc -l command)

    Quote Originally Posted by aamer4yu View Post
    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

  11. #9
    Join Date
    Jun 2010
    Location
    Salatiga, Indonesia
    Posts
    160
    Thanks
    11
    Thanked 32 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    1

    Default Re: how to link library in Qt( like gcc -l command)

    how about adding this to your .pro:

    Qt Code:
    1. CONFIG += link_pkgconfig
    2. PKGCONFIG += xi
    To copy to clipboard, switch view to plain text mode 

    and maybe you need to read this and this.

  12. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how to link library in Qt( like gcc -l command)

    Add the following into the .pro file:
    qmake Code:
    1. LIBS += -lXi
    To copy to clipboard, switch view to plain text mode 
    .. and run qmake and make.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. The following user says thank you to wysota for this useful post:

    dzh1121 (10th June 2010)

  14. #11
    Join Date
    Jun 2010
    Posts
    21
    Thanks
    7
    Qt products
    Qt4

    Default Re: how to link library in Qt( like gcc -l command)

    Quote Originally Posted by wysota View Post
    Add the following into the .pro file:
    qmake Code:
    1. LIBS += -lXi
    To copy to clipboard, switch view to plain text mode 
    .. and run qmake and make.
    Thanks. what I've add is :
    Qt Code:
    1. LIBS += -lXi
    2. # added to make sure that -lXi is included(including link file and its path)
    3. LIBS += /usr/lib/libXi.so
    To copy to clipboard, switch view to plain text mode 

    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.

  15. #12
    Join Date
    Jun 2010
    Posts
    21
    Thanks
    7
    Qt products
    Qt4

    Default Re: how to link library in Qt( like gcc -l command)

    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)
    Any suggestioin?

    Thanks

  16. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how to link library in Qt( like gcc -l command)

    Quote Originally Posted by dzh1121 View Post
    Thanks. what I've add is :
    Qt Code:
    1. LIBS += -lXi
    2. # added to make sure that -lXi is included(including link file and its path)
    3. LIBS += /usr/lib/libXi.so
    To copy to clipboard, switch view to plain text mode 
    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?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  17. #14
    Join Date
    Jun 2010
    Posts
    21
    Thanks
    7
    Qt products
    Qt4

    Default Re: how to link library in Qt( like gcc -l command)

    Well, according to the definition of X11Event,
    I suppose that the parameter XEvent should be the same with the XEvent mentioned in the part4.c file.
    But seems that it is not.
    (but there is no reason,)
    Last edited by dzh1121; 10th June 2010 at 22:33. Reason: spelling corrections

  18. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how to link library in Qt( like gcc -l command)

    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?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  19. #16
    Join Date
    Jun 2010
    Posts
    21
    Thanks
    7
    Qt products
    Qt4

    Default Re: how to link library in Qt( like gcc -l command)

    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.
    Qt Code:
    1. bool MainWindow::x11Event(XEvent * e)
    2. {
    3. XEvent ev = *e;
    4. XGenericEventCookie *cookie = &ev.xcookie; //&e->xcookie;
    5. if(cookie->type != GenericEvent || cookie->extension != xi_opcode || !XGetEventData(dpy, cookie) ){
    6. printf("No GenericEvent Type is found in X11Event, return ******************* \n");
    7. return false;
    8. }
    9. printf("EVENT TYPE %d \n", cookie->evtype);
    10. switch(cookie->evtype){
    11. case XI_RawMotion:
    12. print_rawmotion((XIRawEvent *)cookie->data);
    13. break;
    14. case XI_Enter:
    15. case XI_Leave:
    16. print_enterleaveevent((XIEnterEvent *)cookie->data);
    17. break;
    18. default:
    19. print_deviceEvent((XIDeviceEvent *)cookie->data);
    20. break;
    21. }
    22. return false;
    23. }
    To copy to clipboard, switch view to plain text mode 

    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

  20. #17
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how to link library in Qt( like gcc -l command)

    Quote Originally Posted by dzh1121 View Post
    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?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  21. #18
    Join Date
    Jun 2010
    Posts
    21
    Thanks
    7
    Qt products
    Qt4

    Default Re: how to link library in Qt( like gcc -l command)

    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)]

  22. #19
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how to link library in Qt( like gcc -l command)

    Quote Originally Posted by dzh1121 View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  23. The following user says thank you to wysota for this useful post:

    dzh1121 (11th June 2010)

  24. #20
    Join Date
    Jun 2010
    Posts
    21
    Thanks
    7
    Qt products
    Qt4

    Default Re: how to link library in Qt( like gcc -l command)

    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).

Similar Threads

  1. Is it possible to link the qt library files into exe?
    By hashb in forum Installation and Deployment
    Replies: 2
    Last Post: 7th January 2010, 14:41
  2. How to use a Dynamic Link Library with QT / C++.
    By nivaldonicolau in forum Newbie
    Replies: 5
    Last Post: 29th April 2009, 14:05
  3. How to link library?
    By Macok in forum Qt Tools
    Replies: 1
    Last Post: 31st March 2009, 16:47
  4. Link against library on Mac OS
    By janus in forum Installation and Deployment
    Replies: 2
    Last Post: 22nd March 2009, 11:10
  5. Link *.so library
    By allstar in forum Qt Programming
    Replies: 1
    Last Post: 8th July 2007, 15:27

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.