[PyQt] QString as a method argument using SIP 4.16 and PyQt5

Phil Thompson phil at riverbankcomputing.com
Fri Feb 6 14:08:21 GMT 2015


On 06/02/2015 1:50 pm, Morren, Earl wrote:
> Greetings all,
> 
> I'm new to this PyQT/SIP game, and I'm trying to call into a custom
> DLL from Python 3.4. The top-level class in my DLL (UDP_API) has a
> fairly simple interface:
> 
> // Begin udp_api.h
> #pragma once
> 
> #include "udp_api_global.h"
> 
> // "UDP_API" is just a "reference container" class
> // The actual API definitions are in the following headers...
> #include "command.h"            // class for commanding the backend via 
> the API
> #include "cyclic_data.h"          // class for reading status data
> #include "events.h"                  // class for setting up
> notification channels to handle events
> #include "device_io.h"
> #include "graph_pipeline.h"
> 
> class UDP_API_EXPORT UDP_API : public command, public cyclic_data,
> public events, public device_io, public graph_pipeline
> {
>     public:
>         UDP_API(QString backendAddress);    // This just takes an IP
> address for the back end (which gets passed on to each referenced
> class)
>         ~UDP_API();
>         bool LoadProgram(QString path, QString programName);
> };
> // End udp_api.h
> 
> The associated .sip file looks like so:
> 
> // Begin udp_api.sip// Define the SIP wrapper to the udp_api library.
> %Module udp_api
> 
> class UDP_API {
> 
> %TypeHeaderCode
> #include "udp_api.h"
> #include "command.h"
> #include "cyclic_data.h"
> #include "events.h"
> #include "device_io.h"
> #include "graph_pipeline.h"
> %End
> 
> public:
>     UDP_API(QString backendAddress);
>     bool LoadProgram(QString path, QString programName);
> };
> // End udp_api.sip
> 
> When I run my configure.py and get to the line:
>     os.system(" ".join([config.sip_bin, "-c", ".", "-b", build_file,
> "udp_api.sip"]))
> sip fails with the message:
>     sip: QString is undefined
> 
> I learned from my reading of the PyQt5 documentation that QString is
> not defined in PyQt/SIP for Python 3. What I'm not understanding is
> how to modify my .sip file to manage the QString argument types in my
> class interface. Do I need an alternate interface with something other
> than QString?
> 
> I'm running Python 3.4, Qt 5.3.2, PyQt5 5.3.2, SIP 4.16.5 on Windows
> 7. Compiler is MinGW 4.8.1.
> 
> The answer to this question has got to be simple, but I'm just not
> seeing it. Thanks in advance for any help.

You need to %Import the QtCoremod.sip file.

Phil


More information about the PyQt mailing list