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. Q_PROPERTY in a class failed when moc is running.
Forum Updated to NodeBB v4.3 + New Features

Q_PROPERTY in a class failed when moc is running.

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 228 Views 2 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.
  • B Offline
    B Offline
    blaisesegbeaya
    wrote last edited by aha_1980
    #1

    Hello All,

    OS: Window 10
    QT: 6.9.1
    MSVC 2022
    Build tool: qmake

    ==== Class ==
    #include <QApplication>
    #include <QObject>
    #include <QString>

    class MyClass : public QObject {

    Q_OBJECT
    Q_PROPERTY(QString myText READ getMyText WRITE setMyText NOTIFY myTextChanged)
    

    public:
    MyClass(QObject *parent = nullptr);

    QString getMyText() const;
    void setMyText(const QString &text);
    

    signals:
    void myTextChanged(const QString &newText);

    private:
    QString m_myText;
    };

    ======== Implementation ==

    #include <QApplication>
    #include "myclass.h"

    MyClass::MyClass(QObject *parent ) : QObject(parent)
    {

    }

    QString MyClass::getMyText() const
    {
    return m_myText;
    }

    void MyClass::setMyText(const QString &text)
    {
    if (m_myText != text) {
    m_myText = text;
    emit myTextChanged(m_myText);
    }
    }

    ===== Main ===

    #include "myclass.h"

    int main() {
    MyClass obj;
    obj.setMyText("Hello");
    qDebug() << obj.getMyText(); // Output: "Hello"

    QObject::connect(&obj, &MyClass::myTextChanged,
                     [&](const QString &newText) {
                         qDebug() << "Text changed to:" << newText;
                     });
    
    obj.setMyText("World"); // Output: "Text changed to: World"
    return 0;
    

    }
    ================= Moc error =======
    cl -c -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -permissive- -Zc:_cplusplus -Zc:externConstexpr -std:c++17 -O2 -MD -std:c++17 -utf-8 -W3 -w34100 -w34189 -w44456 -w44457 -w44458 -wd4577 -wd4467 -EHsc -DUNICODE -D_UNICODE -DWIN32 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -DWIN64 -DC_PLUS_PLUS -DWin32 -DWIN32 -D_MYWINDOW -D_CRT_SECURE_NO_WARNINGS -DCPP -DQTV5 -DQTV5 -DQT5MACRO -DQt_5x -DQt_5X -DQT_5X -DQT_5x -DC_PLUS_PLUS -DCPLUSPLUS -D_CRT_SECURE_NO_WARNINGS -DSTATIC_LIB -DSTATIC_QT -DNDEBUG -DQT_NO_DEBUG -DQT_PRINTSUPPORT_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_SQL_LIB -DQT_CORE_LIB -I. -I. -IE:\DEV\msqlib\v6-22/bTableWidget -IE:\DEV\msqlib\v6-22/qlib -IE:\DEV\msqlib\v6-22/include -IE:\DEV\msqlib\v6-22 -I....\Qt\v6\6.9.1\msvc2022_64\include -I....\Qt\v6\6.9.1\msvc2022_64\include\QtPrintSupport -I....\Qt\v6\6.9.1\msvc2022_64\include\QtWidgets -I....\Qt\v6\6.9.1\msvc2022_64\include\QtGui -I....\Qt\v6\6.9.1\msvc2022_64\include\QtNetwork -I....\Qt\v6\6.9.1\msvc2022_64\include\QtSql -I....\Qt\v6\6.9.1\msvc2022_64\include\QtCore -IMOC -I/include -I....\Qt\v6\6.9.1\msvc2022_64\mkspecs\win32-msvc -FoOBJ\moc_myclass.obj MOC\moc_myclass.cpp
    moc_myclass.cpp
    ....\Qt\v6\6.9.1\msvc2022_64\include\QtCore/qtmochelpers.h(262): error C2065: 'result': undeclared identifier
    ....\Qt\v6\6.9.1\msvc2022_64\include\QtCore/qtmochelpers.h(200): note: see reference to function template instantiation 'auto QtMocHelpers::UintData<QtMocHelpers::PropertyData<QString>>::copyTo::<lambda_930f3e387543f60f462d274f690f2e0a>::operator ()<T>(const T &) const' being compiled
    with
    [
    T=QtMocHelpers::PropertyData<QString>
    ]
    ....\Qt\v6\6.9.1\msvc2022_64\include\QtCore/qtmochelpers.h(200): note: see reference to function template instantiation 'auto QtMocHelpers::detail::UintDataStorage<std::integer_sequence<int,0>,QtMocHelpers::PropertyData<QString>>::forEach::<lambda_f952f8e5d1a1fa6d836f8a8f79762b0c>::operator ()<QtMocHelpers::detail::UintDataEntry<0,QtMocHelpers::PropertyData<QString>>>(const QtMocHelpers::detail::UintDataEntry<0,QtMocHelpers::PropertyData<QString>> &) const' being compiled
    ....\Qt\v6\6.9.1\msvc2022_64\include\QtCore/qtmochelpers.h(252): note: see reference to function template instantiation 'void QtMocHelpers::detail::UintDataStorage<std::integer_sequence<int,0>,QtMocHelpers::PropertyData<QString>>::forEach<QtMocHelpers::UintData<QtMocHelpers::PropertyData<QString>>::copyTo::<lambda_930f3e387543f60f462d274f690f2e0a>>(F &&) const' being compiled
    with
    [
    F=QtMocHelpers::UintData<QtMocHelpers::PropertyData<QString>>::copyTo::<lambda_930f3e387543f60f462d274f690f2e0a>
    ]
    ....\Qt\v6\6.9.1\msvc2022_64\include\QtCore/qtmochelpers.h(255): note: see reference to function template instantiation 'void QtMocHelpers::detail::UintDataStorage<std::integer_sequence<int,0>,QtMocHelpers::PropertyData<QString>>::forEach<QtMocHelpers::UintData<QtMocHelpers::PropertyData<QString>>::copyTo::<lambda_930f3e387543f60f462d274f690f2e0a>>(F &&) const' being compiled
    with
    [
    F=QtMocHelpers::UintData<QtMocHelpers::PropertyData<QString>>::copyTo::<lambda_930f3e387543f60f462d274f690f2e0a>
    ]
    ....\Qt\v6\6.9.1\msvc2022_64\include\QtCore/qtmochelpers.h(550): note: see reference to function template instantiation 'void QtMocHelpers::UintData<QtMocHelpers::PropertyData<QString>>::copyTo<Unique,QtMocHelpers::MetaObjectContents<29,10,38,4>>(Result &,size_t,uint &) const' being compiled
    with
    [
    Unique=anonymous-namespace'::qt_meta_tag_ZN7MyClassE_t, Result=QtMocHelpers::MetaObjectContents<29,10,38,4> ] ..\..\Qt\v6\6.9.1\msvc2022_64\include\QtCore/qtmochelpers.h(550): note: see reference to function template instantiation 'void QtMocHelpers::UintData<QtMocHelpers::PropertyData<QString>>::copyTo<Unique,QtMocHelpers::MetaObjectContents<29,10,38,4>>(Result &,size_t,uint &) const' being compiled with [ Unique=anonymous-namespace'::qt_meta_tag_ZN7MyClassE_t,
    Result=QtMocHelpers::MetaObjectContents<29,10,38,4>
    ]
    MOC\moc_myclass.cpp(61): note: see reference to function template instantiation 'QtMocHelpers::MetaObjectContents<29,10,38,4> QtMocHelpers::metaObjectData<MyClass,anonymous-namespace'::qt_meta_tag_ZN7MyClassE_t,QtMocHelpers::StringRefStorage<char [8],char [14],char [1],char [8],char [7]>,QtMocHelpers::UintData<QtMocHelpers::SignalData<void (const QString &)>>,QtMocHelpers::UintData<QtMocHelpers::PropertyData<QString>>,QtMocHelpers::UintData<>,QtMocHelpers::UintData<>,QtMocHelpers::detail::UintDataBlock<0,0>>(uint,const Strings &,const Methods &,const Properties &,const Enums &,const Constructors &,const ClassInfo &)' being compiled with [ Strings=QtMocHelpers::StringRefStorage<char [8],char [14],char [1],char [8],char [7]>, Methods=QtMocHelpers::UintData<QtMocHelpers::SignalData<void (const QString &)>>, Properties=QtMocHelpers::UintData<QtMocHelpers::PropertyData<QString>>, Enums=QtMocHelpers::UintData<>, Constructors=QtMocHelpers::UintData<>, ClassInfo=QtMocHelpers::detail::UintDataBlock<0,0> ] ..\..\Qt\v6\6.9.1\msvc2022_64\include\QtCore/qtmochelpers.h(550): note: while evaluating constexpr function 'QtMocHelpers::UintData<QtMocHelpers::PropertyData<QString>>::copyTo' MOC\moc_myclass.cpp(60): note: while evaluating constexpr function 'QtMocHelpers::metaObjectData' E:\DEV\temp\MOC\../myclass.h(8): note: while evaluating constexpr function 'MyClass::qt_create_metaobjectdata' E:\DEV\temp\MOC\../myclass.h(8): note: see reference to variable template 'const QtMocHelpers::MetaObjectContents<29,10,38,4> MyClass::qt_staticMetaObjectContent<anonymous namespace'::qt_meta_tag_ZN7MyClassE_t>' being compiled
    MOC\moc_myclass.cpp(65): note: see reference to variable template 'const auto MyClass::qt_staticMetaObjectStaticContent<`anonymous namespace'::qt_meta_tag_ZN7MyClassE_t>' being compiled

    =======
    I will appreciate any help.

    1 Reply Last reply
    0
    • Axel SpoerlA Online
      Axel SpoerlA Online
      Axel Spoerl
      Moderators
      wrote last edited by
      #2

      Hello and welcome,
      Could you please edit your post and format your code using the </> code formatting tags? It’s hard to read otherwise. Please also post the actual error. Possible that I’ve overlooked it, but I couldn’t find it.

      Software Engineer
      The Qt Company, Oslo

      1 Reply Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote last edited by
        #3

        Hi,

        One thing I could see is that setMyText is not placed under a slot directive.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        B 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          One thing I could see is that setMyText is not placed under a slot directive.

          B Offline
          B Offline
          blaisesegbeaya
          wrote last edited by
          #4

          @SGaist Thank you for your suggestion. I made the changes, and it did not change the behavior of moc.

          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote last edited by
            #5

            I would test it but since you did not format your code properly I won't fiddle out the mess above by myself...

            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
            0
            • B Offline
              B Offline
              blaisesegbeaya
              wrote last edited by
              #6

              Hello All,

              It was my environment which is creating the miss behavior of moc. My building tools were pointing to the wrong version of VSVC (MSVC 2019). I corrected this, and all worked fine.

              "My Culpa"

              Sincerely.

              1 Reply Last reply
              0
              • B blaisesegbeaya has marked this topic as solved

              • Login

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