Elegent data transmission and GUI construction



  • Hi -

    I have sort of a complicated question, so hopefully I'll be able to make it clear what I'm trying to do.

    I have two computing systems, an embedded remote system and a control workstation. The are commands that go from the control station to the remote system, and status data which is returned from the remote system. Both are Qt based systems, the remote one obviously has no QUI (is a QCoreApplication), and the other one is a GUI-based system. The two share definitions of the messages which must be passed back and forth. The typical way we do this is by defining structures (POD structs, to be clear) which define how all the bytes in the data are laid out.

    What I'm curious about is if there is some slick way to take these POD structs and generically construct GUI elements for sending the commands. So if the struct has three integer fields, it would present the use with three text boxes and only accept ints in said text boxes, then build the appropraite data structure for transmission out the network. The hard part about this is that since they are POD structs, they're not Qt objects, nor do they have any member functions so that I can use them purely to lay over memory. The bummer about turning them into some kind of Qt class is that then I have to have marshaling functions for every one, and there might be hundreds of these.

    Also, there are non-Qt systems between the two computers that look at the messages and evaluate whether they are apprpriate or not.

    I'm sure this is a fairly common setup, and I'm wondering if anyone has a slick solution.



  • Are you looking for a pure C++ solution? Bare <code>struct</code>s can't be looped over in code without knowing a priori the type of each element, and I can't think of a way to do it with template metaprogramming, either (though it may be possible, I'm not great with that stuff). I'd personally approach it by writing a script of some kind that reads the struct definition from the source file and creates compilable code based on that.



  • I guess I'm looking for a pure C++ solution. I also suppose I'd be open to defining the structs in some other format - like maybe in an XML file or something. I'd really prefer not to run a script on the header file though... yuck.



  • I think what you want is not doable. There just isn't enough information in a POD data structure for an application to know what kind of UI to generate for it. For instance, how would you label those three boxes? What are the acceptable input ranges?

    For generating a dynamic UI like that, you quicky end up with property-editor like interfaces. However, these need meta data. That metadata may come from QObject intropection or from other sources, but it needs to come from somewhere. Just the POD is not going to give it to you. In fact, it doesn't even tell you what the data types are that are inside of it.

    What may work, is if you turn to code generation. That gives you the opportunity to generate your data structures as you see fit, and still generate enough meta data to pull this off. Once compiled, you're too late to get to this information.

    Your second question is very unclear. What would define if a message is appropriate?



  • If you are open to alternate ways of defining your structs, then you can indeed loop over them at compile time -- see the "Boost Fusion":http://www.boost.org/doc/libs/1_47_0/libs/fusion/doc/html/index.html library, for example. However, as Andre points out, even if you can figure out the types of each element, your GUI will still just be a column of labels (presumably the struct element name) and generic input widgets, with no input validation, etc.



  • [quote author="Andre" date="1324570517"]I think what you want is not doable. There just isn't enough information in a POD data structure for an application to know what kind of UI to generate for it. For instance, how would you label those three boxes? What are the acceptable input ranges?
    [/quote]

    Ok, so if I was willing to not use POD structs, then what would you guys suggest? Here is what I want to avoid: file explosion. I've seen other people do these with classes before and you end up having hundreds of files and it becomes a nightmare.

    [quote author="Andre" date="1324570517"]Your second question is very unclear. What would define if a message is appropriate?
    [/quote]

    I added this information because I wanted to make it obvious that the data has to come out in an exact format since other systems are watching. I don't have complete control over the data format on the wire.



  • Ok, let me try it the constructive way instead... maybe I asked the question in a bad way (or asked a bad question).

    I have a set of data that a user will input and will need to be transmitted across a network. Is there an elegant way of storing the definition of this data that facilitates easy GUI construction as well as data structures for my two programs?



  • Well, presumably you need to actually use this data at the other end of the communication, so at some point you have a requirement that you can access a particular variable in a particular name: that's got to be coded in one way or another. The fact is that you either have to maintain two independent descriptions of this data structure (one for constructing the GUI and one for actually using within the code), or you need to generate the GUI dynamically from the one in the code (which typically doesn't contain enough information to do a proper job).

    The way my software works is that every time I change my data input requirements (say by adding a new user input), I also modify an XML file that completely documents that variable's requirements, as well as some niceties like a bit of documentation. A simplistic column-of-widgets user interface can then be generated from that XML file. This has the added advantage of providing an automated way of generating simple documentation or the inputs, etc.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.