PDA

View Full Version : how to call a screen plugin function directy



Dzha
27th October 2010, 12:03
I have a screen plugin derived from QScreenDriverPlugin. It returns an object of QScreen* when the create() function is called. The main class in the plugin is derived from QLinuxFbScreen, which is derived from QScreen.
The plugin works perfectly well with the Qt painting system. So painting works ok by using QPainter calls from paintEvent.
Now, the problem is that device requires a special kind of screen refresh to be performed under certain circumstances. The main app knows when to trigger it and the plugin knows how to perform it. I created a function specialRefresh() in the plugin. How can I call it from my app?

In the plugin:


class MyInterface
{
public:
virtual ~MyInterface() {}
virtual void specialRefresh()= 0;
};

Q_DECLARE_INTERFACE(MyInterface, "myApplication/1.0");

Main plugin class


class DeviceScreen : public QObject, MyInterface, public QLinuxFbScreen
{
blah ...

void specialRefresh()
}

The plugin is loaded automatically at the startup and specified by environment variable. Therefore I do not need to load it, but somehow I need to find MyInterface and call specialRefresh(). I have tried so far:



//does not work, I think because QScreen is not derived from QObject
QScreen* screen = QScreen::Instance();
qobject_cast<MyInterface *>((QScreen*)screen );
MyInterface-> specialRefresh()




//does not work, crash
QPluginLoader plugin;
QObject* obj = plugin.Instance();
qobject_cast<MyInterface *>((obj);
MyInterface-> specialRefresh()


Class diagram:
http://d.imagehost.org/0828/refresh_ex.jpg (http://d.imagehost.org/view/0828/refresh_ex)