Results 1 to 10 of 10

Thread: Creating custom plugin

  1. #1
    Join Date
    Feb 2007
    Location
    Wroclaw, Poland
    Posts
    72
    Thanks
    6
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Creating custom plugin

    Hi,
    I want to create a plugin system. So - first I create Interface
    Qt Code:
    1. class ShopInterface
    2. {
    3. public:
    4. virtual ~ShopInterface() {}
    5.  
    6. virtual QStringList shopNames() const = 0;
    7. virtual QIcon getShopIcon() const = 0;
    8. virtual bool checkPrices(QString strCompName, double & dPrice, QString strURL );
    9. };
    To copy to clipboard, switch view to plain text mode 

    Then in separate CMake/VS project plugin is created.
    Qt Code:
    1. class Shop1Plugin : public QObject, public ShopInterface
    2. {
    3. Q_OBJECT
    4. Q_INTERFACES(ShopInterface)
    5. public:
    6. virtual ~Shop1Plugin ();
    7. virtual QStringList shopNames() const;
    8. virtual QIcon getShopIcon() const;
    9. virtual bool checkPrices(QString strCompName, double & dPrice, QString strURL );
    10. };
    To copy to clipboard, switch view to plain text mode 

    File Shop1Plugin.h file is sent to MOC which reports 'Error: Undefined interface' in line with Q_INTERFACES().
    Why? Using Qt version 4.7.3

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Creating custom plugin

    Ehm, where is Q_DECLARE_INTERFACE?

  3. #3
    Join Date
    Feb 2007
    Location
    Wroclaw, Poland
    Posts
    72
    Thanks
    6
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Creating custom plugin

    Oh, I forgot to add this. To be sure - this time its entire interface header.
    Qt Code:
    1. #ifndef _CCS_SHOP_INTERFACE_INCLUDE_
    2. #define _CCS_SHOP_INTERFACE_INCLUDE_
    3. #include <QtCore/QStringList>
    4. #include <QtGui/QIcon>
    5.  
    6. class ShopInterface
    7. {
    8. public:
    9. virtual ~ShopInterface() {}
    10.  
    11. virtual QStringList shopNames() const = 0;
    12. virtual QIcon getShopIcon() const = 0;
    13. virtual bool checkPrices(QString strCompName, double & dPrice, QString strURL );
    14. };
    15. Q_DECLARE_INTERFACE(ShopInterface, "ShopInterface/1.0");
    16.  
    17. #endif //_CCS_SHOP_INTERFACE_INCLUDE_
    To copy to clipboard, switch view to plain text mode 

    And - of course - in implemented plugin there is correct #include.

  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: Creating custom plugin

    Does the plugin have the Q_EXPORT_PLUGIN2 macro?
    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. #5
    Join Date
    Feb 2007
    Location
    Wroclaw, Poland
    Posts
    72
    Thanks
    6
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Creating custom plugin

    Yes, but placed in cpp file. In plugin examples I see that all of them have this macro there.
    On the other hand - it looks like MOC compiler tries to expand Q_INTERFACES define and have problem to find appropriate interface definitions.

  6. #6
    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: Creating custom plugin

    Did you include the file containing the interface definition in the plugin header file?
    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.


  7. #7
    Join Date
    Feb 2007
    Location
    Wroclaw, Poland
    Posts
    72
    Thanks
    6
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Creating custom plugin

    Qt Code:
    1. #ifndef _CCS_SHOP_1_INCLUDE_
    2. #define _CCS_SHOP_1_INCLUDE_
    3. #include <ShopInterface.h>
    4. #include <QtCore/QtPlugin>
    5.  
    6. class Shop1Plugin : public QObject, public ShopInterface
    7. {
    8. Q_OBJECT
    9. Q_INTERFACES(ShopInterface)
    10. public:
    11. virtual ~Shop1Plugin ();
    12. virtual QStringList shopNames() const;
    13. virtual QIcon getShopIcon() const;
    14. virtual bool checkPrices(QString strCompName, double & dPrice, QString strURL );
    15. };
    16. #endif
    To copy to clipboard, switch view to plain text mode 

    It seems most likely that #include isn't processed. Like MOC can't finding Q_DECLARE_INTERFACE, but as you see - its there. I'll make test and put entire interface in one file with its realization.
    PS. And it worked. If Interface is in the same file as its realization - it worked. Why MOC can't find this include? Maybe I should add this include to MOC processing line.

  8. #8
    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: Creating custom plugin

    Make sure the directory containing ShopInterface.h is in INCLUDEPATH.
    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.


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

    hereiam (17th August 2012)

  10. #9
    Join Date
    Feb 2007
    Location
    Wroclaw, Poland
    Posts
    72
    Thanks
    6
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Creating custom plugin

    I use CMake to create configurations and projects. And this is the first time that MOC requires includes. Now I now what need to be fixed.

  11. #10
    Join Date
    Aug 2012
    Posts
    10
    Thanks
    1

    Default Re: Creating custom plugin

    Quote Originally Posted by wysota View Post
    Make sure the directory containing ShopInterface.h is in INCLUDEPATH.
    thanks really a great tip because in previous projects from me cmake always seached all header files automatically.

    I had the same problem but it is fixed now.

Similar Threads

  1. Replies: 4
    Last Post: 22nd May 2011, 17:26
  2. creating designer plugin
    By GrahamLabdon in forum Newbie
    Replies: 3
    Last Post: 21st March 2011, 11:58
  3. Error while creating a plugin for Qt
    By panpaliamahen in forum Qt Programming
    Replies: 1
    Last Post: 7th August 2010, 19:12
  4. Qt plugin for Eclipse not creating Makefile
    By di_zou in forum Qt Tools
    Replies: 2
    Last Post: 15th October 2009, 15:36
  5. creating table plugin
    By mgurbuz in forum Qt Programming
    Replies: 3
    Last Post: 28th April 2006, 13:50

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.