[PyQt] SIP with PyQt5 and "A More Complex C++ Example"

bitmap kid bitmap.kid at gmail.com
Sat Mar 23 12:18:42 GMT 2019


Maybe, the complete history of my commands will help you:



[th at mecanic ~/sip] ls
hello.cpp  hello.h  hello.sip  main.cpp
[th at mecanic ~/sip] sip -t WS_X11 -I /usr/share/sip/PyQt5 -c . hello.sip
[th at mecanic ~/sip]  /usr/bin/g++  -DDEBUG -DHOST -DQT_CORE_LIB -DQT_GUI_LIB
-Dserver_EXPORTS -I. -I../ -Iserver_autogen/include -I../.
-I/usr/include/python3.7m  -isystem /usr/include/qt -isystem
/usr/include/qt/QtCore -isystem /usr/lib/qt/mkspecs/linux-g++ -g -fPIC
-Wall -pedantic -fPIC -std=gnu++17 -MD -I /usr/include/qt/QtWidgets/ -I
/usr/include/qt/QtGui/ -c *.cpp
./siphellocmodule.cpp: Dans la fonction « PyObject*
func_setDefault(PyObject*, PyObject*) »:
./siphellocmodule.cpp:438:13: error: « setDefault » n'a pas été déclaré
dans cette portée
             setDefault(*a0);
             ^~~~~~~~~~
./siphellocmodule.cpp:438:13: note: alternatives suggérées:
« func_setDefault »
             setDefault(*a0);
             ^~~~~~~~~~
             func_setDefault



Le sam. 23 mars 2019 à 13:09, bitmap kid <bitmap.kid at gmail.com> a écrit :

> Oh obviously !
>
> hello.h ================================================
> #ifndef HELLO_H
> #define HELLO_H
> #include <QLabel>
> #include <QWidget>
> #include <QString>
>
> class Hello : public QLabel {
>     // This is needed by the Qt Meta-Object Compiler.
>     Q_OBJECT
>
> public:
>     Hello(QWidget *parent = 0);
>
> private:
>     // Prevent instances from being copied.
>     Hello(const Hello &);
>     Hello &operator=(const Hello &);
> };
>
> #if !defined(Q_OS_WIN)
> void setDefault(const QString &def);
> #endif
> #endif // HELLO_H
>
> hello.cpp ================================================
> #include "hello.h"
>
> Hello::Hello(QWidget *parent): QLabel(parent) {}
> Hello::Hello(const Hello &other) { (void) other; }
> Hello &Hello::operator=(const Hello &other) { (void) other; return *this; }
>
> #if !defined(Q_OS_WIN)
> void setDefault(const QString &def) { (void) def; }
> #endif
>
> hello.sip ================================================
> // Define the SIP wrapper to the hello library.
>
> %Module hello
>
> %Import QtGui/QtGuimod.sip
> %Import QtWidgets/QtWidgetsmod.sip
>
> %If (Qt_5_0_0 -)
>
> class Hello : public QLabel {
>
> %TypeHeaderCode
> #include <hello.h>
> %End
>
> public:
>     Hello(QWidget *parent /TransferThis/ = 0);
>
> private:
>     Hello(const Hello &);
> };
>
> %If (!WS_WIN)
> void setDefault(const QString &def);
> %End
>
> %End
>
>
>
>
>
> Le sam. 23 mars 2019 à 13:05, Phil Thompson <phil at riverbankcomputing.com>
> a écrit :
>
>> On 23 Mar 2019, at 11:46 am, bitmap kid <bitmap.kid at gmail.com> wrote:
>> >
>> > Bonjour,
>> >
>> > I'm trying to make the example "A More Complex C++ Example" given in
>> the documentation. But I'm having trouble with the setDefault function.
>> >
>> > Once the sources generated with the sip command, when I compile, the
>> compiler says:
>> >
>> > ./siphellocmodule.cpp:438:13: error: "setDefault" was not declared in
>> this scope.
>> >               setDefault (* a0);
>> >
>> > Indeed, the siphellocmodule.cpp file refers to the setDefault function
>> but does not include hello.h
>> >
>> > Do you have an idea of where the problem is?
>> >
>> > Please, note :
>> > I am using PyQt5 5.12.1 and SIP 4.19.5.
>> > My project consists of hello.h, hello.cpp and hello.sip files
>> > My sip command is "sip -t WS_X11 -I /usr/share/sip/PyQt5 -c.hello.sip"
>> > It generates the following files:
>> >
>> >     sipAPIhello.h
>> >     siphelloHello.cpp
>> >     siphellocmodule.cpp
>> >
>> > And commenting the setDefault function build the project correctly.
>>
>> Difficult to say without seeing your hello.h, hello.cpp and hello.sip.
>>
>> Phil
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20190323/d6b814b4/attachment-0001.html>


More information about the PyQt mailing list