Results 1 to 2 of 2

Thread: Struggling with interface classes

  1. #1
    Join Date
    Aug 2008
    Posts
    132
    Thanks
    23
    Thanked 3 Times in 3 Posts

    Default Struggling with interface classes

    Hi Guys,

    I'm running into a problem with a class implementing different interfaces. There is basically 3 libraries: 1 contains the IPlugin interface below, the 2nd contains the IInputParser interface and the third contains the class using these interfaces.

    Here is the class and interface definitions. Note that all the SHARED_EXPORT macros are defined in the different libraries as shown below for example:

    Qt Code:
    1. #if defined(HDL_AUTHOR_PARSER_LIBRARY)
    2. # define HDL_AUTHOR_PARSER_SHARED_EXPORT Q_DECL_EXPORT
    3. #else
    4. # define HDL_AUTHOR_PARSER_SHARED_EXPORT Q_DECL_IMPORT
    5. #endif
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. class HDL_AUTHOR_PARSER_SHARED_EXPORT HDL_Author_Parser : public IPlugin, public IInputParser
    2. {
    3. Q_OBJECT
    4. Q_INTERFACES(Qtilities::ExtensionSystem::Interfaces::IPlugin)
    5. //Q_INTERFACES(FirmwareCore::Interfaces::IInputParser)
    6.  
    7. public:
    8. HDL_Author_Parser(QObject* parent = 0);
    9. ~HDL_Author_Parser();
    10.  
    11. // --------------------------------------------
    12. // IInputParser Implementation
    13. // --------------------------------------------
    14. DesignManager* parseDesignFromFile(const QString& fileName) const;
    15. QMap<QString,QString> supportedFileTypes() const;
    16.  
    17. // --------------------------------------------
    18. // IPlugin Implementation
    19. // --------------------------------------------
    20. bool initialize(const QStringList &arguments, QString *errorString);
    21. bool initializeDependancies(QString *errorString);
    22. void finalize();
    23. double pluginVersion();
    24. QList<double> pluginCompatibilityVersions();
    25. QString pluginPublisher();
    26. QString pluginPublisherWebsite();
    27. QString pluginPublisherContact();
    28. QString pluginDescription();
    29. QString pluginCopyright();
    30. QString pluginLicense();
    31.  
    32. private:
    33. HDL_Author_ParserData* d;
    34. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. class FIRMWARE_CORE_LIBRARY_SHARED_EXPORT IInputParser {
    2. public:
    3. IInputParser() {}
    4. virtual ~IInputParser() {}
    5.  
    6. virtual DesignManager* parseDesignFromFile(const QString& fileName) const = 0;
    7. virtual QMap<QString,QString> supportedFileTypes() const = 0;
    8. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. class EXTENSION_SYSTEM_SHARED_EXPORT IPlugin : public QObject
    2. {
    3. Q_OBJECT
    4. Q_ENUMS(PluginState)
    5.  
    6. public:
    7. IPlugin(QObject* parent = 0) : QObject(parent) {}
    8. virtual ~IPlugin() {}
    9.  
    10. enum PluginState { Functional, InitializationError, DependancyError };
    11. void setPluginState(PluginState state) { d_state = state; }
    12. PluginState pluginState() { return d_state; }
    13. void setErrorString(const QString& error_string) { d_error_string = error_string; }.
    14. QString errorString() { return d_error_string; }
    15. virtual bool initialize(const QStringList &arguments, QString *errorString) = 0;
    16. virtual bool initializeDependancies(QString *errorString) = 0;
    17. virtual void finalize() { }
    18. virtual double pluginVersion() = 0;
    19. virtual QList<double> pluginCompatibilityVersions() = 0;
    20. virtual QString pluginPublisher() = 0;
    21. virtual QString pluginPublisherWebsite() = 0;
    22. virtual QString pluginPublisherContact() = 0;
    23. virtual QString pluginDescription() = 0;.
    24. virtual QString pluginCopyright() = 0;
    25. virtual QString pluginLicense() = 0;
    26.  
    27. private:
    28. PluginState d_state;
    29. QString d_error_string;
    30. };
    To copy to clipboard, switch view to plain text mode 

    Now when I compile this I get linker errors:
    Qt Code:
    1. d:/Projects/Qt/FirmwareManagementTool/sources/trunk/build/tmp/HDL_Author_Parser/HDL_Author_Parser.o: In function `IInputParser':
    2. d:/Projects/Qt/FirmwareManagementTool/sources/trunk/libraries/FirmwareCore/sources/IInputParser.h:26: undefined reference to `_imp___ZTVN12FirmwareCore10Interfaces12IInputParserE'
    3. d:/Projects/Qt/FirmwareManagementTool/sources/trunk/build/tmp/HDL_Author_Parser/HDL_Author_Parser.o: In function `~IInputParser':
    4. d:/Projects/Qt/FirmwareManagementTool/sources/trunk/libraries/FirmwareCore/sources/IInputParser.h:27: undefined reference to `_imp___ZTVN12FirmwareCore10Interfaces12IInputParserE'
    5. d:/Projects/Qt/FirmwareManagementTool/sources/trunk/libraries/FirmwareCore/sources/IInputParser.h:27: undefined reference to `_imp___ZTVN12FirmwareCore10Interfaces12IInputParserE'
    6. d:/Projects/Qt/FirmwareManagementTool/sources/trunk/libraries/FirmwareCore/sources/IInputParser.h:27: undefined reference to `_imp___ZTVN12FirmwareCore10Interfaces12IInputParserE'
    To copy to clipboard, switch view to plain text mode 

    I really don't understand why it does not work and I can't see any problems. When the HDL_Author_Parser class does not inherit from the IInputParser class it is not a problem.

    Any help would be appreciated.

    Thanks,
    Jaco

  2. #2
    Join Date
    Aug 2008
    Posts
    132
    Thanks
    23
    Thanked 3 Times in 3 Posts

    Default Re: Struggling with interface classes

    It seems like I managed to get around the problem but it is really a hack only. It seems like the interface classes are not exported properly when the interface is not used anywhere in the library where it lives.

    I the dummy class shown below to the library where the interface classes live and now it works.

    Qt Code:
    1. class DummyParser : public QObject, public IInputParser, public IOutputParser
    2. {
    3. Q_OBJECT
    4. public:
    5. explicit DummyParser(QObject *parent = 0);
    6.  
    7. // --------------------------------------------
    8. // IInputParser Implementation
    9. // --------------------------------------------
    10. DesignManager* parseDesignFromFile(const QString& fileName) const { return 0; }
    11. QMap<QString,QString> supportedInputTypes() const { return QMap<QString,QString>(); }
    12.  
    13. // --------------------------------------------
    14. // IOutputParser Implementation
    15. // --------------------------------------------
    16. bool parseDesignToFile(IDesignManager* design, const QString& fileName) const { return 0; }
    17. QMap<QString,QString> supportedOutputTypes() const { return QMap<QString,QString>(); }
    18.  
    19. signals:
    20.  
    21. public slots:
    22. };
    To copy to clipboard, switch view to plain text mode 

    Has anybody seen this before?
    Thanks
    Jaco

Similar Threads

  1. Effecinecy for a GU Interface
    By salmanmanekia in forum Newbie
    Replies: 3
    Last Post: 2nd June 2010, 14:24
  2. Struggling with QThread...
    By TemporalBeing in forum Qt Programming
    Replies: 2
    Last Post: 23rd March 2009, 20:46
  3. Struggling with value space
    By UnicycleBloke in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 28th May 2008, 23:26
  4. C++ Interface ..???
    By joseph in forum General Programming
    Replies: 3
    Last Post: 28th May 2008, 09:27
  5. how to do interface for gdb
    By misiak in forum Qt Programming
    Replies: 2
    Last Post: 13th November 2006, 21:19

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.