Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to provide C callbacks in a library
Forum Updated to NodeBB v4.3 + New Features

How to provide C callbacks in a library

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 665 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • StokestackS Offline
    StokestackS Offline
    Stokestack
    wrote on last edited by
    #1

    Hey all,

    I don't have a ton of experience building libs. I was going to turn the core of my app into a static library, to re-use in some other projects. But the project includes vendor-provided SDK code (to interact with a piece of hardware) that needs to call C functions in the host app. Callbacks, I guess.

    Currently these functions are in main.cpp as extern "C". I'm trying to isolate all of the functionality that relies on them (and a bunch of other functionality, like DB access) in the lib, which can offer up C++ objects to be used by a Qt Quick GUI. Is this feasible?

    Thanks!

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      QML already expects you to do c++ back end for data and processing so
      calling some SDK function and collect data from the callbacks is absolutely feasible and
      also kinda expected in many use cases.
      So yes, hide the callbacks and C function behind c++ classes exposing the data to QML via
      properties or a model and it should work nicely.

      StokestackS 1 Reply Last reply
      3
      • mrjjM mrjj

        Hi
        QML already expects you to do c++ back end for data and processing so
        calling some SDK function and collect data from the callbacks is absolutely feasible and
        also kinda expected in many use cases.
        So yes, hide the callbacks and C function behind c++ classes exposing the data to QML via
        properties or a model and it should work nicely.

        StokestackS Offline
        StokestackS Offline
        Stokestack
        wrote on last edited by
        #3

        @mrjj Thanks, but the SDK is going to call C functions back. I don't know where to put the C functions in the library, because there's no main.cpp.

        aha_1980A 1 Reply Last reply
        0
        • StokestackS Stokestack

          @mrjj Thanks, but the SDK is going to call C functions back. I don't know where to put the C functions in the library, because there's no main.cpp.

          aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Stokestack then simply put them in another C++ file and declare them as extern C.

          Qt has to stay free or it will die.

          StokestackS 1 Reply Last reply
          3
          • aha_1980A aha_1980

            @Stokestack then simply put them in another C++ file and declare them as extern C.

            StokestackS Offline
            StokestackS Offline
            Stokestack
            wrote on last edited by
            #5

            @aha_1980 Thanks. I don't know why I was thinking this wouldn't work in a lib.

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved