Results 1 to 2 of 2

Thread: Quick question regarding abstract classes and DLLs

  1. #1
    Join Date
    Oct 2006
    Location
    Germany
    Posts
    84
    Thanks
    5
    Thanked 5 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Quick question regarding abstract classes and DLLs

    Hello,
    I have a rather simple question which I can't solve on my own because I'm still a rookie
    Anyway, I have my main application (main.exe) and a module.dll. My application has an AbstractModule class for custom modules and the module.dll uses this.

    AbstractModule.h
    Qt Code:
    1. //.h
    2. class AbstractModule
    3. {
    4. public:
    5. virtual QString name() const = 0;
    6. bool isSomething() const;
    7. };
    8.  
    9. //.cpp
    10. bool AbstractModule::isSomething()
    11. {
    12. return true;
    13. }
    To copy to clipboard, switch view to plain text mode 

    Now I create a separate module dll for the first module ("module.dll") and it uses the "abstractmodule.h":
    Qt Code:
    1. //.h
    2. #include <abstractmodule.h>
    3. class Module : public AbstractModule
    4. {
    5. public:
    6. Module();
    7.  
    8. QString name() const;
    9. };
    10.  
    11. //.cpp
    12. Module::Module()
    13. {
    14. bool isIt = this->isSomething(); //Link error (LNK2019)
    15. }
    16. QString Module::name() const
    17. {
    18. return "Test";
    19. }
    To copy to clipboard, switch view to plain text mode 

    In Visual Studio I set the "module.dll"-project to be dependent on the "main.exe"-project.
    But when I try to compile the solution I get a link error:
    error LNK2019: unresolved external symbol [...]
    I guess it has somehow to do with the fact that the definition of AbstractModule::isSomething() is in the .exe?
    I'm sorry, but I'm totally new to this whole dll stuff
    Thank you for your help.

  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: Quick question regarding abstract classes and DLLs

    If the abstract module has at least one method actually implemented, you have to add the definition to the dll as well, you can't make a dll depend on an exe (only the other way round).

    Hint: You can define some methods in the header file, so you don't have to add any cpp files to your library.

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

    durbrak (8th February 2007)

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.