[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?)
Thanks!
-
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:
helloworld.c
@
#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.so 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
hw=ctypes.cdll.LoadLibrary("helloworld.so")
hw.helloWorld(1,2)
Hello Python World from C!
3
@N.B. for Windows swap 'helloworld.so' for 'helloworld.dll'.
I hope this helps ;o)