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.

Qt Code:
  1. class IGui
  2. {
  3. public slots:
  4. virtual void slot() = 0;
  5.  
  6. signals:
  7. virtual void signal() = 0;
  8. };
  9.  
  10. class MainWindow : public QMainWindow, public IGui
  11. {
  12. Q_OBJECT
  13.  
  14. public:
  15. explicit MainWindow(QWidget *parent = 0);
  16. ~MainWindow();
  17.  
  18. private slots:
  19. void slot();
  20.  
  21. signals:
  22. void signal();
  23.  
  24. private:
  25. Ui::MainWindow *ui;
  26. };
  27.  
  28. class AppCore : public QObject
  29. {
  30. Q_OBJECT
  31.  
  32. public:
  33. explicit AppCore(IGui *gui, QObject *parent = 0);
  34.  
  35. signals:
  36. void doSlot();
  37.  
  38. private slots:
  39. void onSingal();
  40. ...
  41. ...
  42. }
  43.  
  44. AppCore::AppCore(IGui *gui, QObject *parent) :
  45. QObject(parent)
  46. {
  47. connect(gui, SIGNAL(signal()),
  48. this, SLOT(onSingal()));
  49.  
  50. connect(this, SIGNAL(doSlot()),
  51. gui, SLOT(slot()));
  52. }
To copy to clipboard, switch view to plain text mode 

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?