Results 1 to 9 of 9

Thread: how to use Qt dll in Win32 project

  1. #1
    Join Date
    Jul 2007
    Location
    BY.Minsk
    Posts
    90
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default how to use Qt dll in Win32 project

    Hello !

    I created a project Qt dll, It compiles and runs perfectly.
    I get in the output files:
    test.dll
    test.lib
    also have the following files:
    test.h
    test_global.h

    Now, faced with the task, to connect the library to the project in C + + (without Qt!!!)
    but in the files
    test.h
    test_global.h
    there is a connection # include <Qt\qglobal.h>
    And the project is not going to, and not linked.

    Prompt how to create a header file that can connect the library to the project Win32 ?

  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: how to use Qt dll in Win32 project

    You have to expose some interface that will not contain any Qt related things. Then make your Qt class inherit and implament that interface. Then you'll only deliver the base class header file, without any Qt related things.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jul 2007
    Location
    BY.Minsk
    Posts
    90
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to use Qt dll in Win32 project

    Quote Originally Posted by wysota View Post
    You have to expose some interface that will not contain any Qt related things. Then make your Qt class inherit and implament that interface. Then you'll only deliver the base class header file, without any Qt related things.
    May be you can show some example ?

  4. #4
    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: how to use Qt dll in Win32 project

    Quote Originally Posted by Fastman View Post
    May be you can show some example ?
    Let's see...

    Qt Code:
    1. class SomeInterface {
    2. public:
    3. virtual ~SomeInterface(){}
    4. virtual int method1() const = 0;
    5. virtual std::string method2(int) = 0;
    6. // etc.
    7. };
    8.  
    9. class MyQtImplementation : public SomeInterface {
    10. public:
    11. MyQtImplementation(...){...}
    12. int method1() const { qDebug() << "Qt here"; return 1; }
    13. std::string method2(int num) { return QString::number(num).toStdString(); }
    14. };
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    Fastman (9th July 2009)

  6. #5
    Join Date
    Apr 2008
    Posts
    196
    Thanked 8 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    1

    Default Re: how to use Qt dll in Win32 project

    Qt Code:
    1. // H - Interface
    2. class ISampleClass {
    3. public:
    4. virtual ~ISampleClass() {}
    5.  
    6. void DemoFunction1();
    7. void DemoFunction2() = 0; // [OPTIONAL] Abstract function, so the complete class is abstract
    8. };
    9.  
    10. // H - Implementation
    11. class SampleClass : public QObject, public ISampleClass {
    12. Q_OBJECT
    13. public:
    14. SampleClass(QObject *parent = 0);
    15. virtual ~SampleClass() {}
    16.  
    17. void DemoFunction1();
    18. void DemoFunction2();
    19. };
    20.  
    21. // CPP - Implementation
    22. SampleClass::SampleClass(QObject *parent) : QObject(parent) {
    23. }
    24.  
    25. void SampleClass::DemoFunction1() {
    26. // Do Something
    27. }
    28.  
    29. void SampleClass::DemoFunction2() {
    30. // Do Something
    31. }
    To copy to clipboard, switch view to plain text mode 

    Hope this helps

    LG NoRulez

  7. The following user says thank you to NoRulez for this useful post:

    Fastman (9th July 2009)

  8. #6
    Join Date
    Jul 2007
    Location
    BY.Minsk
    Posts
    90
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to use Qt dll in Win32 project

    thx for help !!!

  9. #7
    Join Date
    Jul 2007
    Location
    BY.Minsk
    Posts
    90
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to use Qt dll in Win32 project

    Hmmm... but i'am have some trouble:

    Qt Code:
    1. error LNK2019: unresolved external symbol "public: void __thiscall ISampleClass::DemoFunction1(void)" (?DemoFunction1@ISampleClass@@QAEXXZ) referenced in function _wmain
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "stdafx.h"
    2. #include <string.h>
    3. #include <iostream>
    4. #include "../test/ISample.h"
    5. #pragma comment(lib,"D:\\QT_PROJECT\\test\\debug\\test.lib")
    6.  
    7. using namespace std;
    8.  
    9.  
    10. int _tmain(int argc, _TCHAR* argv[])
    11. {
    12. ISampleClass a;
    13. a.DemoFunction1();
    14. return 0;
    15. }
    To copy to clipboard, switch view to plain text mode 

    What wrong ???

  10. #8
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to use Qt dll in Win32 project

    do it this way..

    Qt Code:
    1. // H - Interface
    2. class ISampleClass {
    3. public:
    4. virtual ~ISampleClass() {}
    5.  
    6. static ISampleClass* getInstance();
    7. virtual void DemoFunction1() = 0; //make everything pure virtual
    8. virtual void DemoFunction2() = 0; // [OPTIONAL] Abstract function, so the complete class is abstract
    9. private:
    10. static ISampleClass *p;
    11. };
    12.  
    13. // CPP - Implementation
    14.  
    15. ISampleClass* ISampleClass::p=0;
    16.  
    17. static ISampleClass* ISampleClass::getInstance();
    18. {
    19. if(!p)
    20. p= new SampleClass;
    21. return p;
    22. }
    23.  
    24.  
    25.  
    26. // H - Implementation
    27. class SampleClass : public QObject, public ISampleClass {
    28. Q_OBJECT
    29. public:
    30. SampleClass(QObject *parent = 0);
    31. virtual ~SampleClass() {}
    32.  
    33. void DemoFunction1();
    34. void DemoFunction2();
    35. };
    36.  
    37. // CPP - Implementation
    38. SampleClass::SampleClass(QObject *parent) : QObject(parent) {
    39. }
    40.  
    41. void SampleClass::DemoFunction1() {
    42. // Do Something
    43. }
    44.  
    45. void SampleClass::DemoFunction2() {
    46. // Do Something
    47. }
    48.  
    49. //MAIN
    50. int _tmain(int argc, _TCHAR* argv[])
    51. {
    52. ISampleClass* a= ISampleClass::getInstance();
    53. a->DemoFunction1();
    54. return 0;
    55. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by nish; 10th July 2009 at 02:05. Reason: missing [code] tags

  11. The following user says thank you to nish for this useful post:

    Fastman (10th July 2009)

  12. #9
    Join Date
    Jul 2007
    Location
    BY.Minsk
    Posts
    90
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to use Qt dll in Win32 project

    Sorry, i'am stupid

    Now everything works.
    I realized QScritEngin in a DLL and is connected to an external win32 project.
    Once again, thank you very much.

Similar Threads

  1. How to Compile VTKDesigner2 with Qt?
    By alfredoaal in forum Newbie
    Replies: 0
    Last Post: 5th September 2008, 05:34
  2. making qmake create VisualStudio console app project file?
    By akos.maroy in forum Qt Programming
    Replies: 2
    Last Post: 18th August 2008, 14:45
  3. help needed with complicated project
    By Muzz in forum Newbie
    Replies: 12
    Last Post: 15th February 2008, 09:54
  4. Importing qt project to an eclipse workspace
    By isahin in forum Installation and Deployment
    Replies: 2
    Last Post: 28th January 2008, 18:00
  5. compiling a qt project under win32
    By elcuco in forum Qt Programming
    Replies: 2
    Last Post: 19th January 2006, 07:43

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.