Results 1 to 6 of 6

Thread: DLL export problem

  1. #1
    Join Date
    Jan 2008
    Posts
    13
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default DLL export problem

    hi to all!

    i've created a simple program with export(i'm not sure if my export code is right) and compile it as .dll..

    then i'm trying to access the .dll using delphi.. but the problem is i can't acces the function in my .dll.. please help..

    heres my code:

    //in .h
    Qt Code:
    1. class q_decl_export dialogimpl : public qdialog, public ui.html#Dialog
    2. {
    3. Q_OBJECT
    4. public:
    5. DialogImpl;
    6. #endif" class="bbcodeurl">#ifndef DIALOGIMPL_H
    7. #define DIALOGIMPL_H
    8. #include <QDialog>
    9. #include "ui_dialog.h"
    10.  
    11. class Q_DECL_EXPORT DialogImpl : public QDialog, public Ui::Dialog
    12. {
    13. Q_OBJECT
    14. public:
    15. DialogImpl( QWidget * parent = 0, Qt::WFlags f = 0 );
    16. void ShowMessage();
    17. private slots:
    18. };
    19. Q_DECL_EXPORT void ShowMessage();
    20. #endif
    21. //in .cpp
    22.  
    23. #include
    24.  
    25. //
    26. q_decl_export dialogimpl.html#DialogImpl;
    27. }" class="bbcodeurl">#include "dialogimpl.h"
    28. #include <QMessageBox>
    29.  
    30. //
    31. Q_DECL_EXPORT DialogImpl::DialogImpl( QWidget * parent, Qt::WFlags f)
    32. : QDialog(parent, f)
    33. {
    34. setupUi(this);
    35. ShowMessage();
    36. }
    37.  
    38. Q_DECL_EXPORT void DialogImpl::ShowMessage()
    39. {
    40. QMessageBox::information(this, tr("DLL"),"DLL exported!");
    41. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by marcel; 11th February 2008 at 07:08. Reason: missing [code] tags

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: DLL export problem

    Unfortunately it's not correct. You can't hardcode Q_DECL_EXPORT like that. You must use Q_DECL_EXPORT when building the library and Q_DECL_IMPORT when using the library. For more details, see this thread: Q_DECL_EXPORT and Q_DECL_IMPORT.
    J-P Nurmi

  3. #3
    Join Date
    Jan 2008
    Posts
    13
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: DLL export problem

    Quote Originally Posted by jpn View Post
    Unfortunately it's not correct. You can't hardcode Q_DECL_EXPORT like that. You must use Q_DECL_EXPORT when building the library and Q_DECL_IMPORT when using the library. For more details, see this thread: Q_DECL_EXPORT and Q_DECL_IMPORT.

    i've changed my first code to this:

    in .h

    Qt Code:
    1. #ifndef DIALOGIMPL_H
    2. #define DIALOGIMPL_H
    3. #include <QDialog>
    4. #include "ui_dialog.h"
    5.  
    6. #ifndef _DLL_BUILD_
    7. #if (defined(QT_DLL) || defined(QT_SHARED)) && !defined(QT_PLUGIN)
    8. #define EXPORT Q_DECL_EXPORT
    9. #else
    10. #define EXPORT
    11. #endif
    12. #else
    13. #define EXPORT Q_DECL_IMPORT
    14. #endif
    15.  
    16.  
    17. class EXPORT DialogImpl : public QDialog, public Ui::Dialog
    18. {
    19. Q_OBJECT
    20. public:
    21. DialogImpl( QWidget * parent = 0, Qt::WFlags f = 0 );
    22. void ShowMessage();
    23. private slots:
    24. };
    25.  
    26. EXPORT void ShowMessage();
    27. #endif
    To copy to clipboard, switch view to plain text mode 

    in .cpp

    Qt Code:
    1. #include "dialogimpl.h"
    2. #include <QMessageBox>
    3.  
    4. EXPORT DialogImpl::DialogImpl( QWidget * parent, Qt::WFlags f)
    5. : QDialog(parent, f)
    6. {
    7. setupUi(this);
    8. ShowMessage();
    9. }
    10.  
    11. EXPORT void DialogImpl::ShowMessage()
    12. {
    13. QMessageBox::information(this, tr("DLL"),"DLL exported!");
    14. }
    To copy to clipboard, switch view to plain text mode 

    i have build the program without error but still the .dll can't be access by delphi..

    hmm, is there any suggestion on how i can solve my problem?

    thanks..
    Last edited by jpn; 11th February 2008 at 09:08. Reason: changed [quote] to [code] tags

  4. #4
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: DLL export problem

    Why do you think you can access C++ code from Delphi? A Qt-Window will never run without a proper QApplication...

  5. #5
    Join Date
    Jan 2008
    Posts
    13
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: DLL export problem

    I think any program compiled into a .dll can be access/imported by any programming language provided that it is properly exported..

    my problem is, I can't find the right code to export my dll..

    is there any suggestion on how I can make this?

    thanks..

  6. #6
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: DLL export problem

    Did you read my post?

    You can't access a QWidget from Delphi (or whatever) because you need a QMainApplication. Also you can't access a C++ class from Delphi at all (imho).

Similar Threads

  1. Tricky problem with ARGB widget / UpdateLayeredWindow
    By nooky59 in forum Qt Programming
    Replies: 3
    Last Post: 21st February 2008, 10:35
  2. qtopia core 4 Fonts on device problem
    By thanwei in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 25th September 2007, 20:42
  3. [QMYSQL] connection problem
    By chaos_theory in forum Installation and Deployment
    Replies: 5
    Last Post: 2nd July 2007, 09:52
  4. problem aboout install qt/e 3.3.4
    By cti1912 in forum Installation and Deployment
    Replies: 0
    Last Post: 12th October 2006, 09:28
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.