invalid application of 'sizeof' to incomplete type 'QVariant'



  • Hi!
    I want to fill the combo box in qml from c++ class, but I have errors in the line return m_serialPortList;
    Any ideas?

    in SerialPortViewModel.h

    Q_PROPERTY(QVariantList serialPortList READ getSerialPortList CONSTANT)
    
    public:
        QVariantList getSerialPortList();
    private:
        QVariantList m_serialPortList;
    

    in SerialPortViewModel.cpp

    QVariantList SerialPortViewModel::getSerialPortList()
    {
        return m_serialPortList;
    }
    

    in main.cpp

    engine.rootContext()->setContextProperty("model", new SerialPortViewModel());
    

    in main.qml

    ComboBox {
             id: comboBoxSerialPorts
             model: model.serialPortList
    }
    

    error:

    In file included from C:\Qt\5.9.1\mingw53_32\include/QtCore/qglobal.h:1152:0,
                     from C:\Qt\5.9.1\mingw53_32\include/QtCore/qnamespace.h:43,
                     from C:\Qt\5.9.1\mingw53_32\include/QtCore/qobjectdefs.h:48,
                     from C:\Qt\5.9.1\mingw53_32\include\QtCore/qobject.h:46,
                     from C:\Qt\5.9.1\mingw53_32\include\QtCore/QObject:1,
                     from ..\..\HidBallast-QtQuick MVVM\HidBallast\serialportviewmodel.h:4,
                     from ..\..\HidBallast-QtQuick MVVM\HidBallast\serialportviewmodel.cpp:1:
    C:\Qt\5.9.1\mingw53_32\include/QtCore/qtypeinfo.h: In instantiation of 'class QTypeInfo<QVariant>':
    C:\Qt\5.9.1\mingw53_32\include/QtCore/qlist.h:459:31:   required from 'void QList<T>::node_copy(QList<T>::Node*, QList<T>::Node*, QList<T>::Node*) [with T = QVariant]'
    C:\Qt\5.9.1\mingw53_32\include/QtCore/qlist.h:813:22:   required from 'QList<T>::QList(const QList<T>&) [with T = QVariant]'
    ..\..\HidBallast-QtQuick MVVM\HidBallast\serialportviewmodel.cpp:5:12:   required from here
    C:\Qt\5.9.1\mingw53_32\include/QtCore/qtypeinfo.h:67:26: error: invalid application of 'sizeof' to incomplete type 'QVariant'
             isLarge = (sizeof(T)>sizeof(void*)),
                              ^
    C:\Qt\5.9.1\mingw53_32\include/QtCore/qtypeinfo.h:69:24: error: invalid application of 'sizeof' to incomplete type 'QVariant'
             sizeOf = sizeof(T)
                            ^
    In file included from C:\Qt\5.9.1\mingw53_32\include\QtCore/qobject.h:49:0,
                     from C:\Qt\5.9.1\mingw53_32\include\QtCore/QObject:1,
                     from ..\..\HidBallast-QtQuick MVVM\HidBallast\serialportviewmodel.h:4,
                     from ..\..\HidBallast-QtQuick MVVM\HidBallast\serialportviewmodel.cpp:1:
    C:\Qt\5.9.1\mingw53_32\include/QtCore/qlist.h: In instantiation of 'void QList<T>::node_copy(QList<T>::Node*, QList<T>::Node*, QList<T>::Node*) [with T = QVariant]':
    C:\Qt\5.9.1\mingw53_32\include/QtCore/qlist.h:813:22:   required from 'QList<T>::QList(const QList<T>&) [with T = QVariant]'
    ..\..\HidBallast-QtQuick MVVM\HidBallast\serialportviewmodel.cpp:5:12:   required from here
    C:\Qt\5.9.1\mingw53_32\include/QtCore/qlist.h:462:28: error: invalid use of incomplete type 'class QVariant'
                     current->v = new T(*reinterpret_cast<T*>(src->v));
                                ^
    In file included from C:\Qt\5.9.1\mingw53_32\include\QtCore/qobject.h:54:0,
                     from C:\Qt\5.9.1\mingw53_32\include\QtCore/QObject:1,
                     from ..\..\HidBallast-QtQuick MVVM\HidBallast\serialportviewmodel.h:4,
                     from ..\..\HidBallast-QtQuick MVVM\HidBallast\serialportviewmodel.cpp:1:
    C:\Qt\5.9.1\mingw53_32\include/QtCore/qmetatype.h:114:21: note: forward declaration of 'class QVariant'
         F(QVariant, 41, QVariant) \
                         ^
    C:\Qt\5.9.1\mingw53_32\include/QtCore/qmetatype.h:1879:11: note: in definition of macro 'QT_FORWARD_DECLARE_STATIC_TYPES_ITER'
         class Name;
               ^
    C:\Qt\5.9.1\mingw53_32\include/QtCore/qmetatype.h:1881:1: note: in expansion of macro 'QT_FOR_EACH_STATIC_CORE_CLASS'
     QT_FOR_EACH_STATIC_CORE_CLASS(QT_FORWARD_DECLARE_STATIC_TYPES_ITER)
    


  • Hi, try #include <QVariant> in your SerialPortViewModel.h



  • @hskoglund thank you so much!!!
    I import <QVarianList> and it solved my problem.



Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.