Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. invalid application of 'sizeof' to incomplete type 'QVariant'
Forum Update on Monday, May 27th 2025

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

Scheduled Pinned Locked Moved Solved QML and Qt Quick
qvariantlist qlqvarianterrorc++ and qml cod
3 Posts 2 Posters 7.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Elnur_Ismailzada
    wrote on 10 Oct 2017, 15:45 last edited by
    #1

    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)
    
    1 Reply Last reply
    0
    • H Offline
      H Offline
      hskoglund
      wrote on 10 Oct 2017, 16:08 last edited by
      #2

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

      E 1 Reply Last reply 10 Oct 2017, 17:12
      3
      • H hskoglund
        10 Oct 2017, 16:08

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

        E Offline
        E Offline
        Elnur_Ismailzada
        wrote on 10 Oct 2017, 17:12 last edited by Elnur_Ismailzada 10 Oct 2017, 17:13
        #3

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

        1 Reply Last reply
        0

        3/3

        10 Oct 2017, 17:12

        • Login

        • Login or register to search.
        3 out of 3
        • First post
          3/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved