I am using Qt to create a window and I have the following code (this is somewhat in pseudo-code):
class MyInterface {
virtual void doupdate() = 0;
}
class InterfaceHandler {
InterfaceHandler(MyInterface *i) {
the_int = i;
start_thread(&mainloop);
}
void mainloop() {
while(1) the_int->doupdate();
}
MyInterface *the_int;
}
class console : public QMainWindow, public MyInterface {
console() {
InterfaceHandler x(this);
}
void doupdate() {
//code to modify the gui
}
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
console w(argc, argv);
w.show();
return a.exec();
}
My issue is that when the_int->doupdate()
is called in mainloop()
, the reference to the_int
is wrong. I think this has to do with the fact that console
inherits QMainWindow
, but I am not sure what the solution is.
MyInterface
doesn't always get inherited by a QObject
. I've tried to split the doupdate()
from console
into another class which gets passed the reference to console
in the constructor, but get the same result.
Any ideas?