rubikon
31st August 2012, 10:49
Hello.
I want to write a small tool and like to separate the business logic from the GUI so I can easily make and use different GUIs.
Therefore I've made a class which contains the business logic called AppCore. The GUI class(es) are called MainWindow.
My idea is to pass the constructor of the AppCore a reference to the GUI so the constructor of the AppCore can connect the AppCore singals to the GUI slots and vice versa.
But to make it flexible I don't want to have the actual GUI as type of the parameter but an Interface (pure virtual class) called IGui which the GUI inherits from.
class IGui
{
public slots:
virtual void slot() = 0;
signals:
virtual void signal() = 0;
};
class MainWindow : public QMainWindow, public IGui
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void slot();
signals:
void signal();
private:
Ui::MainWindow *ui;
};
class AppCore : public QObject
{
Q_OBJECT
public:
explicit AppCore(IGui *gui, QObject *parent = 0);
signals:
void doSlot();
private slots:
void onSingal();
...
...
}
AppCore::AppCore(IGui *gui, QObject *parent) :
QObject(parent)
{
connect(gui, SIGNAL(signal()),
this, SLOT(onSingal()));
connect(this, SIGNAL(doSlot()),
gui, SLOT(slot()));
}
But when I try to compile I get errors:
AppCore.cpp: In constructor 'AppCore::AppCore(IGui*, QObject*)':
AppCore.cpp:9: error: no matching function for call to 'AppCore::connect(IGui*&, const char [10], AppCore* const, const char [12])'
c:\QtSDK\Desktop\Qt\4.8.1\mingw\include\QtCore/qobject.h:204: note: candidates are: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)
c:\QtSDK\Desktop\Qt\4.8.1\mingw\include\QtCore/qobject.h:217: note: static bool QObject::connect(const QObject*, const QMetaMethod&, const QObject*, const QMetaMethod&, Qt::ConnectionType)
c:\QtSDK\Desktop\Qt\4.8.1\mingw\include\QtCore/qobject.h:337: note: bool QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
AppCore.cpp:12: error: no matching function for call to 'AppCore::connect(AppCore* const, const char [10], IGui*&, const char [8])'
c:\QtSDK\Desktop\Qt\4.8.1\mingw\include\QtCore/qobject.h:204: note: candidates are: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)
c:\QtSDK\Desktop\Qt\4.8.1\mingw\include\QtCore/qobject.h:217: note: static bool QObject::connect(const QObject*, const QMetaMethod&, const QObject*, const QMetaMethod&, Qt::ConnectionType)
c:\QtSDK\Desktop\Qt\4.8.1\mingw\include\QtCore/qobject.h:337: note: bool QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
How do I have to do it right?
I want to write a small tool and like to separate the business logic from the GUI so I can easily make and use different GUIs.
Therefore I've made a class which contains the business logic called AppCore. The GUI class(es) are called MainWindow.
My idea is to pass the constructor of the AppCore a reference to the GUI so the constructor of the AppCore can connect the AppCore singals to the GUI slots and vice versa.
But to make it flexible I don't want to have the actual GUI as type of the parameter but an Interface (pure virtual class) called IGui which the GUI inherits from.
class IGui
{
public slots:
virtual void slot() = 0;
signals:
virtual void signal() = 0;
};
class MainWindow : public QMainWindow, public IGui
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void slot();
signals:
void signal();
private:
Ui::MainWindow *ui;
};
class AppCore : public QObject
{
Q_OBJECT
public:
explicit AppCore(IGui *gui, QObject *parent = 0);
signals:
void doSlot();
private slots:
void onSingal();
...
...
}
AppCore::AppCore(IGui *gui, QObject *parent) :
QObject(parent)
{
connect(gui, SIGNAL(signal()),
this, SLOT(onSingal()));
connect(this, SIGNAL(doSlot()),
gui, SLOT(slot()));
}
But when I try to compile I get errors:
AppCore.cpp: In constructor 'AppCore::AppCore(IGui*, QObject*)':
AppCore.cpp:9: error: no matching function for call to 'AppCore::connect(IGui*&, const char [10], AppCore* const, const char [12])'
c:\QtSDK\Desktop\Qt\4.8.1\mingw\include\QtCore/qobject.h:204: note: candidates are: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)
c:\QtSDK\Desktop\Qt\4.8.1\mingw\include\QtCore/qobject.h:217: note: static bool QObject::connect(const QObject*, const QMetaMethod&, const QObject*, const QMetaMethod&, Qt::ConnectionType)
c:\QtSDK\Desktop\Qt\4.8.1\mingw\include\QtCore/qobject.h:337: note: bool QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
AppCore.cpp:12: error: no matching function for call to 'AppCore::connect(AppCore* const, const char [10], IGui*&, const char [8])'
c:\QtSDK\Desktop\Qt\4.8.1\mingw\include\QtCore/qobject.h:204: note: candidates are: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)
c:\QtSDK\Desktop\Qt\4.8.1\mingw\include\QtCore/qobject.h:217: note: static bool QObject::connect(const QObject*, const QMetaMethod&, const QObject*, const QMetaMethod&, Qt::ConnectionType)
c:\QtSDK\Desktop\Qt\4.8.1\mingw\include\QtCore/qobject.h:337: note: bool QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
How do I have to do it right?