[PyQt] Cannot import type 'QMap<QString, QVariant>' from PyQt5.QtCore

nicolaselie at free.fr nicolaselie at free.fr
Wed Jul 4 09:45:52 BST 2018


Dear list,

I am facing a issue with the newly released sip 4.19.11 and PyQt5 5.11.2
I am trying to wrap a custom Qt widget with sip to use it from Python.

Here is an example showing the problem:

// test.h
#ifndef TEST_H
#define TEST_H


#include <QMap>
#include <QVariant>

class Test
{
public:
    Test(QMap<QString,QVariant> map);

protected:
    QMap<QString,QVariant> m_map;
};

#endif // TEST_H


// test.cpp
#include "test.h"

Test::Test(QMap<QString,QVariant> map)
{
    m_map = map;
}

// test.sip
%Module(name=Test, call_super_init=True, keyword_arguments="Optional")
%DefaultSupertype sip.simplewrapper

%Import QtGui/QtGuimod.sip
%Import QtWidgets/QtWidgetsmod.sip
%Import QtCore/QtCoremod.sip

%If (Qt_5_0_0 -)

class Test {

%TypeHeaderCode
#include "test.h"
%End

public:
    Test(QMap<QString,QVariant> map);
};

%End


I can compile this into a pyd module but when I try to import it, it fails with the following error:
RuntimeError: Test cannot import type 'QMap<QString,QVariant>' from PyQt5.QtCore

This code compiles and import well when built against Qt 5.10.1 using PyQt 5.10.1 and sip 4.19.8 but fails with the above message when built against Qt 5.11.1 using PyQt 5.11.2 and sip 4.19.11.
I am using MSVC 2017 on Windows 7 64 bits and Python 3.6.1 64 bits.
Any idea what I am doing wrong?

Subsidiary question:
I had to change this line in sip's win32-msvc2015:
"QMAKE_CFLAGS= -nologo -Zm200 -Zc:wchar_t-"
into this
"QMAKE_CFLAGS= -nologo -Zm200 -Zc:wchar_t" (please note the missing minus at the end)
to be able to compile my library. Otherwise, I got errors about QChar being already declared.
Is this the good way to do it?


Regards,
Nicolas ELIE


More information about the PyQt mailing list