Qt : C++ dynamic parameter GUI for plugin paramete

2019-04-12 10:58发布

问题:

My Qt based application is extensible via plugins ( http://doc.qt.io/archives/4.6/plugins-howto.html#the-lower-level-api-extending-qt-applications) .

These plugins can have its own parameters.(int,double,String, enumerations..etc)

What I want to do is, define this parameters in an XML and generate the GUI dynamically by parsing the XML file.

I found somewhat similar architecture here - http://www.slicer.org/slicerWiki/index.php/Slicer3:Execution_Model_Documentation#Slicer3_GUI_Generation

Is there any library/framework that I can use with Qt for this.Or do I have to manually write my own code from parsing XML,mapping parameters into Maps , generate GUI checking the XML element...etc

Any tips?

回答1:

I needed to do something similar a year or so ago; didn't find anything then to make it easier and quicker (link). Can't share it I'm afraid. Role your own.

Obvious, but I reverse-engineered XML generated by the Designer app and made some interfaces to re-generate common blocks of XML. Keep in mind that the XML might change in later Qt releases and I had unit tests to validate my own XML was valid.



回答2:

You can programmatically create *.ui files, see the XML schema. Then you can render them on the fly with QtUiTools.



回答3:

Tulip has such a mechanism, it is based on C++/Qt : http://tulip.labri.fr/TulipDrupal/ I think that the dev team defined it's own type to replace QVariant, in which they pass the plugin arguments. They can support various primary types, default arguments, various types of plugins, ...

Source code is available at : http://sourceforge.net/projects/auber/files/



回答4:

If you are using Qt and their plugin system, you should be able to define a function that returns a UI element from the plugin. You could then just show that element, and have the element itself handle configuring the plugin however it needs to be done. It seems simpler than going through an XML interface to specify everything.



回答5:

Please note that Slicer4 is based on Qt. I don't know if the GUI-generation part is ported already. Link to the alpha announcement and further information:

http://slicer-users.65878.n3.nabble.com/Slicer-4-0-alpha-td1448047.html



回答6:

You might want to look into QML.



回答7:

Also, you can use QScript, to control UI and what you want.