View Full Version : [SOLVED] Widget plugin ... how to ?
yellowmat
27th January 2006, 23:47
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 :
error C2533 CustomWidgetPlugin::CustomWidgetPlugin : constructor not allowed a return type
... I'm pretty sure that it does not return any value, so why does the compilation failed ?
Here is my code for the .h
#include <qwidgetplugin.h>
class CustomWidgetPlugin : public QWidgetPlugin
{
public:
CustomWidgetPlugin();
QStringList keys() const;
QWidget* create(const QString& classname, QWidget* parent=0, const char* name=0);
QString group(const QString&) const;
QIconSet iconSet(const QString&) const;
QString includeFile(const QString&) const;
QString toolTip(const QString&) const;
QString whatsThis(const QString&) const;
bool isContainer(const QString&) const;
}
the code for the .cpp
#include "CustomWidgetPlugin.h"
CustomWidgetPlugin::CustomWidgetPlugin()
{
}
QStringList CustomWidgetPlugin::keys() const
{
QStringList list;
list << "FileChooser";
return list;
}
QWidget* CustomWidgetPlugin::create(const QString& key, QWidget* parent, const char* name) const
{
if( key == "FileChooser" )
return new FileChooser(parent, name);
return 0;
}
QString CustomWidgetPlugin::includeFile(const QString& feature) const
{
if( feature == "FileChooser" )
return "filechooser.h";
return QString::null;
}
QString CustomWidgetPlugin::group(const QString& feature) const
{
if( feature == "FileChooser" )
return "Input";
return QString::null;
}
QIconSet CustomWidgetPlugin::iconSet(const QString& feature) const
{
return QIconSet( QPixmap("filechooser_pixmap.png"));
}
QString CustomWidgetPlugin::toolTip(const QString& feature) const
{
if( feature == "FileChooser" )
return "File Chooser Widget";
return QString::null;
}
QString CustomWidgetPlugin::whatsThis(const QString& feature) const
{
if( feature == "FileChooser" )
return "A widget to choose a file";
return QString::null;
}
bool CustomWidgetPlugin::isContainer(const QString& feature) const
{
return FALSE;
}
Q_EXPORT_PLUGIN( CustomWidgetPlugin )
and my .pro
SOURCES += CustomWidgetPlugin.cpp ../FileChooser/filechooser.cpp
HEADERS += CustomWidgetPlugin.h ../FileChooser/filechooser.h
DESTDIR = $(QTDIR)/plugins/designer
TARGET = filechooser
target.path=$$plugins.path
isEmpty(target.path):target.path==$$QT_PREFIX/plugins
INSTALLS += target
TEMPLATE = lib
CONFIG += qt warn_on release plugin
INCLUDEPATH += $(QTDIR)/tools/designer/interfaces
DBFILE = CustomWidgetPlugin.db
PROJECTNAME = CustomWidgetPlugin
LANGUAGE = C++
Thanks in advance for your help.
wysota
28th January 2006, 01:37
I don't know if it is connected to the error you mention, but in the constructor the base class constructor should be called.
yellowmat
28th January 2006, 18:09
So, I changed my constructor implementation as follow:
CustomWidgetPlugin::CustomWidgetPlugin()
:QWidgetPlugin()
{
}
... but I still have the same problems, it does not compile. :confused:
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 :mad:
jacek
28th January 2006, 18:15
Try adding a semicolon after the closing brace of your class definition.
yellowmat
29th January 2006, 01:12
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.
jacek
29th January 2006, 01:19
Try this way:
class QT_WIDGET_PLUGIN_EXPORT CustomWidgetPlugin : public QWidgetPlugin
{
// ...
};What is the first error you get?
yellowmat
29th January 2006, 10:53
So here is the code of my custom widget plugin
... the .h
#include <qwidgetplugin.h>
class QT_WIDGET_PLUGIN_EXPORT CustomWidgetPlugin : public QWidgetPlugin
{
public:
CustomWidgetPlugin();
QStringList keys() const;
QWidget* create(const QString& classname, QWidget* parent=0, const char* name=0);
QString group(const QString&) const;
QIconSet iconSet(const QString&) const;
QString includeFile(const QString&) const;
QString toolTip(const QString&) const;
QString whatsThis(const QString&) const;
bool isContainer(const QString&) const;
}
... and the .cpp
#include "CustomWidgetPlugin.h"
CustomWidgetPlugin::CustomWidgetPlugin()
:QWidgetPlugin()
{
}
QStringList CustomWidgetPlugin::keys() const
{
QStringList list;
list << "FileChooser";
return list;
}
QWidget* CustomWidgetPlugin::create(const QString& key, QWidget* parent, const char* name) const
{
if( key == "FileChooser" )
return new FileChooser(parent, name);
return null ;
}
QString CustomWidgetPlugin::includeFile(const QString& feature) const
{
if( feature == "FileChooser" )
return "filechooser.h";
return QString::null;
}
QString CustomWidgetPlugin::group(const QString& feature) const
{
if( feature == "FileChooser" )
return "Input";
return QString::null;
}
QIconSet CustomWidgetPlugin::iconSet(const QString& feature) const
{
return QIconSet( QPixmap("filechooser_pixmap.png"));
}
QString CustomWidgetPlugin::toolTip(const QString& feature) const
{
if( feature == "FileChooser" )
return "File Chooser Widget";
return QString::null;
}
QString CustomWidgetPlugin::whatsThis(const QString& feature) const
{
if( feature == "FileChooser" )
return "A widget to choose a file";
return QString::null;
}
bool CustomWidgetPlugin::isContainer(const QString& feature) const
{
return FALSE;
}
Q_EXPORT_PLUGIN( CustomWidgetPlugin )
and my .pro
################################################## ####################
# Automatically generated by qmake (1.07a) dim. 29. janv. 10:37:16 2006
################################################## ####################
SOURCES += CustomWidgetPlugin.cpp ../FileChooser/FileChooser.cpp
HEADERS += CustomWidgetPlugin.h ../FileChooser/FileChooser.h
DESTDIR = $(QTDIR)/plugins/designer
TARGET = filechooser
target.path = $$plugins.path
isEmpty(target.path):target.path==$$QT_PREFIX/plugins
INSTALLS += target
TEMPLATE = lib
CONFIG += qt warn_on release plugin
INCLUDEPATH += $(QTDIR)/tools/designer/interfaces
DBFILE = plugin.db
PROJECTNAME = Plugin
LANGUAGE = C++
So, I go to the folder where are those files I type in console mode the two following commands :
qmake -o Makefile CustomWidgetPlugin.pro
nmake
Then the console displays me the following errors :
.\CustomWidgetPlugin.cpp(4) : error C2533 : 'CustomWidgetPlugin::CustomWidgetPlugin' : constructors not allowed a retrun type
.\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
.\CustomWidgetPlugin.cpp(61) : error C2264 : 'CustomWidgetPlugin::CustomWidgetPlugin' : error in function definiton or declaration; function not called
That 's all information I can give you.
I hope you will be able to help me.
Thanks in advance.
wysota
29th January 2006, 11:05
Try adding #include <qwidget.h> to the header file. And a semicolon after class declaration. And Q_EXPORT_PLUGIN( ) macro.
yellowmat
29th January 2006, 12:00
Ok, that's what I did.
I alse add the following line in my plugin header
#include ".\\..\\FileChooser\\FileChooser.h"
I still have some errors, but different this time. Here they are :
.\CustomWidgetPlugin.cpp(62) : error C2259: 'CustomWidgetPlugin' : cannot instantiate abstract class due to following members : /.CustomWidgetPlugin.h(4) : see declaration of 'CustomWidgetPlugin'
The line 62 in this file points to the following :
Q_EXPORT_PLUGIN( CustomWidgetPlugin );
jacek
29th January 2006, 14:00
Remove "const" after CustomWidgetPlugin::create() in .cpp file.
yellowmat
29th January 2006, 21:41
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
// FileChooser.h: interface for the CFileChooser class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_FILECHOOSER_H__59B1F80E_2AB6_4FAD_BA4 D_DEAA892068B8__INCLUDED_)
#define AFX_FILECHOOSER_H__59B1F80E_2AB6_4FAD_BA4D_DEAA892 068B8__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <qwidget.h>
class QLineEdit;
class QPushButton;
class CFileChooser : public QWidget
{
Q_OBJECT
Q_PROPERTY( QString fileName READ fileName WRITE setFileName)
// Constructor / Destructor
public:
CFileChooser(QWidget* parent=0, const char* name=0);
virtual ~CFileChooser();
// Slots
public slots:
void setFileName( const QString& fn );
private slots:
void chooseFile();
// Signals
signals:
void fileNameChanged( const QString& fn );
// Functions
public:
QString fileName() const;
// Members
private:
QLineEdit* lineEdit;
QPushButton* button;
};
#endif // !defined(AFX_FILECHOOSER_H__59B1F80E_2AB6_4FAD_BA4 D_DEAA892068B8__INCLUDED_)
FileChooser.cpp
// FileChooser.cpp: implementation of the CFileChooser class.
//
//////////////////////////////////////////////////////////////////////
#include "FileChooser.h"
#include <qlayout.h>
#include <qlineedit.h>
#include <qpushbutton.h>
#include <qfiledialog.h>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CFileChooser::CFileChooser(QWidget* parent, const char* name)
:QWidget(parent, name)
{
QHBoxLayout* layout = new QHBoxLayout(this);
layout->setMargin(0);
lineEdit = new QLineEdit(this, "filechooser_lineedit");
layout->addWidget(lineEdit);
connect(lineEdit, SIGNAL(textChanged(const QString&)), this, SIGNAL(fileNameChanged(const QString&)));
button = new QPushButton("...", this, "filechooser_button");
button->setFixedWidth(button->fontMetrics().width("..."));
layout->addWidget(button);
connect(button, SIGNAL(clicked()), this, SLOT(chooseFile()));
setFocusProxy(lineEdit);
}
CFileChooser::~CFileChooser()
{
}
void CFileChooser::setFileName(const QString& fn)
{
lineEdit->setText(fn);
}
QString CFileChooser::fileName() const
{
return lineEdit->text();
}
void CFileChooser::chooseFile()
{
QString fn;
fn = QFileDialog::getOpenFileName(lineEdit->text(), QString::null, this);
if( !fn.isEmpty() )
{
lineEdit->setText(fn);
emit fileNameChanged(fn);
}
}
Plugin.h
#include <qwidgetplugin.h>
#include <qwidget.h>
class QT_WIDGET_PLUGIN_EXPORT CustomWidgetPlugin : public QWidgetPlugin
{
public:
CustomWidgetPlugin();
QStringList keys() const;
QWidget* create(const QString& classname, QWidget* parent=0, const char* name=0);
QString group(const QString&) const;
QIconSet iconSet(const QString&) const;
QString includeFile(const QString&) const;
QString toolTip(const QString&) const;
QString whatsThis(const QString&) const;
bool isContainer(const QString&) const;
};
Plugin.cpp
#include "CustomWidgetPlugin.h"
#include ".\\..\\FileChooser\\FileChooser.h"
CustomWidgetPlugin::CustomWidgetPlugin()
:QWidgetPlugin()
{
}
QStringList CustomWidgetPlugin::keys() const
{
QStringList list;
list << "CFileChooser";
return list;
}
QWidget* CustomWidgetPlugin::create(const QString& key, QWidget* parent, const char* name)
{
if( key == "CFileChooser" )
return new CFileChooser(parent, name);
return 0;
}
QString CustomWidgetPlugin::includeFile(const QString& feature) const
{
if( feature == "CFileChooser" )
return "filechooser.h";
return QString::null;
}
QString CustomWidgetPlugin::group(const QString& feature) const
{
if( feature == "CFileChooser" )
return "Input";
return QString::null;
}
QIconSet CustomWidgetPlugin::iconSet(const QString& feature) const
{
return QIconSet( QPixmap("filechooser_pixmap.png"));
}
QString CustomWidgetPlugin::toolTip(const QString& feature) const
{
if( feature == "CFileChooser" )
return "File Chooser Widget";
return QString::null;
}
QString CustomWidgetPlugin::whatsThis(const QString& feature) const
{
if( feature == "CFileChooser" )
return "A widget to choose a file";
return QString::null;
}
bool CustomWidgetPlugin::isContainer(const QString& feature) const
{
return FALSE;
}
Q_EXPORT_PLUGIN( CustomWidgetPlugin );
Plugin.pro
################################################## ####################
# Automatically generated by qmake (1.07a) dim. 29. janv. 10:37:16 2006
################################################## ####################
SOURCES += CustomWidgetPlugin.cpp ../FileChooser/FileChooser.cpp
HEADERS += CustomWidgetPlugin.h ../FileChooser/FileChooser.h
DESTDIR = $(QTDIR)/plugins/designer
TARGET = filechooser
target.path = $$plugins.path
isEmpty(target.path):target.path==$$QT_PREFIX/plugins
INSTALLS += target
TEMPLATE = lib
CONFIG += qt warn_on release plugin
INCLUDEPATH += $(QTDIR)/tools/designer/interfaces
DBFILE = plugin.db
PROJECTNAME = Plugin
LANGUAGE = C++
Powered by vBulletin® Version 4.2.5 Copyright © 2023 vBulletin Solutions Inc. All rights reserved.