Results 1 to 4 of 4

Thread: Some questions about using libs in my project

  1. #1
    Join Date
    Jul 2009
    Location
    Valladolid, Spain
    Posts
    125
    Thanks
    16
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Some questions about using libs in my project

    I have a few questions about using libraries with my project.

    First of all, I have a library project (attached here). I can build it fine, but I don't know how to make my project (my main app) use it.

    I have that in my main app pro file:

    Qt Code:
    1. INCLUDEPATH += ./libs/qtsingleapplication/
    2. LIBS += -L./libs/qtsingleapplication/ -lqtsingleapplication
    To copy to clipboard, switch view to plain text mode 

    But when I try to do a

    Qt Code:
    1. #include <QtSingleApplication>
    To copy to clipboard, switch view to plain text mode 

    I get an error saying that the file or folder can't be found.
    What else should I do.

    My second question is how can I make QtCreator build my library and then my main app according to debug or release. Also, should I change something in the pro file of my lib or in the pro file of my app to make them see that they should behave in a different way when debug or release is selected.

    Regards!

    qtsingleapplication.zip

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Some questions about using libs in my project

    Qt Code:
    1. #include <QtSingleApplication>
    To copy to clipboard, switch view to plain text mode 
    and
    Qt Code:
    1. INCLUDEPATH += ./libs/qtsingleapplication/
    To copy to clipboard, switch view to plain text mode 
    This means it searches for the QtSingleApplication first in the known include paths like /usr/include etc...
    If it doesn't find it, it will look in the paths you defined in the pro file, in your case it will look for:
    Qt Code:
    1. /home/youraccount/yourproject/builddir/libs/qtsingleapplication/QtSingleApplication
    To copy to clipboard, switch view to plain text mode 
    Is this the correct path for the header?

    As for building the library in debug or release, you can adjust the project settings. There's a projects button on the left hand side of the Qt Creator window. If you click on that button you'll get a lot of build and run options that you can create or choose from.

  3. #3
    Join Date
    Jul 2009
    Location
    Valladolid, Spain
    Posts
    125
    Thanks
    16
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Some questions about using libs in my project

    But my lib has a few source files that depend on the system that it's built (qtsingleapplication_win.cpp, qtsingleapplication_mac.cpp, qtsingleapplication_x11.cpp)
    And I have a pri file that makes 'make' compile only the source file that is needed.

    On the other hand, if I add the INCLUDEPATH as you said, I get an "undefined reference to "QtSingleApplication::<methods_go_here>" (I guess that this is happening because of what I already said about the source files)

    How can I fix that?

  4. #4
    Join Date
    Jul 2009
    Location
    Valladolid, Spain
    Posts
    125
    Thanks
    16
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Some questions about using libs in my project

    Ok, I figured out how to use my lib with my project. I made a pro file for building my lib. It looks like this:

    Qt Code:
    1. TEMPLATE = lib
    2.  
    3. INCLUDEPATH += $$PWD
    4.  
    5. HEADERS += $$PWD/qtglobal.h \
    6. $$PWD/qtglobalshortcut.h \
    7. $$PWD/qtglobalshortcut_p.h
    8.  
    9. SOURCES += $$PWD/qtglobal.cpp \
    10. $$PWD/qtglobalshortcut.cpp
    11.  
    12. macx{
    13. SOURCES += $$PWD/qtglobalshortcut_mac.cpp
    14. }
    15.  
    16. unix:!mac{
    17. SOURCES += $$PWD/qtglobalshortcut_x11.cpp
    18. }
    19.  
    20. win32{
    21. SOURCES += $$PWD/qtglobalshortcut_win.cpp
    22. }
    To copy to clipboard, switch view to plain text mode 

    Everything works fine when compiling/running my app, and I'm able to use the functions in my lib. The problem is that when I build everything, my lib goes to the same directory that my main app, while in the "source structure" my library is under myproject/libs/my_library/.

    How can I make qtcreator build my library in that same folder structure but in the build directory?

Similar Threads

  1. Project file LIBS debug/release
    By bunjee in forum Qt Programming
    Replies: 5
    Last Post: 27th July 2015, 05:42
  2. Replies: 2
    Last Post: 24th August 2010, 16:47
  3. Replies: 1
    Last Post: 3rd December 2009, 23:34
  4. Project generation on linux from QT Project
    By darpan in forum Qt Programming
    Replies: 6
    Last Post: 11th December 2006, 09:43
  5. use libs under qt4
    By raphaelf in forum Qt Programming
    Replies: 6
    Last Post: 27th February 2006, 17:59

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.