Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[SOLVED] Implementing C library in Qt GUI



  • Hi all,
    I have some C code containing functions that I would like to call from within a Qt GUI. I've seen some tutorials where the functions are defined within the Qt (C++) code itself, but since in my case these functions are already written in C, I would like to attach this C code as a library to the existing Qt Project. Is this the best way to proceed?
    I'm a true beginner with Qt, so if someone is willing to give me a high-level overview of the steps I should take, many thanks to you!
    Thanks in advance



  • The easiest, but maybe not the cleanest is to #include the .h file in the same .cpp of the class. Then just call the functions.

    Other alternative is to define an external function prototype and just link the object.

    A bit of googling around is better than posting and waiting for an answer, in 10s i found this:
    http://www.parashift.com/c++-faq-lite/mixing-c-and-cpp.html
    http://en.cppreference.com/w/cpp/keywords/extern



  • I've moved this to the C++ Gurus' forum, it's not Qt specific.

    Regarding the actual question, just follow the advice in the C++ FAQ on the link that EDIS already posted.

    Also have a look at "this older thread":http://developer.qt.nokia.com/forums/viewthread/8057 regarding the same topic.


Log in to reply