Results 1 to 10 of 10

Thread: How do to add a library to my project?

  1. #1
    Join Date
    Aug 2009
    Location
    United States
    Posts
    45
    Thanks
    20
    Qt products
    Qt4
    Platforms
    Windows

    Default How do to add a library to my project?

    I need to use a serial port in my program and I found what looks like a really nifty library for Qt called "QExtSerialPort." I downloaded the latest version off sourceforge, built the project, and copied "qextserialportd.dll" over to my project directory. I've never used a DLL before, though, and I'm not sure how to proceed. How do I add it to my project so that I can use the classes inside it?

    Thanks for your help!

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How do to add a library to my project?

    There is no project settings required for using a DLL in your project.
    You have to load library and resolve its functions/symbols.
    For that, use QLibrary.

  3. The following user says thank you to yogeshgokul for this useful post:

    N3wb (29th September 2009)

  4. #3
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How do to add a library to my project?

    You can use the library QSerialDevice v 0.1.0 - it is going as static.

    But, if you want to use QextSerialPort and do not want to use the class QLibrary - you can connect a dynamic link library *. dll directly in the project file *. pro

  5. #4
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How do to add a library to my project?

    Do you have also *.lib (or lib*.a if you use MinGW) file with the same name as this *.dll file?
    If yes then you have to link to this .lib (.a) and then just put the .dll in your exec dir.
    To link against some library you have to do something like this in your .pro file:
    Qt Code:
    1. INCLUDEPATH += path/to/library/includes
    2. LIBS += -Lpath/to/lib/or/a/file -lnameofthelibrary
    To copy to clipboard, switch view to plain text mode 
    notice -L for the path to library dir and -l to the librtary itself.
    next thing is that your dll contains letter "d" at the end of the name (before .dll) and it usually means that it is compiled in debug mode, so use it in debug mode of your application, but try to compile also the release version to link to the release version of your application. then you can do something like this (in .pro file):
    Qt Code:
    1. CONFIG(debug, debug|release):LIBS += -lnamewithd
    2. CONFIG(release, debug|release):LIBS += -lonlyname
    To copy to clipboard, switch view to plain text mode 
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  6. The following user says thank you to faldzip for this useful post:

    N3wb (29th September 2009)

  7. #5
    Join Date
    Aug 2009
    Location
    United States
    Posts
    45
    Thanks
    20
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How do to add a library to my project?

    Thanks for all of your replies!

    I tried your method faldżip, but can't seem to get it to work. Would it be better/more proper to use the QLibrary method that yogeshgokul posted? Either way, it looks like it's going to take me some time to figure this out. I'm just wondering which method I should pursue?

  8. #6
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How do to add a library to my project?

    Simply connect the *. dll - not using QLibrary IMHO

  9. #7
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How do to add a library to my project?

    can you show us you *.pro file?
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  10. #8
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How do to add a library to my project?

    here : http://www.prog.org.ru/topic_8259_0.html

    PS: Google translator to help

  11. #9
    Join Date
    Aug 2009
    Location
    United States
    Posts
    45
    Thanks
    20
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How do to add a library to my project?

    Faldżip, thanks so much for helping. Here's my .pro file:
    Qt Code:
    1. SOURCES += main.cpp \
    2. mainwindow.cpp \
    3. baction.cpp \
    4. caction.cpp \
    5. arrowbutton.cpp
    6. HEADERS += main.h \
    7. mainwindow.h \
    8. baction.h \
    9. caction.h \
    10. arrowbutton.h
    11. OTHER_FILES += readme.txt
    12.  
    13. INCLUDEPATH += C:\Users\Nathan\Desktop\qextserialport
    14. LIBS += -LC:\Users\Nathan\Desktop\qextserialport -lqextserialport
    15.  
    16. CONFIG(debug, debug|release):LIBS += -lqextserialportd
    17. CONFIG(release, debug|release):LIBS += -lqextserialport
    To copy to clipboard, switch view to plain text mode 

    The paths I put in there are to this folder: http://www.roboticsguy.com/qextserialport.zip

    I'm really over my head here, I've never used DLLs before and have no idea what I'm doing I really appreciate your time and any advice you could give me.

  12. #10
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How do to add a library to my project?

    Qt Code:
    1. LIBS += -LC:\Users\Nathan\Desktop\qextserialport -lqextserialport
    2.  
    3. CONFIG(debug, debug|release):LIBS += -lqextserialportd
    4. CONFIG(release, debug|release):LIBS += -lqextserialport
    To copy to clipboard, switch view to plain text mode 
    in debug version you are linking to both versions of library... so remove -lqextserialport from the first line I pasted.
    What does it mean it is not working? What errors you get? Are you using MinGW or VisualStudio?
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

Similar Threads

  1. plugin in a library
    By alisami in forum Qt Programming
    Replies: 2
    Last Post: 3rd October 2008, 18:21
  2. How to Compile VTKDesigner2 with Qt?
    By alfredoaal in forum Newbie
    Replies: 0
    Last Post: 5th September 2008, 06:34
  3. Library and Subdirs building problem
    By herenbdy in forum Qt Programming
    Replies: 2
    Last Post: 10th July 2008, 03:10
  4. Replies: 1
    Last Post: 5th March 2007, 21:50
  5. CMake and pthreads
    By Matt Smith in forum General Discussion
    Replies: 5
    Last Post: 3rd September 2006, 21:42

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.