Results 1 to 4 of 4

Thread: Returning a QString to a QLibrary

  1. #1
    Join Date
    Dec 2009
    Posts
    47
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default Returning a QString to a QLibrary

    I am using a shared library and load it using QLibrary. That requires that the functions be exported with extern "C". However, the function
    Qt Code:
    1. extern "C" QString objectName(long type);
    To copy to clipboard, switch view to plain text mode 
    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.

  2. #2
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Returning a QString to a QLibrary

    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.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  3. #3
    Join Date
    Oct 2009
    Posts
    6
    Thanked 2 Times in 2 Posts

    Default Re: Returning a QString to a QLibrary

    simple: you have to use char* and conversions like QString::toUtf8

  4. The following user says thank you to tdt for this useful post:

    johnmauer (14th February 2010)

  5. #4
    Join Date
    Dec 2009
    Posts
    47
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Returning a QString to a QLibrary

    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

Similar Threads

  1. QLibrary in PyQt
    By Urthas in forum Qt Programming
    Replies: 0
    Last Post: 30th October 2009, 18:46
  2. QLibrary resolve problem
    By Nippler in forum Qt Programming
    Replies: 0
    Last Post: 4th December 2008, 15:37
  3. Using Qlibrary on a function that uses arguments
    By schall_l in forum Qt Programming
    Replies: 8
    Last Post: 9th September 2008, 21:58
  4. The problem with QLibrary, help me!
    By dungsivn in forum Qt Programming
    Replies: 4
    Last Post: 17th January 2008, 14:03
  5. Qlibrary
    By rianquinn in forum Qt Programming
    Replies: 5
    Last Post: 4th February 2006, 12:23

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.