qtinuum / QtnProperty

Extended properties for Qt5
Apache License 2.0
427 stars 153 forks source link

ASSERT: "data.ptr->ref.isStatic()" in file kernel\qmetaobject.cpp, line 152 in debug mode #31

Closed Lishen1 closed 6 years ago

Lishen1 commented 6 years ago
#include <QApplication>

#include "PropertyCore.h"
#include "PropertyWidget.h""
#include "QObjectPropertySet.h"

#include <QHBoxLayout>
#include <QString>

int main(int argc, char *argv[])
{

    QApplication a(argc, argv);
    QWidget w;

    w.setLayout(new QHBoxLayout);

    QtnPropertyWidget *centralWidget = new QtnPropertyWidget();

    auto m_propertySet = new QtnPropertySet(centralWidget);

    w.layout()->addWidget(centralWidget);

    auto floatValue = new QtnPropertyFloat(m_propertySet);
    floatValue->setName(QObject::tr("Value"));
    floatValue->setDescription(QObject::tr("Float value"));
    floatValue->setMaxValue(1.f);
    floatValue->setMinValue(0.f);
    floatValue->setStepValue(0.1f);
    floatValue->setValue(0.3f);

    auto m_propertySet2 = new QtnPropertySet(centralWidget);
    m_propertySet2->setName("ololo");
    m_propertySet->addChildProperty(m_propertySet2);

    centralWidget->setPropertySet(m_propertySet);

    w.show();

    return a.exec();
    //QtnPropertyEnum* EnumProperty = new QtnPropertyEnum(nullptr);
}

if uncomment //QtnPropertyEnum* EnumProperty = new QtnPropertyEnum(nullptr); it will works. if exclude all enums from Demo.pef, it will give the same exeption. I think something wrong with initQtnPropertyWidgetLibrary in PropertyDelegateFactory.cpp. I use visual studio 2017 x64 and Qt 5.10.1.

lexxmark commented 6 years ago

I was able to build and run your example using Qt5.9.3, VS2017 debug mode. Couldn't reproduce any assert.

Could you please send a stack trace of the assert.

image

Lishen1 commented 6 years ago

@lexxmark maybe it will helps

Qt5Cored.dll!qt_message_fatal(QtMsgType __formal=QtFatalMsg, const QMessageLogContext & context={...}, const QString & message={...}) Line 1710
    at c:\users\qt\work\qt\qtbase\src\corelib\global\qlogging.cpp(1710)
Qt5Cored.dll!QMessageLogger::fatal(const char * msg=0x00007ff9c8e0d9b8, ...) Line 822
    at c:\users\qt\work\qt\qtbase\src\corelib\global\qlogging.cpp(822)
Qt5Cored.dll!qt_assert(const char * assertion=0x00007ff9c905bc70, const char * file=0x00007ff9c905bc58, int line=152) Line 3126
    at c:\users\qt\work\qt\qtbase\src\corelib\global\qglobal.cpp(3126)
Qt5Cored.dll!stringData(const QMetaObject * mo=0x00007ff60b0ec350, int index=0) Line 153
    at c:\users\qt\work\qt\qtbase\src\corelib\kernel\qmetaobject.cpp(153)
Qt5Cored.dll!rawStringData(const QMetaObject * mo=0x00007ff60b0ec350, int index=0) Line 161
    at c:\users\qt\work\qt\qtbase\src\corelib\kernel\qmetaobject.cpp(161)
Qt5Cored.dll!objectClassName(const QMetaObject * m=0x00007ff60b0ec350) Line 307
    at c:\users\qt\work\qt\qtbase\src\corelib\kernel\qmetaobject.cpp(307)
Qt5Cored.dll!QMetaObject::className() Line 317
    at c:\users\qt\work\qt\qtbase\src\corelib\kernel\qmetaobject.cpp(317)
proplib-qt-gui.exe!QtnPropertyDelegateFactory::registerDelegateDefault(struct QMetaObject const *,class QtnPropertyDelegate * (*)(class QtnPropertyBase &),class QByteArray const &)
proplib-qt-gui.exe!regEnumDelegates(void)
proplib-qt-gui.exe!initQtnPropertyWidgetLibrary(class QIcon *)
proplib-qt-gui.exe!QtnPropertyBoolBase::fromStrImpl(class QString const &)
ucrtbased.dll!_initterm(void(*)() * first=0x00007ff60b086000, void(*)() * last=0x00007ff60b086858) Line 22
    at minkernel\crts\ucrt\src\appcrt\startup\initterm.cpp(22)
proplib-qt-gui.exe!__scrt_common_main_seh() Line 253
    at f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl(253)
proplib-qt-gui.exe!__scrt_common_main() Line 326
    at f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl(326)
proplib-qt-gui.exe!mainCRTStartup() Line 17
    at f:\dd\vctools\crt\vcstartup\src\startup\exe_main.cpp(17)
kernel32.dll!BaseThreadInitThunk()
ntdll.dll!RtlUserThreadStart()

i see you uses your Demo for check this issue. so, probably your project include Demo.peg.cpp and Demo.peg.h. more clean checking should exclude this files from compiling.

lexxmark commented 6 years ago

I have reproduced the ASSERT, you were right it's related to initQtnPropertyWidgetLibrary function. I rewrote the code to eliminate this function. Now default property delegate factory is created indirectly when using QtnPropertyWidget or QtnPropertyView classes.

So you are good now while not using these widgets during static variables initialization, that is very rare cases.

Please check and close issue if everything is OK.

Lishen1 commented 6 years ago

thanks for fast solving.