Results 1 to 11 of 11

Thread: [SOLVED] Widget plugin ... how to ?

  1. #1
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default [SOLVED] Widget plugin ... how to ?

    Hi,

    Here I am once again.

    I'm trying to developp my own custom widget. I did it well the old fashion way but when I try to do it as a plugin it fails at compilation, invoking a problem with my Constructor, I don't know why so I hopre someone could help me.

    The widget I'm trying to developp is a FileChooser from Qt Tutorial.

    The compilation error message is the following :
    Qt Code:
    1. error C2533 CustomWidgetPlugin::CustomWidgetPlugin : constructor not allowed a return type
    To copy to clipboard, switch view to plain text mode 

    ... I'm pretty sure that it does not return any value, so why does the compilation failed ?

    Here is my code for the .h
    Qt Code:
    1. #include <qwidgetplugin.h>
    2.  
    3. class CustomWidgetPlugin : public QWidgetPlugin
    4. {
    5. public:
    6. CustomWidgetPlugin();
    7.  
    8. QStringList keys() const;
    9. QWidget* create(const QString& classname, QWidget* parent=0, const char* name=0);
    10. QString group(const QString&) const;
    11. QIconSet iconSet(const QString&) const;
    12. QString includeFile(const QString&) const;
    13. QString toolTip(const QString&) const;
    14. QString whatsThis(const QString&) const;
    15. bool isContainer(const QString&) const;
    16. }
    To copy to clipboard, switch view to plain text mode 

    the code for the .cpp
    Qt Code:
    1. #include "CustomWidgetPlugin.h"
    2.  
    3. CustomWidgetPlugin::CustomWidgetPlugin()
    4. {
    5.  
    6. }
    7.  
    8. QStringList CustomWidgetPlugin::keys() const
    9. {
    10. list << "FileChooser";
    11. return list;
    12. }
    13.  
    14. QWidget* CustomWidgetPlugin::create(const QString& key, QWidget* parent, const char* name) const
    15. {
    16. if( key == "FileChooser" )
    17. return new FileChooser(parent, name);
    18. return 0;
    19. }
    20.  
    21. QString CustomWidgetPlugin::includeFile(const QString& feature) const
    22. {
    23. if( feature == "FileChooser" )
    24. return "filechooser.h";
    25. return QString::null;
    26. }
    27.  
    28. QString CustomWidgetPlugin::group(const QString& feature) const
    29. {
    30. if( feature == "FileChooser" )
    31. return "Input";
    32. return QString::null;
    33. }
    34.  
    35. QIconSet CustomWidgetPlugin::iconSet(const QString& feature) const
    36. {
    37. return QIconSet( QPixmap("filechooser_pixmap.png"));
    38. }
    39.  
    40. QString CustomWidgetPlugin::toolTip(const QString& feature) const
    41. {
    42. if( feature == "FileChooser" )
    43. return "File Chooser Widget";
    44. return QString::null;
    45. }
    46.  
    47. QString CustomWidgetPlugin::whatsThis(const QString& feature) const
    48. {
    49. if( feature == "FileChooser" )
    50. return "A widget to choose a file";
    51. return QString::null;
    52. }
    53.  
    54. bool CustomWidgetPlugin::isContainer(const QString& feature) const
    55. {
    56. return FALSE;
    57. }
    58.  
    59. Q_EXPORT_PLUGIN( CustomWidgetPlugin )
    To copy to clipboard, switch view to plain text mode 

    and my .pro
    Qt Code:
    1. SOURCES += CustomWidgetPlugin.cpp ../FileChooser/filechooser.cpp
    2. HEADERS += CustomWidgetPlugin.h ../FileChooser/filechooser.h
    3. DESTDIR = $(QTDIR)/plugins/designer
    4. TARGET = filechooser
    5.  
    6. target.path=$$plugins.path
    7. isEmpty(target.path):target.path==$$QT_PREFIX/plugins
    8. INSTALLS += target
    9. TEMPLATE = lib
    10. CONFIG += qt warn_on release plugin
    11. INCLUDEPATH += $(QTDIR)/tools/designer/interfaces
    12. DBFILE = CustomWidgetPlugin.db
    13. PROJECTNAME = CustomWidgetPlugin
    14. LANGUAGE = C++
    To copy to clipboard, switch view to plain text mode 

    Thanks in advance for your help.

  2. #2
    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: Widget plugin ... how to ?

    I don't know if it is connected to the error you mention, but in the constructor the base class constructor should be called.

  3. #3
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: Widget plugin ... how to ?

    So, I changed my constructor implementation as follow:
    Qt Code:
    1. CustomWidgetPlugin::CustomWidgetPlugin()
    2. :QWidgetPlugin()
    3. {
    4. }
    To copy to clipboard, switch view to plain text mode 

    ... but I still have the same problems, it does not compile.

    It may be due to the way I'm trying to compile my sources, here is the method :
    * I go in the folder where the sources are and type the two following commands :
    qmake -o Makefile CustomWidgetPlugin.pro
    nmake

    Pfff, sometimes, developping getting on my nerves

  4. #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: Widget plugin ... how to ?

    Try adding a semicolon after the closing brace of your class definition.

  5. #5
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: Widget plugin ... how to ?

    Even if I had a semicolon it still does not compile and I have the same error messages.

    I don't understand why it crashes, crual world.

    The situation is locked for the moment. The custom widget FileChooser works, I am sure of this because I use it in an application. But how impossible it seems to be to integrate it in a plugin.

    I hope someone will find out what's wrong with my code.

  6. #6
    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: Widget plugin ... how to ?

    Try this way:
    Qt Code:
    1. class QT_WIDGET_PLUGIN_EXPORT CustomWidgetPlugin : public QWidgetPlugin
    2. {
    3. // ...
    4. };
    To copy to clipboard, switch view to plain text mode 
    What is the first error you get?

  7. #7
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: Widget plugin ... how to ?

    So here is the code of my custom widget plugin
    ... the .h
    Qt Code:
    1. #include <qwidgetplugin.h>
    2.  
    3. class QT_WIDGET_PLUGIN_EXPORT CustomWidgetPlugin : public QWidgetPlugin
    4. {
    5. public:
    6. CustomWidgetPlugin();
    7.  
    8. QStringList keys() const;
    9. QWidget* create(const QString& classname, QWidget* parent=0, const char* name=0);
    10. QString group(const QString&) const;
    11. QIconSet iconSet(const QString&) const;
    12. QString includeFile(const QString&) const;
    13. QString toolTip(const QString&) const;
    14. QString whatsThis(const QString&) const;
    15. bool isContainer(const QString&) const;
    16. }
    To copy to clipboard, switch view to plain text mode 

    ... and the .cpp
    Qt Code:
    1. #include "CustomWidgetPlugin.h"
    2.  
    3. CustomWidgetPlugin::CustomWidgetPlugin()
    4. :QWidgetPlugin()
    5. {
    6.  
    7. }
    8.  
    9. QStringList CustomWidgetPlugin::keys() const
    10. {
    11. list << "FileChooser";
    12. return list;
    13. }
    14.  
    15. QWidget* CustomWidgetPlugin::create(const QString& key, QWidget* parent, const char* name) const
    16. {
    17. if( key == "FileChooser" )
    18. return new FileChooser(parent, name);
    19. return null ;
    20. }
    21.  
    22. QString CustomWidgetPlugin::includeFile(const QString& feature) const
    23. {
    24. if( feature == "FileChooser" )
    25. return "filechooser.h";
    26. return QString::null;
    27. }
    28.  
    29. QString CustomWidgetPlugin::group(const QString& feature) const
    30. {
    31. if( feature == "FileChooser" )
    32. return "Input";
    33. return QString::null;
    34. }
    35.  
    36. QIconSet CustomWidgetPlugin::iconSet(const QString& feature) const
    37. {
    38. return QIconSet( QPixmap("filechooser_pixmap.png"));
    39. }
    40.  
    41. QString CustomWidgetPlugin::toolTip(const QString& feature) const
    42. {
    43. if( feature == "FileChooser" )
    44. return "File Chooser Widget";
    45. return QString::null;
    46. }
    47.  
    48. QString CustomWidgetPlugin::whatsThis(const QString& feature) const
    49. {
    50. if( feature == "FileChooser" )
    51. return "A widget to choose a file";
    52. return QString::null;
    53. }
    54.  
    55. bool CustomWidgetPlugin::isContainer(const QString& feature) const
    56. {
    57. return FALSE;
    58. }
    59.  
    60. Q_EXPORT_PLUGIN( CustomWidgetPlugin )
    To copy to clipboard, switch view to plain text mode 

    and my .pro
    Qt Code:
    1. ######################################################################
    2. # Automatically generated by qmake (1.07a) dim. 29. janv. 10:37:16 2006
    3. ######################################################################
    4.  
    5. SOURCES += CustomWidgetPlugin.cpp ../FileChooser/FileChooser.cpp
    6. HEADERS += CustomWidgetPlugin.h ../FileChooser/FileChooser.h
    7. DESTDIR = $(QTDIR)/plugins/designer
    8. TARGET = filechooser
    9.  
    10. target.path = $$plugins.path
    11. isEmpty(target.path):target.path==$$QT_PREFIX/plugins
    12. INSTALLS += target
    13. TEMPLATE = lib
    14. CONFIG += qt warn_on release plugin
    15. INCLUDEPATH += $(QTDIR)/tools/designer/interfaces
    16. DBFILE = plugin.db
    17. PROJECTNAME = Plugin
    18. LANGUAGE = C++
    To copy to clipboard, switch view to plain text mode 

    So, I go to the folder where are those files I type in console mode the two following commands :
    Qt Code:
    1. qmake -o Makefile CustomWidgetPlugin.pro
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. nmake
    To copy to clipboard, switch view to plain text mode 

    Then the console displays me the following errors :
    Qt Code:
    1. .\CustomWidgetPlugin.cpp(4) : error C2533 : 'CustomWidgetPlugin::CustomWidgetPlugin' : constructors not allowed a retrun type
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. .\CustomWidgetPlugin.cpp(17) : error C2511 : 'create' : overloaded member function 'class QWidget*(const class QString&, class Widget*, const char*) const not found in CustomWidgetPlugin ./CustomWidgetPlugin.h(3) : see declaration of CustomWidgetPlugin
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. .\CustomWidgetPlugin.cpp(61) : error C2264 : 'CustomWidgetPlugin::CustomWidgetPlugin' : error in function definiton or declaration; function not called
    To copy to clipboard, switch view to plain text mode 

    That 's all information I can give you.

    I hope you will be able to help me.

    Thanks in advance.

  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: Widget plugin ... how to ?

    Try adding #include <qwidget.h> to the header file. And a semicolon after class declaration. And Q_EXPORT_PLUGIN( ) macro.
    Last edited by wysota; 29th January 2006 at 11:39.

  9. #9
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: Widget plugin ... how to ?

    Ok, that's what I did.

    I alse add the following line in my plugin header
    Qt Code:
    1. #include ".\\..\\FileChooser\\FileChooser.h"
    To copy to clipboard, switch view to plain text mode 

    I still have some errors, but different this time. Here they are :
    Qt Code:
    1. .\CustomWidgetPlugin.cpp(62) : error C2259: 'CustomWidgetPlugin' : cannot instantiate abstract class due to following members : /.CustomWidgetPlugin.h(4) : see declaration of 'CustomWidgetPlugin'
    To copy to clipboard, switch view to plain text mode 

    The line 62 in this file points to the following :
    Qt Code:
    1. Q_EXPORT_PLUGIN( CustomWidgetPlugin );
    To copy to clipboard, switch view to plain text mode 

  10. #10
    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: Widget plugin ... how to ?

    Remove "const" after CustomWidgetPlugin::create() in .cpp file.

  11. #11
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default [SOLVE] Re: Widget plugin ... how to ?

    Thanks Jacek because you lead me to the victory with your final advise.

    I also thanks all other contributors without who I would not be able to realize my first plugin

    Just in case if someone else try to make its own widget as a plugin, I write the full code :

    FileChooser.h
    Qt Code:
    1. // FileChooser.h: interface for the CFileChooser class.
    2. //
    3. //////////////////////////////////////////////////////////////////////
    4.  
    5. #if !defined(AFX_FILECHOOSER_H__59B1F80E_2AB6_4FAD_BA4D_DEAA892068B8__INCLUDED_)
    6. #define AFX_FILECHOOSER_H__59B1F80E_2AB6_4FAD_BA4D_DEAA892068B8__INCLUDED_
    7.  
    8. #if _MSC_VER > 1000
    9. #pragma once
    10. #endif // _MSC_VER > 1000
    11.  
    12. #include <qwidget.h>
    13.  
    14. class QLineEdit;
    15.  
    16. class CFileChooser : public QWidget
    17. {
    18. Q_OBJECT
    19. Q_PROPERTY( QString fileName READ fileName WRITE setFileName)
    20. // Constructor / Destructor
    21. public:
    22. CFileChooser(QWidget* parent=0, const char* name=0);
    23. virtual ~CFileChooser();
    24.  
    25. // Slots
    26. public slots:
    27. void setFileName( const QString& fn );
    28.  
    29. private slots:
    30. void chooseFile();
    31.  
    32. // Signals
    33. signals:
    34. void fileNameChanged( const QString& fn );
    35.  
    36. // Functions
    37. public:
    38. QString fileName() const;
    39.  
    40. // Members
    41. private:
    42. QLineEdit* lineEdit;
    43. QPushButton* button;
    44. };
    45.  
    46. #endif // !defined(AFX_FILECHOOSER_H__59B1F80E_2AB6_4FAD_BA4D_DEAA892068B8__INCLUDED_)
    To copy to clipboard, switch view to plain text mode 

    FileChooser.cpp
    Qt Code:
    1. // FileChooser.cpp: implementation of the CFileChooser class.
    2. //
    3. //////////////////////////////////////////////////////////////////////
    4.  
    5. #include "FileChooser.h"
    6. #include <qlayout.h>
    7. #include <qlineedit.h>
    8. #include <qpushbutton.h>
    9. #include <qfiledialog.h>
    10.  
    11. //////////////////////////////////////////////////////////////////////
    12. // Construction/Destruction
    13. //////////////////////////////////////////////////////////////////////
    14.  
    15. CFileChooser::CFileChooser(QWidget* parent, const char* name)
    16. :QWidget(parent, name)
    17. {
    18. QHBoxLayout* layout = new QHBoxLayout(this);
    19. layout->setMargin(0);
    20.  
    21. lineEdit = new QLineEdit(this, "filechooser_lineedit");
    22. layout->addWidget(lineEdit);
    23.  
    24. connect(lineEdit, SIGNAL(textChanged(const QString&)), this, SIGNAL(fileNameChanged(const QString&)));
    25.  
    26. button = new QPushButton("...", this, "filechooser_button");
    27. button->setFixedWidth(button->fontMetrics().width("..."));
    28. layout->addWidget(button);
    29.  
    30. connect(button, SIGNAL(clicked()), this, SLOT(chooseFile()));
    31.  
    32. setFocusProxy(lineEdit);
    33. }
    34.  
    35.  
    36.  
    37. CFileChooser::~CFileChooser()
    38. {
    39.  
    40. }
    41.  
    42.  
    43.  
    44. void CFileChooser::setFileName(const QString& fn)
    45. {
    46. lineEdit->setText(fn);
    47. }
    48.  
    49.  
    50.  
    51. QString CFileChooser::fileName() const
    52. {
    53. return lineEdit->text();
    54. }
    55.  
    56.  
    57.  
    58. void CFileChooser::chooseFile()
    59. {
    60. QString fn;
    61. fn = QFileDialog::getOpenFileName(lineEdit->text(), QString::null, this);
    62.  
    63. if( !fn.isEmpty() )
    64. {
    65. lineEdit->setText(fn);
    66. emit fileNameChanged(fn);
    67. }
    68. }
    To copy to clipboard, switch view to plain text mode 

    Plugin.h
    Qt Code:
    1. #include <qwidgetplugin.h>
    2. #include <qwidget.h>
    3.  
    4. class QT_WIDGET_PLUGIN_EXPORT CustomWidgetPlugin : public QWidgetPlugin
    5. {
    6. public:
    7. CustomWidgetPlugin();
    8.  
    9. QStringList keys() const;
    10. QWidget* create(const QString& classname, QWidget* parent=0, const char* name=0);
    11. QString group(const QString&) const;
    12. QIconSet iconSet(const QString&) const;
    13. QString includeFile(const QString&) const;
    14. QString toolTip(const QString&) const;
    15. QString whatsThis(const QString&) const;
    16. bool isContainer(const QString&) const;
    17. };
    To copy to clipboard, switch view to plain text mode 

    Plugin.cpp
    Qt Code:
    1. #include "CustomWidgetPlugin.h"
    2. #include ".\\..\\FileChooser\\FileChooser.h"
    3.  
    4. CustomWidgetPlugin::CustomWidgetPlugin()
    5. :QWidgetPlugin()
    6. {
    7.  
    8. }
    9.  
    10. QStringList CustomWidgetPlugin::keys() const
    11. {
    12. list << "CFileChooser";
    13. return list;
    14. }
    15.  
    16. QWidget* CustomWidgetPlugin::create(const QString& key, QWidget* parent, const char* name)
    17. {
    18. if( key == "CFileChooser" )
    19. return new CFileChooser(parent, name);
    20. return 0;
    21. }
    22.  
    23. QString CustomWidgetPlugin::includeFile(const QString& feature) const
    24. {
    25. if( feature == "CFileChooser" )
    26. return "filechooser.h";
    27. return QString::null;
    28. }
    29.  
    30. QString CustomWidgetPlugin::group(const QString& feature) const
    31. {
    32. if( feature == "CFileChooser" )
    33. return "Input";
    34. return QString::null;
    35. }
    36.  
    37. QIconSet CustomWidgetPlugin::iconSet(const QString& feature) const
    38. {
    39. return QIconSet( QPixmap("filechooser_pixmap.png"));
    40. }
    41.  
    42. QString CustomWidgetPlugin::toolTip(const QString& feature) const
    43. {
    44. if( feature == "CFileChooser" )
    45. return "File Chooser Widget";
    46. return QString::null;
    47. }
    48.  
    49. QString CustomWidgetPlugin::whatsThis(const QString& feature) const
    50. {
    51. if( feature == "CFileChooser" )
    52. return "A widget to choose a file";
    53. return QString::null;
    54. }
    55.  
    56. bool CustomWidgetPlugin::isContainer(const QString& feature) const
    57. {
    58. return FALSE;
    59. }
    60.  
    61. Q_EXPORT_PLUGIN( CustomWidgetPlugin );
    To copy to clipboard, switch view to plain text mode 

    Plugin.pro
    Qt Code:
    1. ######################################################################
    2. # Automatically generated by qmake (1.07a) dim. 29. janv. 10:37:16 2006
    3. ######################################################################
    4.  
    5. SOURCES += CustomWidgetPlugin.cpp ../FileChooser/FileChooser.cpp
    6. HEADERS += CustomWidgetPlugin.h ../FileChooser/FileChooser.h
    7. DESTDIR = $(QTDIR)/plugins/designer
    8. TARGET = filechooser
    9.  
    10. target.path = $$plugins.path
    11. isEmpty(target.path):target.path==$$QT_PREFIX/plugins
    12. INSTALLS += target
    13. TEMPLATE = lib
    14. CONFIG += qt warn_on release plugin
    15. INCLUDEPATH += $(QTDIR)/tools/designer/interfaces
    16. DBFILE = plugin.db
    17. PROJECTNAME = Plugin
    18. LANGUAGE = C++
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Plugin with widget
    By Misenko in forum Qt Programming
    Replies: 1
    Last Post: 29th August 2008, 21:55
  2. Replies: 4
    Last Post: 9th August 2007, 09:20
  3. QPluginLoader not recognizing a plugin
    By KShots in forum Qt Programming
    Replies: 3
    Last Post: 29th June 2007, 15:13
  4. Replies: 7
    Last Post: 3rd February 2006, 11:20
  5. Managing widget plugin in Qt Designer
    By yellowmat in forum Newbie
    Replies: 8
    Last Post: 31st January 2006, 10:58

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.