Please nominate your Qt Champions for 2021!

[SOLVED] Qt functions from a DLL

  • I'm new to Qt and still very much learning python, so I'm wondering how difficult (or easy) would it be to go about creating a PyQt GUI application that calls functions from a standard 'C' dll?

    I know for standard VC++ applications, libraries may be linked statically or dynamically with my application, but with Python/PyQt it works differently, i.e it's an interpretive language (Just-In-Time compiling?)


  • This is actually very easy. Python is actually written is C and therefore has excellent facilities for accessing shared objects/DLL's. Consider the following C script:

    #include <stdio.h>

    extern int helloWorld(int a, int b){
    printf("Hello Python World from C!\n");
    return a+b;

    Which would be compiled to a shared object (for *nix) using GCC as follows:

    $ gcc -c -Wall -Werror -fpic helloworld.c
    $ gcc -shared -o helloworld.o

    Or for Windows as follows:


    gcc -Wall -Werror helloworld.c
    gcc -shared -o helloworld.dll helloworld.o

    To call our helloWorld() function from Python we would simply do the following:


    import ctypes
    Hello Python World from C!

    N.B. for Windows swap '' for 'helloworld.dll'.

    I hope this helps ;o)

  • Thanks! that worked!

Log in to reply