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

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Nicolas ELIE
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
_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: Cannot import type 'QMap<QString, QVariant>' from PyQt5.QtCore

Phil Thompson-5
On 4 Jul 2018, at 9:45 am, [hidden email] wrote:

>
> 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?

I can't reproduce the problem, although I am using a development versions of sip and PyQt. However I can't imagine how any changes would affect things in the way you describe.

I assume you are using the new -n flag to sip when generating your module. If you are obtaining the flags from QtCore.PYQT_CONFIGURATION['sip_flags'] then that should be automatic.

sip v4.19.12 will be released soon.

Phil

> 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
> _______________________________________________
> PyQt mailing list    [hidden email]
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt

_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt