Results 1 to 3 of 3

Thread: dll using qt

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Posts
    23
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default dll using qt

    hi there,

    i'm not really a qt newbie - but in this field here i am

    i have to develop a dll (and a so, later, too) which uses qtcore. in particular i need container classes, threads and mutexes as well as signals and slots. i don't need any gui stuff.

    my first question: i have qt 4.3.3 installed, as well as the vs 2005 integration. now, when i choose 'new project' and specify 'qt library', i obviously get a dll project and i can build it - but - where is DllMain()

    do i have to add the code?

    my second question: do i have to have a QCoreApplication? What if the caller of my dll runs it's own event loop?

    thanks for any advice,

    sepp

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: dll using qt

    creating library
    creating dlls with Qt is very simple, you need to add export keywords to export needed entities, but there are several rules:
    first of all you need to create some kind of global h-file for your library-project with import/export variables, it should look like this example
    Qt Code:
    1. #ifndef MYWIDGET_GLOBAL_H
    2. #define MYWIDGET_GLOBAL_H
    3.  
    4. #include <QtGlobal>
    5.  
    6. #ifdef MYWIDGET_STATICLIB
    7. # undef MYWIDGET_SHAREDLIB
    8. # define MYWIDGET_EXPORT
    9. #else
    10. # ifdef MYWIDGET_MAKEDLL
    11. # define MYWIDGET_EXPORT Q_DECL_EXPORT
    12. # else
    13. # define MYWIDGET_EXPORT Q_DECL_IMPORT
    14. # endif
    15. #endif
    16.  
    17. #endif//MYWIDGET_GLOBAL_H
    To copy to clipboard, switch view to plain text mode 
    then as I said earlier you need to add export keyword before class declaration, e.g.
    Qt Code:
    1. ....
    2. #include "mywidget_global.h"
    3. ...
    4. class MYWIDGET_EXPORT MyWidget: public QWidget
    5. {
    6. ....
    7. };
    To copy to clipboard, switch view to plain text mode 
    that's all what you need to add in source file.
    then you need to prepare correct pro and pri files.
    * pri-file should contain the next lines
    MYWIDGET_LIB = -llibmywidget

    INCLUDEPATH += $$TOP/libmywidget/include
    DEPENDPATH += $$TOP/libmywidget/src
    where $$TOP is start path.
    * pro-file should contain the next lines
    CONFIG += dll
    TEMPLATE = lib
    DESTDIR = lib

    unix:CLEAN_FILES += $(DESTDIR)lib$(QMAKE_TARGET).*
    win32:CLEAN_FILES += $(DESTDIR)$(QMAKE_TARGET).*

    TOP = ../..

    TARGET = libmywidget
    include(libmywidget.pri)

    contains(CONFIG, staticlib) {
    DEFINES += MYWIDGET_STATICLIB
    } else {
    DEFINES += MYWIDGET_SHAREDLIB
    }

    win32 {
    DEFINES += MYWIDGET_MAKEDLL
    }
    and that's all! now, when you call qmake/(n/mingw32-)make you'll get shared library.
    how to attach this library to another project?
    you just need to add following lines in pro-file of needed project which will use created library
    ...
    TOP = ..

    include($$TOP/libmywidget/libmywidget.pri)

    LIBS += -L$$TOP/libmywidget/lib/ $$MYWIDGET_LIB
    ...
    and then build this project.
    PS. attach contsins complete example.
    Attached Files Attached Files
    Last edited by spirit; 27th November 2008 at 06:15.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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

    robertson1 (19th February 2009)

  4. #3
    Join Date
    Feb 2006
    Posts
    23
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: dll using qt

    Quote Originally Posted by spirit View Post
    how to attach this library to another project?
    you just need to add following lines in pro-file of needed project which will use created library

    and then build this project.
    PS. attach contsins complete example.
    ok, thanks. so i probally don't need a DllMain()... i'll find out.

    however, the application which will use my library will not be a qt project. therefore, again: do i need a QCoreApplication in my dll to use signals/slots, qt threads/mutexes and qt container classes? may this conflict with the applications own event loop?

    thanks,

    sepp

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
  •  
Qt is a trademark of The Qt Company.