PDA

View Full Version : plugins with separate windows



janK
15th May 2013, 21:59
Hello

I have an SDR (Software Defined Radio) application that I want to extend. Basically the architecture of the program implementing the SDR is simple:
I read data from some device, do some processing (set some parameters and show some things), and pass processed data on to a selected decoder.
Currently I have app 10 decoders (typical decoders are for speech, usb, lsb, fm, rtty, psk, morse decoding, fax etc etc).
The structure of the user interaction with each of the decoders is different, the
input of the decoders is a simple stream, the output things written on a screen and a simple (data) stream. Each
decoder has its own (sub)screen on which decoder-specific interaction takes place, and a few,
very limited, connection to the main program. The subscreens are implemented as a stacked construct.
Since the number of decoders is growing, a few more are under development, I was thinking on a different, more dynamic, structure,
one were decoders are loaded dynamically, and off-loaded when another one is requested for. Then at the start of the program a list is made of
available decoders, such that a selector can be made. In such a set up, a user could even decide only to have a subset of the decoders on his machine, while
on the other hand, the program could be extended without recompilation: adding a new decoder somewhere
would cause it to be available on the next program start.

I was thinking whether the plug-in features of Qt could be helpful or otherwise it better could be solved by having the
decoders as separate programs, connected to the "main program" through a relatively simple IP mechanism. The biggest problem
with the plugin approach to me seems to be the dynamic creation (and destruction) of interaction windows (either
separate or embedded in the programs main window), something I really have no idea about (currently I am a simple user
of the Qt designer to create the GUI).

Any idea on this issue would be greatly appreciated.

thanks in advance
jan

lanz
16th May 2013, 08:34
The biggest problem
with the plugin approach to me seems to be the dynamic creation (and destruction) of interaction windows (either
separate or embedded in the programs main window), something I really have no idea about (currently I am a simple user
of the Qt designer to create the GUI).


That's really easy :D You see, to create window(or widget) you simple call it's constructor and then add resulting window to the respective layout/widget. You always can see generated Ui files for a simple example, or feel free to ask.
For example you can setup your plugin/main window somehow about this way:

class MainWindow {
public:
void loadPlugin () {
PluginInterface *loadedPlugin = doLoad ();
QWidget pluginWindow = loadedPlugin->createPluginWindow ();
pluginWindow->setParent(this);
this->ui->centralLayout->addWidget (pluginWindow);
};
};

class PluginInterface {
public:
QWidget * createPluginWindow () {
return new MyPluginWindow;
};
};

On details of how to create and load plugin look at the plug&paint example here:
http://qt-project.org/doc/qt-4.8/tools-plugandpaint.html

MSUdom5
17th May 2013, 17:09
janK,

Just wanted to offer a (perhaps irrelavent) tip that caused a me lot of issues when first starting out with plugins. The Qt documentation here:

http://qt-project.org/doc/qt-4.8/plugins-howto.html

has the following instruction step for creating a plugin:

"Define a set of interfaces (classes with only pure virtual functions) used to talk to the plugins."

This is a little misleading as the "interface" you create for your plugin does *not* have to be pure virtual. It can have defined functions, and the plugin can reimplement select ones.

janK
17th May 2013, 19:05
Thanks all so far,

My issue is not as much that I cannot load the plugin, I understand the standard example. My issue
is twofold:
a. when having selected a certain decoder, I want to be able to interact with a set of buttons and sliders on a screen, however, without
the main program having any knowledge of it (plugins, i.e. it should be possible to add decoders, without the main program having to
know on beforehand that such a decoder even exists)
b. When deallocating a decoder and creating a new decoder I want to have a fresh screen with the visuals of the new decoder. Is it possible to design
a screen for such a plugin (to be embedded on a fixed location in the main screen) using the designer

A pointer to any example (not begin the standard brushes etc plugin) would be appreciated

best
jan

lanz
20th May 2013, 08:49
a. when having selected a certain decoder, I want to be able to interact with a set of buttons and sliders on a screen, however, without
the main program having any knowledge of it (plugins, i.e. it should be possible to add decoders, without the main program having to
know on beforehand that such a decoder even exists)
See the second part of my previous post. Here I elaborate a little.

class MainWindow {

public:

void loadPlugin () {
// here you load plugin
PluginInterface *loadedPlugin = doLoad ();
// Now call defined in the interface method to create widget that contains
// buttons and sliders specific for that plugin
QWidget pluginWindow = loadedPlugin->createPluginWindow ();
// And add this widget to our mainwindow
// Of course you can add specific widget(say QFrame) to be the exact container for child
// widget (with plugin controls)
pluginWindow->setParent(this);
this->ui->centralLayout->addWidget (pluginWindow);
// After that you'll have plugin-specific set of controls ins widget of choice
// Let's just save pointer for subsequent deletion
this->plugWindow= pluginWindow;
};

};


class PluginInterface {

public:
QWidget * createPluginWindow () {
// here you can return QWidget window created in designer beforehand
// It's irrelevant if you want stand-alone window or a widget being a part of the ui
// the return type is the same
// This widget will encapsulate all controls specific for the concrete plugin
return new MyPluginWindow;
};
};


b. When deallocating a decoder and creating a new decoder I want to have a fresh screen with the visuals of the new decoder. Is it possible to design
a screen for such a plugin (to be embedded on a fixed location in the main screen) using the designer
As I already said, you can place QFrame or QWidget in place where you want your plugin and the add plugin widget as a child widget to it.
Deletion is quite straightforward:

class MainWindow {
public:
void cleanUp (){
// here we clean up
this->plugWindow->deleteLater ();
// and can load another plugin
this->loadPlugin ();
// After that the widget gets deleted and a new one will be added
};
};