Important: Please read the Qt Code of Conduct -

Cannot include <QVector3D>

  • I am trying to pass a Qt.vector3d() from QML to c++. In my c++ class, as soon as I type in the

    #include <QVector3D>

    QtCreator shows the following error regardless of whether the .pro file has += gui

    qvector3d.h:57:20: error: redefinition of 'QVector3D'
    Test.h:1:1: note: in file included from ...\Testing\untitled20\Test.h:1:
    Test.h:5:10: note: in file included from ...\Testing\untitled20\Test.h:5:
    QVector3D:1:10: note: in file included from C:\Qt\Qt5.13.0\5.13.0\msvc2017_64\include\QtGui\QVector3D:1:
    qpoint.h:219:21: note: previous definition is here

    To Reproduce on my system

    I can reproduce this consistently. I am using Qt 5.13 on Windows.

    • Start with empty QtQuick application template.
    • Add a QObject derived class using the Add class wizard.
    • Add the include file for QVector3D.


    #ifndef TEST_H
    #define TEST_H
    #include <QObject>
    #include <QVector3D>
    class Test : public QObject
        explicit Test(QObject *parent = nullptr);
    public slots:
    #endif // TEST_H

    Even if I start with a Qt Form application, I get the same error as soon as I include <QVector3D> in any source file. There is another declaration for QVector3D in the qpoint.h header that is being favored even though it only holds two elements, x and y.

    How can I get Qt.vector3d data when I can't even get a class with 3 elements to catch it? Why is this other mislabeled class taking over?

    Thanks for mulling this one over!

  • Qt Champions 2019

    You have a (modified) qpoint.h somewhere - the original qpoint.h does not defined a QVector3D class:

  • UPDATE: If you don't include the header, the vector3d is passed from QML to C++ as the correct QVector3D. However, you can't access any of the correct methods for this version of QVector3D which in turn means you cannot extract the third component of the vector as only x and y are exposed in the qpoint.h version of QVector3D.

    The question remains,

    How does one access the correct signatures for QVector3D methods on the C++ side of a QML/C++ application?

  • Qt Champions 2019

    You have a (modified) qpoint.h somewhere - the original qpoint.h does not defined a QVector3D class:

  • @Christian-Ehrlicher
    Do you know of any automated Qt tools that would do this during compilation?

    I checked the install files, and a batch of them had been modified as of this morning when I first noticed the problem.

    <rant>The Qt installer on Windows is the worst. No option to fix the installation, and I have to upgrade the installer in order to be able to see any options that might remotely be like "fix installation". And as far as I can tell you can't do anything with it if you are not connected to the network.</rant>

    On the non-rant side, the Qt/QML framework is hands down my favorite for C++ applications.

Log in to reply