PDA

View Full Version : Can't create my custom QGraphicsView for QDesigner



sincnarf
11th October 2007, 23:24
Hello I am trying to create my own custom QGraphicsView to be used by QtDesigner. This is my code and I based it on customclockwidget that I read in QtAssistant


#ifndef CUSTOMGVPLUGIN_H
#define CUSTOMGVPLUGIN_H
#include <QDesignerCustomWidgetInterface>
class customgvPlugin : public QObject, public QDesignerCustomWidgetInterface {
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)

public:
customgvPlugin(QObject *parent = 0);

bool isContainer() const;
bool isInitialized() const;
QIcon icon() const;
QString domXml() const;
QString group() const;
QString includeFile() const;
QString name() const;
QString toolTip() const;
QString whatsThis() const;
QGraphicsView *createWidget(QGraphicsScene *scene, QWidget *parent);
void initialize(QDesignerFormEditorInterface *core);

private:
bool initialized;
};
#endif



This is the error

customgvplugin.h:3:43: error: QDesignerCustomWidgetInterface: No such file or directory What could be the cause of this? I'm running qt in Ubuntu Feisty Fawn. my make install for Qt-4.3.1 had no errors at all

marcel
11th October 2007, 23:53
Does your pro file contains
CONFIG += designer plugin?

sincnarf
12th October 2007, 00:59
Does your pro file contains ?
Thanks for that. Now it has the error

customgvplugin.cpp: In function ‘QObject* qt_plugin_instance()’:
customgvplugin.cpp:73: error: cannot allocate an object of abstract type ‘customgvPlugin’
customgvplugin.h:4: note: because the following virtual functions are pure within ‘customgvPlugin’:
/usr/local/Trolltech/Qt-4.3.1/include/QtDesigner/customwidget.h:66: note: virtual QWidget* QDesignerCustomWidgetInterface::createWidget(QWidg et*)
make[1]: *** [release/customgvplugin.o] Error 1
make[1]: Leaving directory `/root/workspace/IADFUQ/PLUGINS/customgvplugin'
make: *** [release] Error 2

this is on last line

Q_EXPORT_PLUGIN2(customgvplugin, customgvPlugin)

here' the full code of the plugin

#include "customgv.h"
#include "customgvplugin.h"

#include <QtPlugin>

customgvPlugin::customgvPlugin(QObject *parent):QObject(parent) {
initialized = false;
}

void customgvPlugin::initialize(QDesignerFormEditorInte rface *) {
if (initialized)
return;

initialized = true;
}

bool customgvPlugin::isInitialized() const {
return initialized;
}

QGraphicsView *customgvPlugin::createWidget(QGraphicsScene *scene, QWidget *parent)
{
return new customgv(scene, parent);
}

QString customgvPlugin::name() const {
return "IADFUQGraphicsView";
}

QString customgvPlugin::group() const {
return "Display Widgets [Examples]";
}

QIcon customgvPlugin::icon() const {
return QIcon();
}

QString customgvPlugin::toolTip() const {
return "";
}

QString customgvPlugin::whatsThis() const {
return "";
}

bool customgvPlugin::isContainer() const {
return false;
}

QString customgvPlugin::domXml() const {
return "<widget class=\"customgv\" name=\"customgv\">\n"
" <property name=\"geometry\">\n"
" <rect>\n"
" <x>0</x>\n"
" <y>0</y>\n"
" <width>100</width>\n"
" <height>100</height>\n"
" </rect>\n"
" </property>\n"
" <property name=\"toolTip\" >\n"
" <string>IADFUQ GRAPHICS VIEW</string>\n"
" </property>\n"
" <property name=\"whatsThis\" >\n"
" <string>IADFUQ GRAPHICS VIEW</string>\n"
" </property>\n"
"</widget>\n";
}

QString customgvPlugin::includeFile() const {
return "customgv.h";
}

Q_EXPORT_PLUGIN2(customgvplugin, customgvPlugin)

Does this mean I can't create my own QGraphicsView to be integrated with QDesigner? (because QGraphicsView does not directly inherit the QWidget class? Instead QGraphicsView inherits from QAbstractScrollArea) (?)

spud
12th October 2007, 10:05
AFAICT you have to add


QWidget *customgvPlugin::createWidget(QWidget *parent)
{
return new customgv(0, parent);
}

sincnarf
12th October 2007, 11:32
AFAICT you have to add


QWidget *customgvPlugin::createWidget(QWidget *parent)
{
return new customgv(0, parent);
}


same error still. I think I'm gonna give up on this

wysota
12th October 2007, 12:33
createWidget has to return a QWidget pointer, not QGraphicsView pointer.

sincnarf
12th October 2007, 12:36
Attached are all of the files for a custom QGraphicsView. Anyway if ever I succeed in this, how can I handle the includes for customgv.h that will be used by the designer? On compilation of my whole project there's an error in ui_mainwindow.h file of mine because of the line


#include "customgv.h"

Also all lines like
customgv *customgv; in the ui_mainwindow.h will have errors. How will I solve this?

wysota
12th October 2007, 12:55
What kind of error?

sincnarf
12th October 2007, 13:08
What kind of error?

ui_mainwindow.h:68: error: ISO C++ forbids declaration of ‘customgv’ with no type
ui_mainwindow.h:68: error: expected ‘;’ before ‘*’ token
ui_mainwindow.h: In member function ‘void Ui_mainwindow::setupUi(QMainWindow*)’:
ui_mainwindow.h:351: error: ‘customgv’ was not declared in this scope
ui_mainwindow.h:351: error: expected type-specifier before ‘customgv’
ui_mainwindow.h:351: error: expected `;' before ‘customgv’
ui_mainwindow.h: In member function ‘void Ui_mainwindow::retranslateUi(QMainWindow*)’ :
ui_mainwindow.h:850: error: ‘customgv’ was not declared in this scope

spud
12th October 2007, 13:11
#include "‘customgv.h" is missing.

sincnarf
13th October 2007, 09:12
#include "‘customgv.h" is missing.

see, whenever I execute "qmake" "make" .... the ui_mainwindow.h that comes from my mainwindow.ui is generated including the line "#include "customgv.h", so it's already there...

What I need is this instead #include "../PLUGINS/customgvplugin/customgv.h" but alas, executing make generates the wrong path which is #include "customgv.h" only in my ui_mainwindow.h.

So what I'm thinking right now is now that I've created my libcustomgvplugin.so plugin and it's aleady under the folder /usr/local/Trolltech/Qt-4.3.1/plugins/designer.... how can executing "make" not report errors like the ones stated above

wysota
13th October 2007, 10:47
You have to place the header file in some known location (just like regular headers are placed within /usr/include) and use the INCLUDEPATH+=-I<dir> statement in the project file of the project where you want to use the file.

You can take a look at my wwWidgets (http://www.wysota.eu.org/wwwidgets) to see how to solve some of your problems.

sincnarf
13th October 2007, 21:29
You can take a look at my wwWidgets (http://www.wysota.eu.org/wwwidgets) to see how to solve some of your problems.

Thanks but the site http://www.wysota.eu.org/wwwidgets is not loading.

wysota
13th October 2007, 22:55
Try again tomorrow or on Monday, there seems to be a problem with the network link. I can do nothing about it now.