I didn't read all the posts, just the last question.
Of course you can... Qt does it with the MVC architecture, for example. There are other ways too.can't I separate logic and gui when using Qt ?
I'm not sure what CompView is supposed to do, but it doesn't look good. Having an object inheriting from a GUI class and a class that implements app logic is not called "separating logic".
Actually, there's a word for that: "mess". In the end you'll end up with an object that exposes both things anyway.
I can't(not yet) because I still don't see the point... Are you writing a library? Or what?
Currently you are not hiding anything. You still need a QApplication object, you'll need to run QApplication::exec() eventually, etc. This is certainly not the way to go, regardless of the language used.
If you want to hide Qt, hide all of it and not a part of it - have a function(s) that will do everything starting from making sure there is a QApplication object available, through instantiating the object, showing it, manipulating it up to destroying it when it's not needed anymore. Currently you're just handling instantiation and what about the rest?
There are for instance Photoshop plugins written in Qt and they handle the situation very well, so obscuring the technology behind the interface is possible, you are just doing it the wrong way.
Here is a trivial example (not tested - and you still need QApplication::exec() somewhere):
Qt Code:
class Iface { public: virtual void initialize() = 0; virtual void show() = 0; virtual void destroy() = 0; }; class Implementation : public Iface { public: void initialize() { } } void show() { widget->show(); } void destroy() { delete widget; } private: QMainWindow *widget; };To copy to clipboard, switch view to plain text mode
Plain old casting and doubble inheritance do not work as expected. Look at this line:
Qt Code:
To copy to clipboard, switch view to plain text mode
Try using qobject_cast or dynamic_cast:
Qt Code:
mw.setCentralWidget( qobject_cast<QWidget*>(c) ); mw.setCentralWidget( dynamic_cast<QWidget*>(c) );To copy to clipboard, switch view to plain text mode
or just no cast at all:
And do try to put the QObject first in the double inheritance.
Rockem (8th March 2008)
qobject_cast won't work because CompView is not a QObject. dynamic_cast seems to work.
yea, dynamic_cast works great !!!
thanx![]()
Bookmarks