Results 1 to 5 of 5

Thread: Qt and dlls ?

  1. #1
    Join Date
    Jan 2006
    Posts
    185
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Qt and dlls ?

    Let me make it simple:

    I have a class that allows me to put together two words. You instantiate this class, pass two words to it, and you will get the words added together and capitalized.

    You pass "hel" and "lo"

    You get "HELLO"

    Now, the question is:

    How can I make a dll out of that class, so I can later on change some of its functionality without having to compile the whole program again ?

    I want a dll for windows and a .so for Linux.

    How ?

  2. #2
    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: Qt and dlls ?

    Create such a project file:
    TEMPLATE=lib
    CONFIG += dll
    CONFIG -= qt # I'm not sure if you want this
    SOURCES+=filename.cpp
    HEADERS+=filename.h
    qmake && (n)make should do it.

  3. #3
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt and dlls ?

    1. Create a qmake project, specifying "TEMPLATE = lib" and maybe "CONFIG += shared"
    2. Add an header which will hold some crucial macros, ideally it should be called $projectname$.h
    3. In this file add the following code (some names may be changed...)
    Qt Code:
    1. #ifdef _PROJECT_BUILD_
    2. #if (defined(QT_SHARED) || defined(QT_DLL)) && !defined(QT_PLUGIN)
    3. #define PROJECT_EXPORT Q_DECL_EXPORT
    4. #else
    5. #define PROJECT_EXPORT
    6. #endif
    7. #else
    8. #define PROJECT_EXPORT Q_DECL_IMPORT
    9. #endif
    To copy to clipboard, switch view to plain text mode 

    Then include this file in all headers containing classes definition meant to be exported and place this macro between the "class" keyword and your class name.

    Compile your dll.

    To link the created dll through qmake add the following line to your project file :

    LIBS += -L$path/to/your/dll$ -l$name_of_your_dll_without_suffix$

    And you're done!!!
    Current Qt projects : QCodeEdit, RotiDeCode

  4. #4
    Join Date
    Jan 2006
    Posts
    185
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt and dlls ?

    how about for Linux ?

  5. #5
    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: Qt and dlls ?

    For Linux my answer is sufficient

Similar Threads

  1. Can't build Dlls in VS2005 mt.exe error
    By kemp in forum Qt Programming
    Replies: 1
    Last Post: 28th August 2006, 12:38
  2. Using dll's in QT
    By qtguy in forum Qt Programming
    Replies: 1
    Last Post: 29th June 2006, 15:11
  3. making a portable binary on windows
    By patcito in forum Qt Programming
    Replies: 10
    Last Post: 29th May 2006, 09:02

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.