PDA

View Full Version : QCombobox Plugin - how ?



vieraci
22nd November 2009, 06:43
I've made a designer widget but it has some shortcomings.
It's basically a combobox with some added functionality, but when I use it in the gui editor it doesn't come up in the tab order list and setFocus() doesn't work. I think it's because I've derived my part from QWidget, I tried changing the base class to QComboBox but it doesn't compile. The alternative is to subclass setFocous() and then do cb.setFocus() from within the class but this is not a proper solution


dbcomboboxplugin.cpp: In function ‘QObject* qt_plugin_instance()’:
dbcomboboxplugin.cpp:91: error: cannot allocate an object of abstract type ‘DbComboBoxPlugin’
dbcomboboxplugin.h:9: note: because the following virtual functions are pure within ‘DbComboBoxPlugin’:
/usr/include/qt4/QtDesigner/customwidget.h:71: note: virtual QWidget* QDesignerCustomWidgetInterface::createWidget(QWidg et*)

I've attached the 2 header files.

faldzip
22nd November 2009, 11:37
You didn't implement required pure virtual method so your class it is abstract so you can't have an instance (object) of an abstract class. Did you read Designer plugin example in Assistant? There is all you need to know. You have a:


QComboBox *createWidget(QComboBox *parent);

in your header. So it is your own additional method in DbComboBoxPlugin.
You don't have


QWidget *createWidget(QWidget *parent);

which is pure virtual in QDesignerCustomWidgetInterface so you have to implement it in your QDesignerCustomWidgetInterface implementation which is DbComboBoxPlugin in your case.

I think that it was just a mistake to write QComboBox instead of QWidget, but if not, then try to renew your knowledge about C++ Overriding.

vieraci
22nd November 2009, 12:42
I did read the example, my earlier version that compiled did have:

QWidget *createWidget(QWidget *parent);
as per the example,and in the implementation file:

QWidget *DbComboBoxPlugin::createWidget(QWidget *parent)
{
return new DbComboBox(parent);
}
(Is this not C++ over-riding ? if not, I have not understood it at all). :o
This is creating an instance, but I'm not seeing all of QComboBox features.
What am I missing then?

vieraci
23rd November 2009, 22:30
no one got any idea or clue ?