PDA

View Full Version : c++ library integration?



wabab
8th October 2010, 00:46
Hallo world!

Let's get to the point. We are about to start working with the creation of an advanced GUI interfacing a big complicated C++ library.
Our task is to represent every C++ routine as a module in the GUI and to enable users to make combinations of those module to produce a diferent output (depending on the modules combination) of the initial input.
The question is this: can we do this efficiently, without interfere with the library's routines' code? Just use their output?
And will those routines be compiled at once with the whole GUI project so we can feed them with data easily and check their outputs at any time?
Are we gonna need any code as glue between GUI and library?

Too many questions for a debute. Will come back with more :p

wysota
8th October 2010, 01:48
The question is this: can we do this efficiently, without interfere with the library's routines' code? Just use their output?
And will those routines be compiled at once with the whole GUI project so we can feed them with data easily and check their outputs at any time?
Are we gonna need any code as glue between GUI and library?
It's hard to answer any of those questions without knowing how the library works and what it does.

I can try to answer the last question -- you don't need any code to glue your library to Qt but it might be beneficial if you had a wrapper around your library to integrate it with Qt's API, especially its data structures and models.

wabab
8th October 2010, 12:22
Hi there...


It's hard to answer any of those questions without knowing how the library works and what it does.

The library is a series of pure C++ classes. Each class has a series of routines and each of them represents an electronic unit. It's a simulator. The user inputs the initial data (eg voltage, ...) and the routine produces the outcomes. I need to viualise this via a GUI. But C++ is not the ideal language for this. Here comes a simple routine example:


generic_unit* specific_generic_unit(const int min, const int* volt, const double energy)
{
int i;
if(min<=0)
{
printf("specific_generic_unit: problem.\n");
exit(1);
}
int M=1<<min;
double level=sqrt(energy);
double* sR = new double[2*M];

double off=32.53253245435/M;
for(i=0;i<M;i++)
{
sR[2*i] = level*cos(off*(1.+2.*i));
sR[2*i+1] = level*sin(off*(1.+2.*i));
}
generic_unit* temp=new generic_unit;
if (volt==(const int*)1)volt=[12,43,43,21];

temp->SetParameters(min,sR,volt,false);

delete[] sR;
return temp;
}

Have in mind that there will be multiple, different and complex type input and multiple output as well. I DON'T WANT TO INTERFERE with those routines' code. That's my critical question...Do I need something more than the Qt Suite. Won't it compile the whole thing, the C++ routines and the Qt gui code at the same project? I have no idea how to start at this point...how to connect my code with the GUI...Probably I haven't studied enough, or is this a Qt weakness?


I can try to answer the last question -- you don't need any code to glue your library to Qt but it might be beneficial if you had a wrapper around your library to integrate it with Qt's API, especially its data structures and models.

Some glue code? Beneficial coding is crucial as well. But if there is a need for glue code then we return to my first question about connecting directly Qt GUI with the C++ library at the sam Qt project. Are there any examples of such glue code?

wysota
8th October 2010, 12:44
Do I need something more than the Qt Suite.
No.


Won't it compile the whole thing, the C++ routines and the Qt gui code at the same project?
It will. Unless you don't want it to -- then you can make your pure C++ part a library and just link to it from the part written using Qt.

I have no idea how to start at this point...how to connect my code with the GUI...Probably I haven't studied enough, or is this a Qt weakness?
You have not studied enough :)


Some glue code? Beneficial coding is crucial as well. But if there is a need for glue code then we return to my first question about connecting directly Qt GUI with the C++ library at the sam Qt project. Are there any examples of such glue code?
For instance if have a routine that outputs an array of elements, then it is beneficial to wrap it into Qt API (i.e. to return "QList<Element>" instead of "Element*") and maybe make it object oriented at the same time as currently your code looks more like C than C++.
This is not something you have to do but Qt provides many routines (for instance "foreach" loop) that would be more efficient or simply would let your data be handled easier if the data conformed to Qt's API.

Wow... not that I look at it, your code is completely C-ish and not a pretty one, too. What does this do?

if (volt==(const int*)1)volt=[12,43,43,21];
Correct me if I'm wrong but this is an (incorrect, this condition will never return true) equivalent of:

if (*volt==1) volt= ??? [12];// is this pure ANSI/C99 C++? What does the [] construction do here?

You should make your code more C++-ish... Sorry for going off-topic, I always want to correct the world...

wabab
8th October 2010, 13:00
That's straightforward enough for me to go on. I guess I'll start some serious studying.

One question though: I can probably make a simple type casting for such situations ("QList<Element>" instead of "Element*")....



Wow... not that I look at it, your code is completely C-ish and not a pretty one, too. What does this do?

if (volt==(const int*)1)volt=[12,43,43,21];
Correct me if I'm wrong but this is an (incorrect, this condition will never return true) equivalent of:

if (*volt==1) volt= ??? [12];// is this pure ANSI/C99 C++? What does the [] construction do here?

You should make your code more C++-ish... Sorry for going off-topic, I always want to correct the world...

Haha...you did actually looked at it. I was trying to present a "generalised" code so I changed var names and stuff. The one you were looking with horror at and you are completely right was actually a const array's element, so by rush I made a representation of the whole const array instead of a single element of it (array[2]---->[23,323,43,23,...]:p) Anyway that's not my code so feel free to say anything :cool:

Let's sail on with this...