Results 1 to 5 of 5

Thread: Load form mdi child plugin

  1. #1
    Join Date
    Jan 2008
    Location
    Brasil
    Posts
    131
    Thanks
    18
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Load form mdi child plugin

    Hi guys,

    I'm creating a plugin that contains a form. How can I load this plugin as a child window in an application mdi?

    Thanks,

    Marcelo E. Geyer

  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: Load form mdi child plugin

    What did you try so far? How does the plugin create the widget?
    Qt Code:
    1. class PluginInterface
    2. {
    3. public:
    4. ...
    5. QWidget* createForm(QWidget* parent = 0) = 0;
    6. ...
    7. };
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

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

    estanisgeyer (11th February 2008)

  4. #3
    Join Date
    Jan 2008
    Location
    Brasil
    Posts
    131
    Thanks
    18
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Load form mdi child plugin

    I have no idea how this implementation. I will post here in the code. Anyway, I will try to take the hint and make us their tests here.

    RecInterface.h:
    Qt Code:
    1. #ifndef RECINTERFACE_H
    2. #define RECINTERFACE_H
    3.  
    4. #include <QtPlugin>
    5. #include <QWidget>
    6.  
    7. class ReceberInterface: public QWidget
    8. {
    9. public:
    10. virtual ~RecInterface() {}
    11. virtual QString getIcon() const = 0;
    12. virtual QString typeInterface() const = 0;
    13. virtual QString statustipInterface() const = 0;
    14. virtual QString menuInterface() const = 0;
    15.  
    16. private:
    17. };
    18.  
    19. Q_DECLARE_INTERFACE(RecInterface, "snet.RecInterface/1.0")
    20.  
    21. #endif
    To copy to clipboard, switch view to plain text mode 

    Rec.h:
    Qt Code:
    1. #ifndef REC_H
    2. #define REC_H
    3.  
    4. #include <QtGui>
    5. #include "ui_Rec.h"
    6. #include "RecInterface.h"
    7.  
    8. class Rec: public RecInterface
    9. {
    10. Q_OBJECT
    11. Q_INTERFACES(RecInterface)
    12.  
    13. public:
    14. Rec();
    15. virtual ~Rec();
    16.  
    17. QString getIcon() const;
    18. QString typeInterface() const;
    19. QString statustipInterface() const;
    20. QString menuInterface() const;
    21.  
    22. private:
    23. Ui::Form_Rec ui;
    24.  
    25. protected:
    26.  
    27. };
    28.  
    29. #endif
    To copy to clipboard, switch view to plain text mode 

    Rec.cpp:
    Qt Code:
    1. #include "Rec.h"
    2.  
    3. Rec::Rec()
    4. {
    5. qDebug() << "Rec is load...";
    6. }
    7.  
    8. Rec::~Rec()
    9. {
    10.  
    11. }
    12.  
    13. QString Rec::getIcon() const
    14. {
    15. QString icon = ":/imagens/contas_rec.png";
    16. return icon;
    17. }
    18.  
    19. QString Rec::typeInterface() const
    20. {
    21. QString tipo = "Account Rec...";
    22. return tipo;
    23. }
    24.  
    25. QString Rec::statustipInterface() const
    26. {
    27. QString statustip = "Account Rec...";
    28. return statustip;
    29. }
    30.  
    31. QString Rec::menuInterface() const
    32. {
    33. QString menu = "&Account";
    34. return menu;
    35. }
    36.  
    37. Q_EXPORT_PLUGIN2(librec, Rec)
    To copy to clipboard, switch view to plain text mode 

    Thanks,

    Marcelo E. Geyer

  5. #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: Load form mdi child plugin

    First of all, the plugin interface must be a class with pure virtual functions only, thus you cannot make it inherit QWidget. Secondly, you should write a function which creates and returns a widget. This way you can control the life time of the widget properly.

    For more details, see How to Create Qt Plugins - The Lower-Level API: Extending Qt Applications.
    J-P Nurmi

  6. #5
    Join Date
    Jan 2008
    Location
    Brasil
    Posts
    131
    Thanks
    18
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Talking Re: Load form mdi child plugin

    Thanks for hints!
    I'm resolved the problem, follow below the code:

    MainWindow.cpp:

    Qt Code:
    1. void MainWindow::slotShowPlugin()
    2. {
    3. QAction *act = qobject_cast<QAction *>(sender());
    4. RecInterface *interface = qobject_cast<RecInterface *>(act->parent());
    5.  
    6. QMdiSubWindow *mdiSubWin = new QMdiSubWindow;
    7. mdiSubWin->setWidget(interface->createWidget());
    8. mdiSubWin->setAttribute(Qt::WA_DeleteOnClose);
    9. mdiArea->addSubWindow(mdiSubWin);
    10. mdiSubWin->show();
    11. }
    To copy to clipboard, switch view to plain text mode 

    RecInterface.h
    Qt Code:
    1. #include <QtPlugin>
    2. #include <QWidget>
    3.  
    4. class RecInterface
    5. {
    6. public:
    7. virtual QWidget *createWidget(QWidget *parent = 0) = 0;
    8. virtual ~RecInterface() {};
    9. virtual QString getIcon() const = 0;
    10. virtual QString tipoInterface() const = 0;
    11. virtual QString statustipInterface() const = 0;
    12. virtual QString menuInterface() const = 0;
    13.  
    14. private:
    15. };
    16.  
    17. Q_DECLARE_INTERFACE(RecInterface, "snet.RecInterface/1.0")
    18.  
    19. #endif
    To copy to clipboard, switch view to plain text mode 

    Rec.h:
    Qt Code:
    1. #include <QWidget>
    2. #include <QtDebug>
    3. #include "ui_Rec.h"
    4. #include "RecInterface.h"
    5.  
    6. class RecWidget;
    7. class Rec: public QWidget, public RecInterface
    8. {
    9. Q_OBJECT
    10. Q_INTERFACES(RecInterface)
    11.  
    12. public:
    13. Rec(QWidget *parent = 0);
    14. virtual ~Rec();
    15. QWidget *createWidget(QWidget *parent = 0);
    16. QString getIcon() const;
    17. QString tipoInterface() const;
    18. QString statustipInterface() const;
    19. QString menuInterface() const;
    20.  
    21. RecWidget *recWid;
    22.  
    23. private:
    24.  
    25. protected:
    26.  
    27. };
    28.  
    29. class RecWidget: public QWidget
    30. {
    31. Q_OBJECT
    32. public:
    33. RecWidget(QWidget *parent = 0);
    34. virtual ~RecWidget();
    35.  
    36. private:
    37. Ui::Form_Rec ui;
    38.  
    39. protected:
    40.  
    41. };
    42.  
    43. #endif
    To copy to clipboard, switch view to plain text mode 

    Rec.cpp:
    Qt Code:
    1. #include "Rec.h"
    2.  
    3. Rec::Rec(QWidget *parent)
    4. :QWidget(parent)
    5. {
    6. qDebug() << "Loading rec...";
    7. }
    8.  
    9. Rec::~Rec()
    10. {
    11.  
    12. }
    13.  
    14. QString Rec::getIcon() const
    15. {
    16. QString icon = ":/imagens/nf.png";
    17. return icon;
    18. }
    19. QString Rec::tipoInterface() const
    20. {
    21. QString tipo = "Plugin Rec...";
    22. return tipo;
    23. }
    24.  
    25. QString Rec::statustipInterface() const
    26. {
    27. QString statustip = "Account Rec...";
    28. return statustip;
    29. }
    30.  
    31. QString Rec::menuInterface() const
    32. {
    33. QString menu = "&Account";
    34. return menu;
    35. }
    36.  
    37. QWidget *Rec::createWidget(QWidget *parent)
    38. {
    39. recWid = new RecWidget(this);
    40. return recWid;
    41. }
    42.  
    43. Q_EXPORT_PLUGIN2(librec, Rec)
    44.  
    45.  
    46. RecWidget::RecWidget(QWidget *parent)
    47. :QWidget(parent)
    48. {
    49. qDebug() << "Loading form...";
    50. ui.setupUi(this);
    51. }
    52.  
    53. RecWidget::~RecWidget()
    54. {
    55.  
    56. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. MDI child form icon
    By tebessum in forum Qt Programming
    Replies: 1
    Last Post: 2nd January 2008, 09:33
  2. QPluginLoader not recognizing a plugin
    By KShots in forum Qt Programming
    Replies: 3
    Last Post: 29th June 2007, 14:13
  3. Replies: 1
    Last Post: 28th July 2006, 14:10

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.