
Originally Posted by
Rockem
can you give me an example ? for the short program I have ?
how can I have a widget but hide all Qt related ?
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):
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:
};
class Iface {
public:
virtual void initialize() = 0;
virtual void show() = 0;
virtual void destroy() = 0;
};
class Implementation : public Iface {
public:
void initialize() {
if(!QApplication::instance()){
QApplication *app = new QApplication;
widget = new QMainWindow;
}
}
void show() { widget->show(); }
void destroy() { delete widget; }
private:
QMainWindow *widget;
};
To copy to clipboard, switch view to plain text mode
Bookmarks