Embedded code in C, harness in Qt C++ delivering QTimer

  • I have a plain C project where I want to run some code for AVR XMEGA on the desktop. I have isolated/removed the lower HW layers. In the C code there is a real-time Scheduler [1]. Assume this works fine.

    But I need a timer, and I want Qt to later use for some more stuff.

    This scheduler has an "event loop" that on the AVR would sleep until next interrupt or timer interrupt. The timer interrupt is the next timeout, in multiples of ticks (10 ms).

    My first hit at this is make a library of the C code, all inclusive, making my_main callable. Also to have Scheduler callable, and it will return when it has nothing more to do, to then become retriggered by C++ QTimer.

    So I want Qt C++ with QTimer in another project.

    Q1. What type Qt project is best?

    Console app starts a "terminal window" and supplies its own event loop. I don't need that.

    QtQuick2 starts a window and terminates, which I could use to start my_main. But I don't need it.

    Let's say I used Console app and just commented away the code in there, and did my own stuff?

    Q2. How do I export my C library to be used by Qt C++?

    I have tried "import" and "include" (?), but I assume I must do some setup as well? I have asked here at work, but it seems they work in Qt only.

    Q3. Any example of this?

    I have searched! Is there a project setup somewhere that could hold my hand and take me into this room? I would need two projects I assume. To repeat, the main event loop is in my own C++ code (not hidden anywhere in a Qt object), and it will call Scheduler in C.

    Connecting QTimer's timeout to a function I also am somewhat uncertain about, if that should be a function of its own or like Tick or if I could use my own event loop (which calls Scheduler as mentioned).

    I am aware of QTimer help page and examples, and extern "C" and that stuff, but I am not able to stuff it correctly :-(

    [1] - "http://www.teigfam.net/oyvind/pub/pub_details.html#NewALT"

  • If I use this in the C library's .pro:

    @TARGET = main_AutroKeeper_Qt_PlainC # LIB
    TEMPLATE = lib # LIB
    CONFIG += staticlib # LIB@

    and in the lib header file:
    @#ifdef __cplusplus
    extern "C" {

    extern void main_AutroKeeper_Qt_PlainC (void);

    #ifdef __cplusplus

    and this in the C++ system's .pro that would use the lib above:

    @INCLUDEPATH += D:...\build-autrokeeper_Qt_plainC-AutroKeeper-Debug\debug
    DEPENDPATH += D:...\build-autrokeeper_Qt_plainC-AutroKeeper-Debug\debug

    LIBS += -LD:...\build-autrokeeper_Qt_plainC-AutroKeeper-Debug\debug -lmain_AutroKeeper_Qt_PlainC

    TEMPLATE = app@

    then C++ compiles and links and runs my C library.

    This included help from "http://stackoverflow.com/questions/10870145/qt-creator-using-external-libraries-within-my-own-library" plus a collegue.

    Obs no end '' in the paths to dirs.

    Was this ok?

    Now Q3 and QTimer are left. Since I have posted these questions, I feel obliged to tell if I solve it here? Is this etiquette here?

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.