Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Moc compilation error
Forum Updated to NodeBB v4.3 + New Features

Moc compilation error

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 1.5k Views 1 Watching
  • 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.
  • Y Offline
    Y Offline
    Ylvy
    wrote on last edited by Ylvy
    #1

    Why when i modify
    void setText(const QString& text)
    to
    void setText(const QString& text, QString text_2)

    It doesnt compile anymore? getting this error:

    1>Build FAILED.
    1>
    1>x64\Debug\moc\moc_test.cpp(168,19): error C2660: 'Test::setText': function does not take 1 arguments
    
    class Test : public QObject
    {
        Q_OBJECT
        Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
    
    public:
        QString text() { return ""; }
    
    public slots:
        void setText(const QString& text, const QString& text_2) 
        {
        }
    signals:
        void textChanged(const QString& text);
    };
    
    JoeCFDJ 1 Reply Last reply
    0
    • Y Ylvy

      Why when i modify
      void setText(const QString& text)
      to
      void setText(const QString& text, QString text_2)

      It doesnt compile anymore? getting this error:

      1>Build FAILED.
      1>
      1>x64\Debug\moc\moc_test.cpp(168,19): error C2660: 'Test::setText': function does not take 1 arguments
      
      class Test : public QObject
      {
          Q_OBJECT
          Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
      
      public:
          QString text() { return ""; }
      
      public slots:
          void setText(const QString& text, const QString& text_2) 
          {
          }
      signals:
          void textChanged(const QString& text);
      };
      
      JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by
      #2

      @Ylvy make clean or make distclean with pro file.
      Rebuild your project.

      Y 1 Reply Last reply
      0
      • JoeCFDJ JoeCFD

        @Ylvy make clean or make distclean with pro file.
        Rebuild your project.

        Y Offline
        Y Offline
        Ylvy
        wrote on last edited by Ylvy
        #3

        @JoeCFD Already tried it multiple times.

        Commenting: Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
        It does compile, when the function expect more than one argument i need to modify something in the Q_PROPERTY WRITE setText?

        /****************************************************************************
        ** Meta object code from reading C++ file 'test.h'
        **
        ** Created by: The Qt Meta Object Compiler version 68 (Qt 6.5.0)
        **
        ** WARNING! All changes made in this file will be lost!
        *****************************************************************************/
        
        #include "stdafx.h"
        #include "../../../test.h"
        #include <QtGui/qtextcursor.h>
        #include <QScreen>
        #include <QtCore/qmetatype.h>
        
        #if __has_include(<QtCore/qtmochelpers.h>)
        #include <QtCore/qtmochelpers.h>
        #else
        QT_BEGIN_MOC_NAMESPACE
        #endif
        
        
        #include <memory>
        
        #if !defined(Q_MOC_OUTPUT_REVISION)
        #error "The header file 'test.h' doesn't include <QObject>."
        #elif Q_MOC_OUTPUT_REVISION != 68
        #error "This file was generated using the moc from 6.5.0. It"
        #error "cannot be used with the include files from this version of Qt."
        #error "(The moc has changed too much.)"
        #endif
        
        #ifndef Q_CONSTINIT
        #define Q_CONSTINIT
        #endif
        
        QT_WARNING_PUSH
        QT_WARNING_DISABLE_DEPRECATED
        QT_WARNING_DISABLE_GCC("-Wuseless-cast")
        namespace {
        
        #ifdef QT_MOC_HAS_STRINGDATA
        struct qt_meta_stringdata_CLASSTestENDCLASS_t {};
        static constexpr auto qt_meta_stringdata_CLASSTestENDCLASS = QtMocHelpers::stringData(
            "Test",
            "textChanged",
            "",
            "text",
            "setText",
            "text_2"
        );
        #else  // !QT_MOC_HAS_STRING_DATA
        struct qt_meta_stringdata_CLASSTestENDCLASS_t {
            uint offsetsAndSizes[12];
            char stringdata0[5];
            char stringdata1[12];
            char stringdata2[1];
            char stringdata3[5];
            char stringdata4[8];
            char stringdata5[7];
        };
        #define QT_MOC_LITERAL(ofs, len) \
            uint(sizeof(qt_meta_stringdata_CLASSTestENDCLASS_t::offsetsAndSizes) + ofs), len 
        Q_CONSTINIT static const qt_meta_stringdata_CLASSTestENDCLASS_t qt_meta_stringdata_CLASSTestENDCLASS = {
            {
                QT_MOC_LITERAL(0, 4),  // "Test"
                QT_MOC_LITERAL(5, 11),  // "textChanged"
                QT_MOC_LITERAL(17, 0),  // ""
                QT_MOC_LITERAL(18, 4),  // "text"
                QT_MOC_LITERAL(23, 7),  // "setText"
                QT_MOC_LITERAL(31, 6)   // "text_2"
            },
            "Test",
            "textChanged",
            "",
            "text",
            "setText",
            "text_2"
        };
        #undef QT_MOC_LITERAL
        #endif // !QT_MOC_HAS_STRING_DATA
        } // unnamed namespace
        
        Q_CONSTINIT static const uint qt_meta_data_CLASSTestENDCLASS[] = {
        
         // content:
              11,       // revision
               0,       // classname
               0,    0, // classinfo
               2,   14, // methods
               1,   34, // properties
               0,    0, // enums/sets
               0,    0, // constructors
               0,       // flags
               1,       // signalCount
        
         // signals: name, argc, parameters, tag, flags, initial metatype offsets
               1,    1,   26,    2, 0x06,    2 /* Public */,
        
         // slots: name, argc, parameters, tag, flags, initial metatype offsets
               4,    2,   29,    2, 0x0a,    4 /* Public */,
        
         // signals: parameters
            QMetaType::Void, QMetaType::QString,    3,
        
         // slots: parameters
            QMetaType::Void, QMetaType::QString, QMetaType::QString,    3,    5,
        
         // properties: name, type, flags
               3, QMetaType::QString, 0x00015103, uint(0), 0,
        
               0        // eod
        };
        
        Q_CONSTINIT const QMetaObject Test::staticMetaObject = { {
            QMetaObject::SuperData::link<QObject::staticMetaObject>(),
            qt_meta_stringdata_CLASSTestENDCLASS.offsetsAndSizes,
            qt_meta_data_CLASSTestENDCLASS,
            qt_static_metacall,
            nullptr,
            qt_incomplete_metaTypeArray<qt_meta_stringdata_CLASSTestENDCLASS_t,
                // property 'text'
                QtPrivate::TypeAndForceComplete<QString, std::true_type>,
                // Q_OBJECT / Q_GADGET
                QtPrivate::TypeAndForceComplete<Test, std::true_type>,
                // method 'textChanged'
                QtPrivate::TypeAndForceComplete<void, std::false_type>,
                QtPrivate::TypeAndForceComplete<const QString &, std::false_type>,
                // method 'setText'
                QtPrivate::TypeAndForceComplete<void, std::false_type>,
                QtPrivate::TypeAndForceComplete<const QString &, std::false_type>,
                QtPrivate::TypeAndForceComplete<const QString &, std::false_type>
            >,
            nullptr
        } };
        
        void Test::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
        {
            if (_c == QMetaObject::InvokeMetaMethod) {
                auto *_t = static_cast<Test *>(_o);
                (void)_t;
                switch (_id) {
                case 0: _t->textChanged((*reinterpret_cast< std::add_pointer_t<QString>>(_a[1]))); break;
                case 1: _t->setText((*reinterpret_cast< std::add_pointer_t<QString>>(_a[1])),(*reinterpret_cast< std::add_pointer_t<QString>>(_a[2]))); break;
                default: ;
                }
            } else if (_c == QMetaObject::IndexOfMethod) {
                int *result = reinterpret_cast<int *>(_a[0]);
                {
                    using _t = void (Test::*)(const QString & );
                    if (_t _q_method = &Test::textChanged; *reinterpret_cast<_t *>(_a[1]) == _q_method) {
                        *result = 0;
                        return;
                    }
                }
            }else if (_c == QMetaObject::ReadProperty) {
                auto *_t = static_cast<Test *>(_o);
                (void)_t;
                void *_v = _a[0];
                switch (_id) {
                case 0: *reinterpret_cast< QString*>(_v) = _t->text(); break;
                default: break;
                }
            } else if (_c == QMetaObject::WriteProperty) {
                auto *_t = static_cast<Test *>(_o);
                (void)_t;
                void *_v = _a[0];
                switch (_id) {
                case 0: _t->setText(*reinterpret_cast< QString*>(_v)); break;
                default: break;
                }
            } else if (_c == QMetaObject::ResetProperty) {
            } else if (_c == QMetaObject::BindableProperty) {
            }
        }
        
        const QMetaObject *Test::metaObject() const
        {
            return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
        }
        
        void *Test::qt_metacast(const char *_clname)
        {
            if (!_clname) return nullptr;
            if (!strcmp(_clname, qt_meta_stringdata_CLASSTestENDCLASS.stringdata0))
                return static_cast<void*>(this);
            return QObject::qt_metacast(_clname);
        }
        
        int Test::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
        {
            _id = QObject::qt_metacall(_c, _id, _a);
            if (_id < 0)
                return _id;
            if (_c == QMetaObject::InvokeMetaMethod) {
                if (_id < 2)
                    qt_static_metacall(this, _c, _id, _a);
                _id -= 2;
            } else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
                if (_id < 2)
                    *reinterpret_cast<QMetaType *>(_a[0]) = QMetaType();
                _id -= 2;
            }else if (_c == QMetaObject::ReadProperty || _c == QMetaObject::WriteProperty
                    || _c == QMetaObject::ResetProperty || _c == QMetaObject::BindableProperty
                    || _c == QMetaObject::RegisterPropertyMetaType) {
                qt_static_metacall(this, _c, _id, _a);
                _id -= 1;
            }
            return _id;
        }
        
        // SIGNAL 0
        void Test::textChanged(const QString & _t1)
        {
            void *_a[] = { nullptr, const_cast<void*>(reinterpret_cast<const void*>(std::addressof(_t1))) };
            QMetaObject::activate(this, &staticMetaObject, 0, _a);
        }
        QT_WARNING_POP
        
        

        The error is at this line case 0: _t->setText(*reinterpret_cast< QString*>(_v)); break;
        is this a bug from the auto-generated moc file?

        JoeCFDJ JonBJ 2 Replies Last reply
        0
        • Y Ylvy

          @JoeCFD Already tried it multiple times.

          Commenting: Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
          It does compile, when the function expect more than one argument i need to modify something in the Q_PROPERTY WRITE setText?

          /****************************************************************************
          ** Meta object code from reading C++ file 'test.h'
          **
          ** Created by: The Qt Meta Object Compiler version 68 (Qt 6.5.0)
          **
          ** WARNING! All changes made in this file will be lost!
          *****************************************************************************/
          
          #include "stdafx.h"
          #include "../../../test.h"
          #include <QtGui/qtextcursor.h>
          #include <QScreen>
          #include <QtCore/qmetatype.h>
          
          #if __has_include(<QtCore/qtmochelpers.h>)
          #include <QtCore/qtmochelpers.h>
          #else
          QT_BEGIN_MOC_NAMESPACE
          #endif
          
          
          #include <memory>
          
          #if !defined(Q_MOC_OUTPUT_REVISION)
          #error "The header file 'test.h' doesn't include <QObject>."
          #elif Q_MOC_OUTPUT_REVISION != 68
          #error "This file was generated using the moc from 6.5.0. It"
          #error "cannot be used with the include files from this version of Qt."
          #error "(The moc has changed too much.)"
          #endif
          
          #ifndef Q_CONSTINIT
          #define Q_CONSTINIT
          #endif
          
          QT_WARNING_PUSH
          QT_WARNING_DISABLE_DEPRECATED
          QT_WARNING_DISABLE_GCC("-Wuseless-cast")
          namespace {
          
          #ifdef QT_MOC_HAS_STRINGDATA
          struct qt_meta_stringdata_CLASSTestENDCLASS_t {};
          static constexpr auto qt_meta_stringdata_CLASSTestENDCLASS = QtMocHelpers::stringData(
              "Test",
              "textChanged",
              "",
              "text",
              "setText",
              "text_2"
          );
          #else  // !QT_MOC_HAS_STRING_DATA
          struct qt_meta_stringdata_CLASSTestENDCLASS_t {
              uint offsetsAndSizes[12];
              char stringdata0[5];
              char stringdata1[12];
              char stringdata2[1];
              char stringdata3[5];
              char stringdata4[8];
              char stringdata5[7];
          };
          #define QT_MOC_LITERAL(ofs, len) \
              uint(sizeof(qt_meta_stringdata_CLASSTestENDCLASS_t::offsetsAndSizes) + ofs), len 
          Q_CONSTINIT static const qt_meta_stringdata_CLASSTestENDCLASS_t qt_meta_stringdata_CLASSTestENDCLASS = {
              {
                  QT_MOC_LITERAL(0, 4),  // "Test"
                  QT_MOC_LITERAL(5, 11),  // "textChanged"
                  QT_MOC_LITERAL(17, 0),  // ""
                  QT_MOC_LITERAL(18, 4),  // "text"
                  QT_MOC_LITERAL(23, 7),  // "setText"
                  QT_MOC_LITERAL(31, 6)   // "text_2"
              },
              "Test",
              "textChanged",
              "",
              "text",
              "setText",
              "text_2"
          };
          #undef QT_MOC_LITERAL
          #endif // !QT_MOC_HAS_STRING_DATA
          } // unnamed namespace
          
          Q_CONSTINIT static const uint qt_meta_data_CLASSTestENDCLASS[] = {
          
           // content:
                11,       // revision
                 0,       // classname
                 0,    0, // classinfo
                 2,   14, // methods
                 1,   34, // properties
                 0,    0, // enums/sets
                 0,    0, // constructors
                 0,       // flags
                 1,       // signalCount
          
           // signals: name, argc, parameters, tag, flags, initial metatype offsets
                 1,    1,   26,    2, 0x06,    2 /* Public */,
          
           // slots: name, argc, parameters, tag, flags, initial metatype offsets
                 4,    2,   29,    2, 0x0a,    4 /* Public */,
          
           // signals: parameters
              QMetaType::Void, QMetaType::QString,    3,
          
           // slots: parameters
              QMetaType::Void, QMetaType::QString, QMetaType::QString,    3,    5,
          
           // properties: name, type, flags
                 3, QMetaType::QString, 0x00015103, uint(0), 0,
          
                 0        // eod
          };
          
          Q_CONSTINIT const QMetaObject Test::staticMetaObject = { {
              QMetaObject::SuperData::link<QObject::staticMetaObject>(),
              qt_meta_stringdata_CLASSTestENDCLASS.offsetsAndSizes,
              qt_meta_data_CLASSTestENDCLASS,
              qt_static_metacall,
              nullptr,
              qt_incomplete_metaTypeArray<qt_meta_stringdata_CLASSTestENDCLASS_t,
                  // property 'text'
                  QtPrivate::TypeAndForceComplete<QString, std::true_type>,
                  // Q_OBJECT / Q_GADGET
                  QtPrivate::TypeAndForceComplete<Test, std::true_type>,
                  // method 'textChanged'
                  QtPrivate::TypeAndForceComplete<void, std::false_type>,
                  QtPrivate::TypeAndForceComplete<const QString &, std::false_type>,
                  // method 'setText'
                  QtPrivate::TypeAndForceComplete<void, std::false_type>,
                  QtPrivate::TypeAndForceComplete<const QString &, std::false_type>,
                  QtPrivate::TypeAndForceComplete<const QString &, std::false_type>
              >,
              nullptr
          } };
          
          void Test::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
          {
              if (_c == QMetaObject::InvokeMetaMethod) {
                  auto *_t = static_cast<Test *>(_o);
                  (void)_t;
                  switch (_id) {
                  case 0: _t->textChanged((*reinterpret_cast< std::add_pointer_t<QString>>(_a[1]))); break;
                  case 1: _t->setText((*reinterpret_cast< std::add_pointer_t<QString>>(_a[1])),(*reinterpret_cast< std::add_pointer_t<QString>>(_a[2]))); break;
                  default: ;
                  }
              } else if (_c == QMetaObject::IndexOfMethod) {
                  int *result = reinterpret_cast<int *>(_a[0]);
                  {
                      using _t = void (Test::*)(const QString & );
                      if (_t _q_method = &Test::textChanged; *reinterpret_cast<_t *>(_a[1]) == _q_method) {
                          *result = 0;
                          return;
                      }
                  }
              }else if (_c == QMetaObject::ReadProperty) {
                  auto *_t = static_cast<Test *>(_o);
                  (void)_t;
                  void *_v = _a[0];
                  switch (_id) {
                  case 0: *reinterpret_cast< QString*>(_v) = _t->text(); break;
                  default: break;
                  }
              } else if (_c == QMetaObject::WriteProperty) {
                  auto *_t = static_cast<Test *>(_o);
                  (void)_t;
                  void *_v = _a[0];
                  switch (_id) {
                  case 0: _t->setText(*reinterpret_cast< QString*>(_v)); break;
                  default: break;
                  }
              } else if (_c == QMetaObject::ResetProperty) {
              } else if (_c == QMetaObject::BindableProperty) {
              }
          }
          
          const QMetaObject *Test::metaObject() const
          {
              return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
          }
          
          void *Test::qt_metacast(const char *_clname)
          {
              if (!_clname) return nullptr;
              if (!strcmp(_clname, qt_meta_stringdata_CLASSTestENDCLASS.stringdata0))
                  return static_cast<void*>(this);
              return QObject::qt_metacast(_clname);
          }
          
          int Test::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
          {
              _id = QObject::qt_metacall(_c, _id, _a);
              if (_id < 0)
                  return _id;
              if (_c == QMetaObject::InvokeMetaMethod) {
                  if (_id < 2)
                      qt_static_metacall(this, _c, _id, _a);
                  _id -= 2;
              } else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
                  if (_id < 2)
                      *reinterpret_cast<QMetaType *>(_a[0]) = QMetaType();
                  _id -= 2;
              }else if (_c == QMetaObject::ReadProperty || _c == QMetaObject::WriteProperty
                      || _c == QMetaObject::ResetProperty || _c == QMetaObject::BindableProperty
                      || _c == QMetaObject::RegisterPropertyMetaType) {
                  qt_static_metacall(this, _c, _id, _a);
                  _id -= 1;
              }
              return _id;
          }
          
          // SIGNAL 0
          void Test::textChanged(const QString & _t1)
          {
              void *_a[] = { nullptr, const_cast<void*>(reinterpret_cast<const void*>(std::addressof(_t1))) };
              QMetaObject::activate(this, &staticMetaObject, 0, _a);
          }
          QT_WARNING_POP
          
          

          The error is at this line case 0: _t->setText(*reinterpret_cast< QString*>(_v)); break;
          is this a bug from the auto-generated moc file?

          JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by JoeCFD
          #4

          @Ylvy I thought about that as well. setText Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) needs one argument. You can define two funcs

          public slots:
              void setText(const QString& text, const QString& text_2) 
              {
              }   
          
              void setText(const QString& text ) 
               {
               }
          
          1 Reply Last reply
          0
          • Y Ylvy

            @JoeCFD Already tried it multiple times.

            Commenting: Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
            It does compile, when the function expect more than one argument i need to modify something in the Q_PROPERTY WRITE setText?

            /****************************************************************************
            ** Meta object code from reading C++ file 'test.h'
            **
            ** Created by: The Qt Meta Object Compiler version 68 (Qt 6.5.0)
            **
            ** WARNING! All changes made in this file will be lost!
            *****************************************************************************/
            
            #include "stdafx.h"
            #include "../../../test.h"
            #include <QtGui/qtextcursor.h>
            #include <QScreen>
            #include <QtCore/qmetatype.h>
            
            #if __has_include(<QtCore/qtmochelpers.h>)
            #include <QtCore/qtmochelpers.h>
            #else
            QT_BEGIN_MOC_NAMESPACE
            #endif
            
            
            #include <memory>
            
            #if !defined(Q_MOC_OUTPUT_REVISION)
            #error "The header file 'test.h' doesn't include <QObject>."
            #elif Q_MOC_OUTPUT_REVISION != 68
            #error "This file was generated using the moc from 6.5.0. It"
            #error "cannot be used with the include files from this version of Qt."
            #error "(The moc has changed too much.)"
            #endif
            
            #ifndef Q_CONSTINIT
            #define Q_CONSTINIT
            #endif
            
            QT_WARNING_PUSH
            QT_WARNING_DISABLE_DEPRECATED
            QT_WARNING_DISABLE_GCC("-Wuseless-cast")
            namespace {
            
            #ifdef QT_MOC_HAS_STRINGDATA
            struct qt_meta_stringdata_CLASSTestENDCLASS_t {};
            static constexpr auto qt_meta_stringdata_CLASSTestENDCLASS = QtMocHelpers::stringData(
                "Test",
                "textChanged",
                "",
                "text",
                "setText",
                "text_2"
            );
            #else  // !QT_MOC_HAS_STRING_DATA
            struct qt_meta_stringdata_CLASSTestENDCLASS_t {
                uint offsetsAndSizes[12];
                char stringdata0[5];
                char stringdata1[12];
                char stringdata2[1];
                char stringdata3[5];
                char stringdata4[8];
                char stringdata5[7];
            };
            #define QT_MOC_LITERAL(ofs, len) \
                uint(sizeof(qt_meta_stringdata_CLASSTestENDCLASS_t::offsetsAndSizes) + ofs), len 
            Q_CONSTINIT static const qt_meta_stringdata_CLASSTestENDCLASS_t qt_meta_stringdata_CLASSTestENDCLASS = {
                {
                    QT_MOC_LITERAL(0, 4),  // "Test"
                    QT_MOC_LITERAL(5, 11),  // "textChanged"
                    QT_MOC_LITERAL(17, 0),  // ""
                    QT_MOC_LITERAL(18, 4),  // "text"
                    QT_MOC_LITERAL(23, 7),  // "setText"
                    QT_MOC_LITERAL(31, 6)   // "text_2"
                },
                "Test",
                "textChanged",
                "",
                "text",
                "setText",
                "text_2"
            };
            #undef QT_MOC_LITERAL
            #endif // !QT_MOC_HAS_STRING_DATA
            } // unnamed namespace
            
            Q_CONSTINIT static const uint qt_meta_data_CLASSTestENDCLASS[] = {
            
             // content:
                  11,       // revision
                   0,       // classname
                   0,    0, // classinfo
                   2,   14, // methods
                   1,   34, // properties
                   0,    0, // enums/sets
                   0,    0, // constructors
                   0,       // flags
                   1,       // signalCount
            
             // signals: name, argc, parameters, tag, flags, initial metatype offsets
                   1,    1,   26,    2, 0x06,    2 /* Public */,
            
             // slots: name, argc, parameters, tag, flags, initial metatype offsets
                   4,    2,   29,    2, 0x0a,    4 /* Public */,
            
             // signals: parameters
                QMetaType::Void, QMetaType::QString,    3,
            
             // slots: parameters
                QMetaType::Void, QMetaType::QString, QMetaType::QString,    3,    5,
            
             // properties: name, type, flags
                   3, QMetaType::QString, 0x00015103, uint(0), 0,
            
                   0        // eod
            };
            
            Q_CONSTINIT const QMetaObject Test::staticMetaObject = { {
                QMetaObject::SuperData::link<QObject::staticMetaObject>(),
                qt_meta_stringdata_CLASSTestENDCLASS.offsetsAndSizes,
                qt_meta_data_CLASSTestENDCLASS,
                qt_static_metacall,
                nullptr,
                qt_incomplete_metaTypeArray<qt_meta_stringdata_CLASSTestENDCLASS_t,
                    // property 'text'
                    QtPrivate::TypeAndForceComplete<QString, std::true_type>,
                    // Q_OBJECT / Q_GADGET
                    QtPrivate::TypeAndForceComplete<Test, std::true_type>,
                    // method 'textChanged'
                    QtPrivate::TypeAndForceComplete<void, std::false_type>,
                    QtPrivate::TypeAndForceComplete<const QString &, std::false_type>,
                    // method 'setText'
                    QtPrivate::TypeAndForceComplete<void, std::false_type>,
                    QtPrivate::TypeAndForceComplete<const QString &, std::false_type>,
                    QtPrivate::TypeAndForceComplete<const QString &, std::false_type>
                >,
                nullptr
            } };
            
            void Test::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
            {
                if (_c == QMetaObject::InvokeMetaMethod) {
                    auto *_t = static_cast<Test *>(_o);
                    (void)_t;
                    switch (_id) {
                    case 0: _t->textChanged((*reinterpret_cast< std::add_pointer_t<QString>>(_a[1]))); break;
                    case 1: _t->setText((*reinterpret_cast< std::add_pointer_t<QString>>(_a[1])),(*reinterpret_cast< std::add_pointer_t<QString>>(_a[2]))); break;
                    default: ;
                    }
                } else if (_c == QMetaObject::IndexOfMethod) {
                    int *result = reinterpret_cast<int *>(_a[0]);
                    {
                        using _t = void (Test::*)(const QString & );
                        if (_t _q_method = &Test::textChanged; *reinterpret_cast<_t *>(_a[1]) == _q_method) {
                            *result = 0;
                            return;
                        }
                    }
                }else if (_c == QMetaObject::ReadProperty) {
                    auto *_t = static_cast<Test *>(_o);
                    (void)_t;
                    void *_v = _a[0];
                    switch (_id) {
                    case 0: *reinterpret_cast< QString*>(_v) = _t->text(); break;
                    default: break;
                    }
                } else if (_c == QMetaObject::WriteProperty) {
                    auto *_t = static_cast<Test *>(_o);
                    (void)_t;
                    void *_v = _a[0];
                    switch (_id) {
                    case 0: _t->setText(*reinterpret_cast< QString*>(_v)); break;
                    default: break;
                    }
                } else if (_c == QMetaObject::ResetProperty) {
                } else if (_c == QMetaObject::BindableProperty) {
                }
            }
            
            const QMetaObject *Test::metaObject() const
            {
                return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
            }
            
            void *Test::qt_metacast(const char *_clname)
            {
                if (!_clname) return nullptr;
                if (!strcmp(_clname, qt_meta_stringdata_CLASSTestENDCLASS.stringdata0))
                    return static_cast<void*>(this);
                return QObject::qt_metacast(_clname);
            }
            
            int Test::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
            {
                _id = QObject::qt_metacall(_c, _id, _a);
                if (_id < 0)
                    return _id;
                if (_c == QMetaObject::InvokeMetaMethod) {
                    if (_id < 2)
                        qt_static_metacall(this, _c, _id, _a);
                    _id -= 2;
                } else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
                    if (_id < 2)
                        *reinterpret_cast<QMetaType *>(_a[0]) = QMetaType();
                    _id -= 2;
                }else if (_c == QMetaObject::ReadProperty || _c == QMetaObject::WriteProperty
                        || _c == QMetaObject::ResetProperty || _c == QMetaObject::BindableProperty
                        || _c == QMetaObject::RegisterPropertyMetaType) {
                    qt_static_metacall(this, _c, _id, _a);
                    _id -= 1;
                }
                return _id;
            }
            
            // SIGNAL 0
            void Test::textChanged(const QString & _t1)
            {
                void *_a[] = { nullptr, const_cast<void*>(reinterpret_cast<const void*>(std::addressof(_t1))) };
                QMetaObject::activate(this, &staticMetaObject, 0, _a);
            }
            QT_WARNING_POP
            
            

            The error is at this line case 0: _t->setText(*reinterpret_cast< QString*>(_v)); break;
            is this a bug from the auto-generated moc file?

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @Ylvy
            For a QPROPERTY WRITE you cannot use your method. https://doc.qt.io/qt-6/properties.html

            A WRITE accessor function is optional. It is for setting the property value. It must return void and must take exactly one argument, either of the property's type or a pointer or reference to that type

            Y 1 Reply Last reply
            2
            • JonBJ JonB

              @Ylvy
              For a QPROPERTY WRITE you cannot use your method. https://doc.qt.io/qt-6/properties.html

              A WRITE accessor function is optional. It is for setting the property value. It must return void and must take exactly one argument, either of the property's type or a pointer or reference to that type

              Y Offline
              Y Offline
              Ylvy
              wrote on last edited by
              #6

              @JonB And when you need more than one argument?

              Christian EhrlicherC 1 Reply Last reply
              0
              • Y Ylvy

                @JonB And when you need more than one argument?

                Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Ylvy said in Moc compilation error:

                And when you need more than one argument?

                A property does need exactly one element as written in the documentation - otherwise it's not a property. So either don't define it as property or only pass one argument.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                2

                • Login

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