Results 1 to 16 of 16

Thread: Problem of including Widgets into DLL

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2008
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Problem of including Widgets into DLL

    Hi. I am writing a software using VS2008 and QT4.3.3 with VS integration and it's structure is following:

    First project is an application
    Second project is a Qt Library project which produces a DLL. Now the problem I am having is that when I include DLL header file into my application compiled can't find auto generated ui_***.h file.

    How should I go about including several widgets that I plan to use into a single DLL and be able to use QT Designer. If I were to write a widget from scratch without using .ui files - everything works. But the problem is that DLL compiles just fine, but the actual application, when includes DLL header (which also includes auto generated ui_***.h files) does not find those auto generated headers.

    Maybe there is some other way to write a single DLL projects which includes several widgets?

  2. #2
    Join Date
    Nov 2008
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem of including Widgets into DLL

    HI.

    I have done something the same as you do...but I made an _impl class which inluded the ui file.

    the actual dll interface is defined as an interface class I have totally defined (just calls to the _impl class)...in this way I can control which elements in the widget(s) can be accessed externally.

    rgds
    Jan

  3. #3
    Join Date
    Nov 2008
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem of including Widgets into DLL

    I am not sure what you mean by _impl class. Could you explain a little more. I am not a big C++ pro =(

  4. #4
    Join Date
    Nov 2008
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem of including Widgets into DLL

    I always make the dll's with one interface class.

    e.g.

    dll_mywidget.hpp
    dll_mywidget.cpp

    the class dll_mywidget are just call to another class dll_mywidget_impl

    The dll_mywidget_impl class is the one that include the ui file...basically you make dll_mywidget_impl as you would make a normal widget....

    and in dll_mywidget.cpp you decide which parts to make public in the dll...dont forget the class you want to make public in the dll, needs special DLL declaration (DLL_EXPORT) in order to work.

    jan

  5. #5
    Join Date
    Nov 2008
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem of including Widgets into DLL

    LOL I still don't get it. I think the way I understand it is that I have a dummy class which gets included into the main application and it exports other class with UI. But how do I include the base class into main application without ui header?

    So far I have this:

    Here the dummy class which includes the interface class (test.h) :
    Qt Code:
    1. #ifndef FBL_GUI_H
    2. #define FBL_GUI_H
    3.  
    4. #include "fbl_gui_global.h"
    5. #include "test.h"
    6. class FBL_GUI_EXPORT fbl_gui
    7. {
    8. public:
    9. fbl_gui();
    10. ~fbl_gui();
    11.  
    12. private:
    13.  
    14. };
    15.  
    16. #endif // FBL_GUI_H
    To copy to clipboard, switch view to plain text mode 

    Then I have an interface class in the same dll project:

    Qt Code:
    1. #ifndef TEST_H
    2. #define TEST_H
    3.  
    4. #include <QWidget>
    5. #include "ui_test.h"
    6.  
    7. class test : public QWidget
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. test(QWidget *parent = 0);
    13. ~test();
    14.  
    15. private:
    16. Ui::testClass ui;
    17. };
    18.  
    19. #endif // TEST_H
    To copy to clipboard, switch view to plain text mode 

    Now the problem is that if I include the base dll class it also includes the widget class. How can I skip this part but be able to access the widget and be able to create it in the main app?

  6. #6
    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: Problem of including Widgets into DLL

    Quote Originally Posted by dsedov View Post
    Hi. I am writing a software using VS2008 and QT4.3.3 with VS integration and it's structure is following:

    First project is an application
    Second project is a Qt Library project which produces a DLL. Now the problem I am having is that when I include DLL header file into my application compiled can't find auto generated ui_***.h file.

    How should I go about including several widgets that I plan to use into a single DLL and be able to use QT Designer. If I were to write a widget from scratch without using .ui files - everything works. But the problem is that DLL compiles just fine, but the actual application, when includes DLL header (which also includes auto generated ui_***.h files) does not find those auto generated headers.

    Maybe there is some other way to write a single DLL projects which includes several widgets?
    at the first you need to create h-file with the following content (e.g. myglobal.h)
    Qt Code:
    1. #ifndef MYGLOBAL_H
    2. #define MYGLOBAL_H
    3.  
    4. #include <QtGlobal>
    5.  
    6. #ifdef MY_LIB_STATICLIB
    7. # undef MY_LIB_SHAREDLIB
    8. # define MY_LIB_EXPORT
    9. #else
    10. # ifdef MY_LIB_MAKEDLL
    11. # define MY_LIB_EXPORT Q_DECL_EXPORT
    12. # else
    13. # define MY_LIB_EXPORT Q_DECL_IMPORT
    14. # endif
    15. #endif
    16.  
    17. #endif//MYGLOBAL_H
    To copy to clipboard, switch view to plain text mode 

    then in pro-file of your lib you should add next thing
    Qt Code:
    1. ...
    2. contains(CONFIG, staticlib) {
    3. DEFINES += MY_LIB_STATICLIB
    4. } else {
    5. DEFINES += MY_LIB_SHAREDLIB
    6. }
    7.  
    8. win32 {
    9. DEFINES += MY_LIB_MAKEDLL
    10. }
    11. ...
    To copy to clipboard, switch view to plain text mode 

    and then you must add MY_LIB_EXPORT before class name which you want to export
    Qt Code:
    1. #include "myglobal.h"
    2. class MY_LIB_EXPORT MyObj
    3. {
    4. ...
    5. };
    To copy to clipboard, switch view to plain text mode 
    Last edited by spirit; 14th November 2008 at 13:20. Reason: updated contents
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  7. #7
    Join Date
    Nov 2008
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem of including Widgets into DLL

    Yeah I know that. Thanks. The problem is that when I include DLL header in a main app it won't be able to find autogenerated files from QT Designer. Dll compiles just fine, but when main app compiles it sais : fatal error C1083: Cannot open include file: 'ui_test.h': No such file or directory

  8. #8
    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: Problem of including Widgets into DLL

    could you show us pro-file of app not lib?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  9. #9
    Join Date
    Nov 2008
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem of including Widgets into DLL

    Err.. there is no .pro file. I am using VS2008 with QT integration.

  10. #10
    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: Problem of including Widgets into DLL

    ok. what do you try to do now: build a lib or build app with the lib which you are created?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  11. #11
    Join Date
    Nov 2008
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem of including Widgets into DLL

    Build an app.
    The lib compiles just fine. I just have problem of my app using lib headers as it cannot find autogenerated ui_***.h files.

    My app has this in a header:
    Qt Code:
    1. #include "../fbl_gui/fbl_gui.h"
    To copy to clipboard, switch view to plain text mode 

    This includes library header, so I will be able to use it's objects.

  12. #12
    Join Date
    Nov 2008
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem of including Widgets into DLL

    So any ideas???

  13. #13
    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: Problem of including Widgets into DLL

    look at this example
    Attached Files Attached Files
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

Similar Threads

  1. Replies: 0
    Last Post: 16th July 2008, 13:15
  2. Replies: 3
    Last Post: 10th May 2008, 17:36
  3. Algorithms problem of brackets including.
    By luffy27 in forum General Programming
    Replies: 2
    Last Post: 12th April 2007, 01:10
  4. Docking widgets setFixedSize and setBaseSize Problem
    By forrestfsu in forum Qt Programming
    Replies: 2
    Last Post: 16th October 2006, 18:20
  5. Replies: 11
    Last Post: 7th July 2006, 13:09

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.