Results 1 to 7 of 7

Thread: QT4 Plugins - problems, problems

  1. #1
    Join Date
    May 2006
    Location
    Leeds, West Yorkshire, UK.
    Posts
    17
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QT4 Plugins - problems, problems

    Greetings,

    anyone got QT4 plugins to work yet, other than the PlugAndPaint demo supplied with QT4.1.2 ?

    I'm using QT 4.1.2, mingw compiler and Windows 2000.

    I'm able to get the above demo to compile, but when I try to build my own simple test setup, I continually get this error :

    plugin.cpp:10: error: expected constructor, destructor, or type conversion before '(' token
    plugin.cpp:10: error: expected `,' or `;' before '(' token
    mingw32-make[1]: *** [release\plugin.o] Error 1

    For now, everything is in the same folder. I have three files :

    The interface header :

    Qt Code:
    1. class QString;
    2.  
    3. class PluginInterface {
    4. public:
    5. // Destructor - does nothing.
    6. virtual ~PluginInterface() {}
    7.  
    8. // Simple interface - returns some text in a QString.
    9. virtual QString GetText() const = 0;
    10. };
    11.  
    12. Q_DECLARE_INTERFACE(PluginInterface, "dunbar-it.co.uk.test.TextInterface/1.0")
    To copy to clipboard, switch view to plain text mode 


    The header file for my plugin :

    Qt Code:
    1. #ifndef plugin_h
    2. #define plugin_h
    3.  
    4. #include <QObject>
    5. #include <QString>
    6.  
    7. #include "interfaces.h"
    8.  
    9. class TextPlugin : public QObject, public PluginInterface {
    10. Q_OBJECT
    11. Q_INTERFACES(PluginInterface)
    12.  
    13. public:
    14. // Destructor - does nothing.
    15. ~TextPlugin() {}
    16.  
    17. // Simple interface - returns some text in a QString.
    18. QString GetText();
    19. };
    20.  
    21. #endif
    To copy to clipboard, switch view to plain text mode 
    The plugin source file :

    Qt Code:
    1. #include "plugin.h"
    2.  
    3. QString TextPlugin::GetText()
    4. {
    5. return QString("This is some text.");
    6. }
    7.  
    8. //Q_EXPORT_PLUGIN2(PlugIn_Name, Plugin_class)
    9.  
    10. Q_EXPORT_PLUGIN2(plugin, TextPlugin)
    To copy to clipboard, switch view to plain text mode 
    The project file is named 'plugin.pro' and contains the following :

    Qt Code:
    1. TEMPLATE = lib
    2. CONFIG += plugin
    3. HEADERS = plugin.h
    4. SOURCES = plugin.cpp
    5. DESTDIR = ../plugins
    6.  
    7. contains(TEMPLATE,lib) {
    8. CONFIG(debug, debug|release) {
    9. unix:TARGET = $$member(TARGET, 0)_debug
    10. else:TARGET = $$member(TARGET, 0)d
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 

    The error message only appears when I have the Q_EXPORT_PLUGIN2 macro in my cpp file. The error line is indeed that line.

    Any hints and tipe from those of you much better than I am at QT and C++ programming will be gratefully received. Thanks.

    Cheers,
    Norman.

  2. #2
    Join Date
    Jan 2006
    Posts
    109
    Thanks
    2
    Thanked 5 Times in 5 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QT4 Plugins - problems, problems

    Quote Originally Posted by NormanDunbar
    For now, everything is in the same folder. I have three files :

    The interface header :
    You don't seem to be including any Qt header in this file. Q_DECLARE_INTERFACE is declared in <QObject>.

    Quote Originally Posted by NormanDunbar
    The plugin source file :
    You don't seem to be including <QtPlugin> in this file. Q_EXPORT_PLUGIN2 is declared in <QtPlugin>.

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

    NormanDunbar (8th May 2006)

  4. #3
    Join Date
    May 2006
    Location
    Leeds, West Yorkshire, UK.
    Posts
    17
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QT4 Plugins - problems, problems

    Quote Originally Posted by dimitri
    You don't seem to be including any Qt header in this file. Q_DECLARE_INTERFACE is declared in <QObject>.
    That one made no difference

    Quote Originally Posted by dimitri
    You don't seem to be including <QtPlugin> in this file. Q_EXPORT_PLUGIN2 is declared in <QtPlugin>.
    But that one made all the difference.

    I suppose it was my own fault really, I was following the instructions given in the documentation for QT4.

    Much obliged for the prompt and accurate reply, thank you.


    Cheers,
    Norman.

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QT4 Plugins - problems, problems

    Quote Originally Posted by NormanDunbar
    // Simple interface - returns some text in a QString.
    virtual QString GetText() const = 0;
    ...
    // Simple interface - returns some text in a QString.
    QString GetText();
    There is a "const" keyword missing after TextPlugin::GetText().

  6. #5
    Join Date
    May 2006
    Location
    Leeds, West Yorkshire, UK.
    Posts
    17
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QT4 Plugins - problems, problems

    Quote Originally Posted by jacek
    There is a "const" keyword missing after TextPlugin::GetText().
    Indeed there was, thanks. I've fixed that as well. The real fix, however, was a missing #include <QtPlugin> in the cpp file. AT least, that allowed it to compile, I've yet to write the 'app' that uses the test plugin ...

    Cheers,
    Norman.

  7. #6
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QT4 Plugins - problems, problems

    That is the hard part indeed. If you need some ideas have a look at the last version of DevQt, it uses a plugin system to customize every aspect of the app.
    Current Qt projects : QCodeEdit, RotiDeCode

  8. #7
    Join Date
    May 2006
    Location
    Leeds, West Yorkshire, UK.
    Posts
    17
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QT4 Plugins - problems, problems

    Afternoon,

    Quote Originally Posted by fullmetalcoder
    That is the hard part indeed. If you need some ideas have a look at the last version of DevQt, it uses a plugin system to customize every aspect of the app.
    Sppokily enough, I set a compilation of DevQt running this very morning - just to see what it is/does. I shall have to have a quick look now. Thanks for the pointer though.

    Cheers,
    Norman.

Similar Threads

  1. Qt Plugins Error
    By nathanpackard in forum Qt Programming
    Replies: 1
    Last Post: 17th August 2007, 23:19
  2. Qt4 Plugins How-to
    By Chaid in forum Qt Programming
    Replies: 4
    Last Post: 8th July 2006, 08:32

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.