PDA

View Full Version : C library help please



K4ELO
16th November 2012, 00:54
Ok, I don't know C and I am a newbie to C++/Qt, so here is my problem.
I have a Qt program which works fine, until I try to link to a C library.

I put the required lines into the .pro file and the library appears to link just fine. No errors on compile/link.
Yes, I included the required C library .h files.
Now, how to properly call a function in the C library? This should be easy for you experts :)

In the C library header, we have: int (*rig_init) (RIG * rig); And the correct value for my rig is 32.
So in my mainwindow.h I put: int* rig;
Then in mainwindow.cpp I put: rig = rig_init(32);

And when I try to build, I get: mainwindow.cpp:238: error: cannot convert 'RIG*' to 'int*' in assignment

So, please help me out here and tell a newbie what I am doing wrong, and thanks!

ChrisW67
16th November 2012, 02:14
The function declaration you tell us about expects an argument of type pointer-to-RIG and returns an int. You are not using this AFAICT.

The function you are calling expects an int argument and returns a pointer-to-RIG. You are giving it an int argument and trying to force the RIG* into an int*.

Functions are from hamlib?

wysota
16th November 2012, 05:35
In other words it should probably be:


RIG rig;
int ok = rig_init(&rig);

amleto
16th November 2012, 10:08
more like


RIG rig;
int ok = (*rig_init)(&rig);

K4ELO
16th November 2012, 15:40
Thanks guys - I'll work on it. Yes Chris, the library is hamlib. Good docs on using the executables but I'm not finding any on using the library. I'm trying to use it with the logging program I wrote in Qt so I can support more than just my Flex radio.