PDA

View Full Version : Returning a QString to a QLibrary



johnmauer
13th February 2010, 22:35
I am using a shared library and load it using QLibrary. That requires that the functions be exported with extern "C". However, the function

extern "C" QString objectName(long type);
gets a compiler warning

'objectName' has C-linkage specified, but returns UDT 'QString' which is incompatible with C
Is there a way to export a QString return from a shared library? I would prefer not defeating a really good class like QString.

faldzip
14th February 2010, 00:06
It is because of 'extern "C"'. Why do you need this extern C? As the error says you can't use QString as it is not compatible with C which is totally right as QString is a class.

tdt
14th February 2010, 08:29
simple: you have to use char* and conversions like QString::toUtf8

johnmauer
14th February 2010, 12:27
Yes, I've used the dual conversion already. I was just hoping that there was a better to export it; QLibrary could have been written to resolve the transformation. Thanks