Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Setting up PythonQt in Qt Creator on Arch Linux



  • Hello everyone,

    I'm struggeling setting up the PythonQt library in Qt Creator.
    So far, I installed pythonqt from the AUR and added the library to my .pro file, but the build fails with the following error:

    @[...]
    g++ -Wl,-O1,--sort-common,--as-needed,-z,relro -o PythonQtTest main.o -lPythonQt -lQt5Core -lpthread
    /usr/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../lib/libPythonQt.so: undefined reference to vtable for PythonQtWrapper_QWizard' Makefile:182: recipe for target 'PythonQtTest' failed /usr/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../lib/libPythonQt.so: undefined reference tovtable for PythonQtWrapper_QWizardPage'
    /usr/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../lib/libPythonQt.so: undefined reference to vtable for PythonQtWrapper_QWheelEvent' /usr/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../lib/libPythonQt.so: undefined reference tovtable for PythonQtWrapper_QWidgetAction'
    /usr/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../lib/libPythonQt.so: undefined reference to vtable for PythonQtWrapper_QWhatsThis' /usr/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../lib/libPythonQt.so: undefined reference tovtable for PythonQtWrapper_QVector4D'
    /usr/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../lib/libPythonQt.so: undefined reference to vtable for PythonQtWrapper_QWidget' /usr/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../lib/libPythonQt.so: undefined reference tovtable for PythonQtWrapper_QWindowsStyle'
    /usr/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../lib/libPythonQt.so: undefined reference to vtable for PythonQtWrapper_QVector2D' /usr/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../lib/libPythonQt.so: undefined reference tovtable for PythonQtWrapper_QWorkspace'
    /usr/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../lib/libPythonQt.so: undefined reference to vtable for PythonQtWrapper_QVector3D' /usr/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../lib/libPythonQt.so: undefined reference tovtable for PythonQtWrapper_QValidator'
    /usr/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../lib/libPythonQt.so: undefined reference to vtable for PythonQtWrapper_QWhatsThisClickedEvent' /usr/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../lib/libPythonQt.so: undefined reference tovtable for PythonQtWrapper_QWidgetItem'
    /usr/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../lib/libPythonQt.so: undefined reference to `vtable for PythonQtWrapper_QWindowStateChangeEvent'
    [...]@

    This is my .pro file:

    @
    QT += core

    QT -= gui

    TARGET = PythonQtTest
    CONFIG += console
    CONFIG -= app_bundle

    INCLUDEPATH += /usr/include/python2.7
    INCLUDEPATH += /usr/include/PythonQt

    TEMPLATE = app

    SOURCES += main.cpp

    HEADERS += PythonQt/PythonQt.h

    unix|win32: LIBS += -lPythonQt
    @

    And my main.cpp

    @
    #include <QCoreApplication>
    #include <PythonQt.h>

    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);

    PythonQt::init();
    
    PythonQtObjectPtr pythonContext = PythonQt::self()->getMainModule();
    pythonContext.evalScript("print 'Hello Python!';");
    
    return a.exec&#40;&#41;;
    

    }
    @

    Am I missing a certain include or library file? I already searched a lot on the Internet but I could not find a similar example.



  • Hi,

    undefined reference error refer to class included in QtWidget module.
    Try to modify your code in order to link Qt5Gui e Qt5Widgets



  • Hi, thanks for the quick reply.

    I changed my .pro file the following way:
    I removed

    @QT -= gui@

    and added

    @QT += widgets
    QT += gui@

    In main.cpp I added

    @#include <QtGui>
    #include <QtWidgets>@

    But there are still the same errors as before... :(



  • Ok it turned out that I tried to use a Qt 4.8 version of PythonQt with Qt 5.2.
    It also seems that unfortunately there aren't any builds for Qt 5 yet. Meh.



  • Hi,

    PyQt5 is built for Qt5 but requires Python 3.x



  • Thanks for the tip, but PyQt rather looks like a binding you would use to write your whole application in Python. I am going to write my application in C++ and wanted to make it Scriptable using PythonQt.
    Anyway, I'm looking at the Qt Script module again and I think I'll stick to this as it seems to provide the featues that I need.



  • Ok,

    if you want make an application Scriptable, the best (and the only Qt made) solution is to use QtScript module.

    As you stated PyQt task is to allow you to write the whole application in Python


Log in to reply