Results 1 to 9 of 9

Thread: Plugin-signals-slots problem

  1. #1
    Join Date
    Jun 2008
    Posts
    33
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Plugin-signals-slots problem

    Hi all

    I have application which load all plugins in directory plugins and show thier menus. I do this in class plugins:

    Qt Code:
    1. bool Plugins::loadPlugins()
    2. {
    3. QDir dir("./plugins");
    4. if (!dir.exists())
    5. return false;
    6.  
    7. foreach (QString filename, dir.entryList(QDir::Files))
    8. {
    9. loader->setFileName(dir.absoluteFilePath(filename));
    10. QObject *couldBeFilter = loader->instance();
    11. if (couldBeFilter)
    12. {
    13. PluginInterface *plugin = qobject_cast<PluginInterface*>(couldBeFilter);
    14. if (plugin)
    15. {
    16. plugins.insert(plugin->name(), plugin);
    17. connect(plugin->menu(), SIGNAL(writeData(QByteArray)), this, SIGNAL(dataOut(QByteArray)));
    18. }
    19. }
    20. }
    21.  
    22. return true;
    23. }
    To copy to clipboard, switch view to plain text mode 

    Then I have class PluginInterface:

    Qt Code:
    1. class PluginInterface
    2. {
    3.  
    4. public:
    5. virtual QString name() const = 0;
    6. virtual Menu* menu() const = 0;
    7. };
    8.  
    9. Q_DECLARE_INTERFACE(PluginInterface, "sk.kimle.PluginInterface/0.1")
    To copy to clipboard, switch view to plain text mode 

    And now I am writing plugin. First I inherit from this interface this class:

    Qt Code:
    1. class ProgramViewer : public QObject, PluginInterface
    2. {
    3. Q_OBJECT
    4. Q_INTERFACES(PluginInterface)
    5.  
    6. public:
    7. ProgramViewer();
    8. virtual ~ProgramViewer();
    9. virtual QString name() const;
    10. virtual Menu* menu() const;
    11. private:
    12. QString pluginName;
    13. };
    To copy to clipboard, switch view to plain text mode 

    Function menu() return Menu object. It inherits from QWidget and have only virtual functions and slots:

    Qt Code:
    1. class Menu : public QWidget
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. Menu(){}
    7. ~Menu(){}
    8. virtual void showWindow() const = 0;
    9. virtual void makeConnections() = 0;
    10. public slots:
    11. virtual void readData(QByteArray array) =0;
    12. signals:
    13. virtual void writeData(QByteArray array);
    14. };
    To copy to clipboard, switch view to plain text mode 

    I have also class which inherits from Menu and this class has other widgets and functions.

    Qt Code:
    1. class ProgramViewerMenu : public Menu
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. enum DataToSend
    7. {
    8. NewImage = 1,
    9. Pixels,
    10. Stop
    11. };
    12. ProgramViewerMenu();
    13. ~ProgramViewerMenu();
    14. void showWindow() const;
    15. void makeConnections();
    16. bool startBroadcasting();
    17. bool stopBroadcasting();
    18. QByteArray* takeShot(WId id);
    19. QByteArray* changePixels(QImage oldOne, QImage newOne);
    20. public slots:
    21. void readData(QByteArray array);
    22. void broadcasting();
    23. void capture();
    24. void refreshList();
    25. signals:
    26. void writeData(QByteArray array);
    27. private:
    28. QLabel *title;
    29. QPushButton *broadcast;
    30. QPushButton *refresh;
    31. QGridLayout *grid;
    32. QListWidget *list;
    33. QTimer *timerRefresh;
    34. QTimer *timerBroadcast;
    35. QImage screen;
    36. WId id;
    37. bool isBroadcasting;
    38. };
    To copy to clipboard, switch view to plain text mode 

    In some functions of this class I want to emit writeData(QByteArray) signal which is connected in the first class. But I ve got this error:
    In function `ZN17ProgramViewerMenu11qt_metacallEN11QMetaObject 4CallEiPPv':
    In function `ZN17ProgramViewerMenu11qt_metacastEPKc':
    undefined reference to `Menu::qt_metacall(QMetaObject::Call, int, void**)'
    undefined reference to `Menu::qt_metacast(char const*)'

    I do not know whats wrong. I am not sure about those virtual functions, signals and slots and also I do not know if it is possible to connect something to plugin. Can anybody solve this? Thanks.

    Sorry about my english.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Plugin-signals-slots problem

    Try re-running qmake.
    J-P Nurmi

  3. #3
    Join Date
    Jun 2008
    Posts
    33
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Plugin-signals-slots problem

    I ve done this many times becouse I ve been trying to change virtual functions, signals, slots etc.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Plugin-signals-slots problem

    Is menu.h listed in the .pro file?
    J-P Nurmi

  5. #5
    Join Date
    Jun 2008
    Posts
    33
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Plugin-signals-slots problem

    No it wasnt but I added it but nothing chenged.

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Plugin-signals-slots problem

    Now re-run qmake once again.
    J-P Nurmi

  7. #7
    Join Date
    Jun 2008
    Posts
    33
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Plugin-signals-slots problem

    Thanks it works, but I dont know why

    But I have another problem. I cant load plugin in Plugins class with function loadPlugins().
    It found file and get filepath but it cant create QObject instance and I dont know why.

  8. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Plugin-signals-slots problem

    Quote Originally Posted by Misenko View Post
    Thanks it works, but I dont know why
    Headers containing the Q_OBJECT macro must be listed in the .pro file because qmake must create rules for running MOC on them.

    But I have another problem. I cant load plugin in Plugins class with function loadPlugins().
    It found file and get filepath but it cant create QObject instance and I dont know why.
    Have you checked QPluginLoader::errorString()?
    J-P Nurmi

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

    Misenko (23rd September 2008)

  10. #9
    Join Date
    Jun 2008
    Posts
    33
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Plugin-signals-slots problem

    Thank you man. I didnt know about this errorString function
    Ok problem solved. Plugin appears correctly.

Similar Threads

  1. Problem with SpinBox signals and slots
    By ramstormrage in forum Newbie
    Replies: 4
    Last Post: 2nd May 2008, 01:45
  2. Signals And Slots problem
    By ldiamond in forum Newbie
    Replies: 7
    Last Post: 23rd March 2008, 00:11
  3. Plugin interfaces, signals and slots
    By QPlace in forum Qt Programming
    Replies: 8
    Last Post: 9th August 2007, 21:19
  4. Memory Problem with SIGNALS and SLOTS
    By ^NyAw^ in forum Qt Programming
    Replies: 1
    Last Post: 19th March 2007, 20:39
  5. Problem with Signals and Slots
    By Kapil in forum Newbie
    Replies: 11
    Last Post: 15th February 2006, 11:35

Tags for this Thread

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.