Results 1 to 20 of 25

Thread: How to create a plugin

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: How to create a plugin

    This is weird. I don't see the problem. QMake should find it automatically.

  2. #2
    Join Date
    Jun 2010
    Posts
    142
    Thanks
    11
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to create a plugin

    Qt Code:
    1. $ ls
    2. Makefile myplugin.cpp myplugin.h myplugin.pro
    3. $ cat myplugin.pro
    4. ######################################################################
    5. # Automatically generated by qmake (2.01a) Fri Aug 27 08:29:32 2010
    6. ######################################################################
    7.  
    8. QT += gui
    9. TEMPLATE = lib
    10. CONFIG = plugin
    11. TARGET = $$qtLibraryTarget(myplugin)
    12. DEPENDPATH += .
    13. INCLUDEPATH += .
    14.  
    15. # Input
    16. HEADERS += myplugin.h
    17. SOURCES += myplugin.cpp
    18. $ qmake
    19. $ make
    20. g++ -c -m64 -pipe -march=x86-64 -mtune=generic -O2 -pipe -fPIC -I/usr/share/qt/mkspecs/linux-g++-64 -I. -I. -o myplugin.o myplugin.cpp
    21. In file included from myplugin.cpp:1:0:
    22. myplugin.h:1:17: fatal error: QtGui: No such file or directory
    23. compilation terminated.
    24. make: *** [myplugin.o] Error 1
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: How to create a plugin

    As you can see in the following line:

    Qt Code:
    1. g++ -c -m64 -pipe -march=x86-64 -mtune=generic -O2 -pipe -fPIC -I/usr/share/qt/mkspecs/linux-g++-64 -I. -I. -o myplugin.o myplugin.cpp
    To copy to clipboard, switch view to plain text mode 

    The following include paths are at least missing:

    Qt Code:
    1. -I/usr/include/.../QtCore -I/usr/include/.../QtGui
    To copy to clipboard, switch view to plain text mode 
    These are pseudo paths, I don't know where they are on your system.

    This is mighty strange as, like I said, when QT += gui and QT += core (which are default, you don't generally have to add those manually to the .pro file) are added to your .pro file, the include paths should be set by qmake.

    One thing I can think of is to manually delete the Makefile, and try qmake and make again. But I guess this won't solve it either.

    Edit: try this too:

    Qt Code:
    1. CONFIG += plugin
    To copy to clipboard, switch view to plain text mode 
    Note the +
    When you do not add the +, you erase all the configs

  4. #4
    Join Date
    Jun 2010
    Posts
    142
    Thanks
    11
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to create a plugin

    Another error:

    $ make
    /usr/bin/qmake -unix -o Makefile myplugin.pro
    g++ -c -m64 -pipe -march=x86-64 -mtune=generic -O2 -pipe -Wall -W -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_PLUGIN -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt/mkspecs/linux-g++-64 -I. -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include -I. -I. -o myplugin.o myplugin.cpp
    myplugin.cpp: In function ‘QObject* qt_plugin_instance()’:
    myplugin.cpp:18:1: error: cannot allocate an object of abstract type ‘MyPlugin’
    myplugin.h:6:1: note: because the following virtual functions are pure within ‘MyPlugin’:
    /home/michael/junk/QPanel/qpanelappletinterface.h:13:18: note: virtual void QPanelAppletInterface::showSettingsDialog()
    make: *** [myplugin.o] Error 1
    The interface:

    Qt Code:
    1. #ifndef QPANELAPPLETINTERFACE_H
    2. #define QPANELAPPLETINTERFACE_H
    3.  
    4. #include <QtPlugin>
    5.  
    6. class QPanelAppletInterface
    7. {
    8. public:
    9. virtual ~QPanelAppletInterface() {}
    10.  
    11. virtual QWidget *getWidget() = 0;
    12.  
    13. virtual void showSettingsDialog() = 0;
    14. };
    15.  
    16. Q_DECLARE_INTERFACE(QPanelAppletInterface, "com.trolltech.PlugAndPaint.QPanelAppletInterface/1.0")
    17.  
    18. #endif // QPANELAPPLETINTERFACE_H
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: How to create a plugin

    Yes, you need to add the void showSettingsDialog() function to MyPlugin

  6. #6
    Join Date
    Jun 2010
    Posts
    142
    Thanks
    11
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to create a plugin

    My main application now "unexpectedly finishes" if I uncomment the commented out line:

    Qt Code:
    1. dirIter.next();
    2. QPluginLoader loader(dirIter.filePath());
    3. QPanelAppletInterface *plugin = qobject_cast<QPanelAppletInterface*>(loader.instance());
    4. //ui->appletLayout->addWidget(plugin->getWidget());
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: How to create a plugin

    Most probably, plugin is 0 resulting in the crash.

    To prevent the crash, but not solve it do this:
    Qt Code:
    1. if (plugin)
    2. ui->appletLayout->addWidget(plugin->getWidget());
    To copy to clipboard, switch view to plain text mode 

    Now, to solve the plugin problem.
    1. check if loader does point to the correct file. This means that dirIter.filePath() should be the same as "/home/you/where/the/plugin/is/myplugin.so"
    2. Check if the cast can actually be performed. Therefor, the instance returned by the plugin loader needs to be correct at least.

  8. #8
    Join Date
    Jun 2010
    Posts
    142
    Thanks
    11
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to create a plugin

    It finally works!!!

    The problem is that it was trying to load the files "." and "..".

  9. #9
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: How to create a plugin

    Nice, well done.

Similar Threads

  1. Replies: 7
    Last Post: 11th April 2013, 10:55
  2. Plugin and shared class between plugin and application
    By wishper in forum Qt Programming
    Replies: 7
    Last Post: 23rd August 2010, 17:00
  3. Create plugin in Visual Studio
    By estel in forum Installation and Deployment
    Replies: 2
    Last Post: 9th March 2010, 23:40
  4. Replies: 4
    Last Post: 1st May 2009, 11:00
  5. Replies: 7
    Last Post: 23rd August 2007, 12:33

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
  •  
Qt is a trademark of The Qt Company.