Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. [SOLVED] Qt functions from a DLL
Forum Update on Monday, May 27th 2025

[SOLVED] Qt functions from a DLL

Scheduled Pinned Locked Moved Language Bindings
3 Posts 2 Posters 1.6k Views
  • 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.
  • S Offline
    S Offline
    snoop911
    wrote on 21 Jul 2014, 00:14 last edited by
    #1

    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!

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jazzycamel
      wrote on 21 Jul 2014, 09:07 last edited by
      #2

      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)

      For the avoidance of doubt:

      1. All my code samples (C++ or Python) are tested before posting
      2. As of 23/03/20, my Python code is formatted to PEP-8 standards using black from the PSF (https://github.com/psf/black)
      1 Reply Last reply
      0
      • S Offline
        S Offline
        snoop911
        wrote on 28 Jul 2014, 23:47 last edited by
        #3

        Thanks! that worked!

        1 Reply Last reply
        0

        • Login

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