PDA

View Full Version : interface on plugin



tranfuga25s
6th March 2008, 15:27
when I try to compile my plugin, I get this error:

compilando presupuesto.cpp (g++)
presupuesto.h:45: error: ISO C++ forbids declaration of 'EPresupuesto' with no type
presupuesto.h:45: error: expected ';' before '*' token
presupuesto.cpp: In constructor 'Presupuesto::Presupuesto(QObject*)':
presupuesto.cpp:65: error: '_plugin' was not declared in this scope
presupuesto.cpp:65: error: 'EPresupuesto' was not declared in this scope
presupuesto.cpp:65: error: parse error in template argument list
presupuesto.cpp:65: error: no matching function for call to 'qobject_cast(QObject*)'

but the code is the next:


if( loader->load() )
{
_plugin = qobject_cast<EPresupuesto *>(loader->instance());and in the class is declared as follows:

private:
EPresupuesto *_plugin;the include is present and the interface is

#include <QtPlugin>
class QString;
class QSqlRecord;
/**
* \brief Interfaz de presupuesto
*
* Interfaz para especificaciones del plugin presupuesto
*
* @author Esteban Zeller <juiraze@yahoo.com.ar>
*/
class EPresupuesto
{
public:
virtual ~EPresupuesto() {}
virtual QString nombre() const = 0;
virtual double version() const = 0;
virtual void setRegistro( QSqlRecord *rec ) = 0;
virtual QString obtenerHtml() = 0;
virtual QString obtenerContenido() = 0;
};

Q_DECLARE_INTERFACE(EPresupuesto,
"tranfuga.EPresupuesto/1.0" )Where is the problem??? :(
thanks in advance

estanisgeyer
6th March 2008, 15:38
You included the head of the class?

tranfuga25s
6th March 2008, 17:56
You included the head of the class?

Yes. the epresupuesto.h file...

jpn
6th March 2008, 18:48
Could you clarify where the interface is declared and which file includes and what?

tranfuga25s
6th March 2008, 20:32
the file presupuesto.cpp:

#ifndef EPRESUPUESTO_H
#define EPRESUPUESTO_H

#include <QObject>
class QSqlRecord;
#include <QPluginLoader>
#include <epresupuesto.h>
class QPainter;
/**
* \brief Clase de presupuesto
*
* Clase que sirve como contenedor de un presupuesto y puede hacer todas sus operaciones
*
* @author Esteban Zeller <juiraze@yahoo.com.ar>
*/
class Presupuesto : public QObject
{
Q_OBJECT
public:
Presupuesto(QObject *parent = 0);
~Presupuesto();
QSqlRecord registro( int id );
void imprimir( QPainter *pintador );

private:
EPresupuesto *_plugin;
QPluginLoader *loader;
};

#endifin the file presupuesto.cpp:

#include "presupuesto.h"


#include <QDir>
#include <QApplication>
#include <QSqlRecord>
#include <QPainter>
#include "eplugin.h"

#include "prespuesto.h"
#include <QMessageBox>

Presupuesto::Presupuesto(QObject *parent)
: QObject(parent)
{
loader = new QPluginLoader( this );
// Busco los plugins de presupuestos
QDir pluginsDir = QDir(qApp->applicationDirPath());

#if defined(Q_OS_WIN)
if (pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release")
pluginsDir.cdUp();
#elif defined(Q_OS_MAC)
if (pluginsDir.dirName() == "MacOS") {
pluginsDir.cdUp();
pluginsDir.cdUp();
pluginsDir.cdUp();
}
#endif
pluginsDir.cd("plugins");
pluginsDir.cd("presupuesto");
#ifdef Q_WS_WIN32
QStringList filtro;
filtro.append( "*.dll" );
#endif
// Obtengo el nombre del plugin de infoprog actual para cargar el del mismo nombre
int pos = pluginsDir.entryList( QDir::Files ).indexOf( prespuesto::pref()->value( "pluginInfo", "default" ).toString() );
if( pos == -1 )
{
QMessageBox::critical( 0, "Error", "No existe ningun plugin de presupuestos definidos! Verifique la instalación!" );
return;
}
loader->setFileName( pluginsDir.absoluteFilePath( pluginsDir.entryList( QDir::Files ).at( pos ) ) );
if( loader->load() )
{
_plugin = qobject_cast<EPresupuesto *>(loader->instance());

}
else
{
qWarning( "Error al cargar el plugin" );
qWarning( QString( "Error: %1" ).arg( loader->errorString() ).toLocal8Bit() );
}
// Fin de la carga del plugin
}


Presupuesto::~Presupuesto()
{
}

the include file that contains the interface it this:

#ifndef EPRESUPUESTO_H
#define EPRESUPUESTO_H

#include <QtPlugin>
class QString;
class QSqlRecord;
/**
* \brief Interfaz de presupuesto
*
* Interfaz para especificaciones del plugin presupuesto
*
* @author Esteban Zeller <juiraze@yahoo.com.ar>
*/
class EPresupuesto
{
public:
virtual ~EPresupuesto() {}
virtual QString nombre() const = 0;
virtual double version() const = 0;
virtual void setRegistro( QSqlRecord *rec ) = 0;
virtual QString obtenerHtml() = 0;
virtual QString obtenerContenido() = 0;
};

Q_DECLARE_INTERFACE(EPresupuesto,
"tranfuga.EPresupuesto/1.0" )

#endif


all the sintaxis and definitions are ok, but the compiler dont get the class EPresupuesto like a valid class...
all this clasess are inside a Qt Plugin....

jpn
6th March 2008, 21:34
You have the same define guard EPRESUPUESTO_H in two different header files.

tranfuga25s
6th March 2008, 21:56
Thanks! Many thanks...