Qt 5.7 Extending Popup (ASSERT: "_currentList.object" in file qml/qqmlobjectcreator.cpp, line 945)
<p>I got the runtime error below when using my custom popup implementation with Qt 5.7 (Qt 5.7 is necessary because there is introduced Popup and it needs to be compiled with<br>
<code>-developer-build</code> flag so private symbols (QQuickPopup class) are exported).</p>

<p>You can try replace "<code>CPopup</code>" with "<code>Popup</code>" in <strong>MyItem.qml</strong> and you will see it works, so the problem needs to be somewhere with the inheritance from <code>QQuickPopup</code> in my <code>CustomPopup</code> class.</p>

<p><strong>ERROR:</strong> <code>ASSERT: "_currentList.object" in file qml/qqmlobjectcreator.cpp, line 945</code></p>

<p><a href="https://github.com/qt/qtquickcontrols2/blob/5.7/src/quicktemplates2/qquickpopup_p.h" rel="nofollow">https://github.com/qt/qtquickcontrols2/blob/5.7/src/quicktemplates2/qquickpopup_p.h</a>
<a href="https://github.com/qt/qtquickcontrols2/blob/5.7/src/quicktemplates2/qquickpopup.cpp" rel="nofollow">https://github.com/qt/qtquickcontrols2/blob/5.7/src/quicktemplates2/qquickpopup.cpp</a>
<a href="https://github.com/qt/qtdeclarative/blob/dev/src/qml/qml/qqmlobjectcreator_p.h" rel="nofollow">https://github.com/qt/qtdeclarative/blob/dev/src/qml/qml/qqmlobjectcreator_p.h</a>
<a href="https://github.com/qt/qtdeclarative/blob/dev/src/qml/qml/qqmlobjectcreator.cpp" rel="nofollow">https://github.com/qt/qtdeclarative/blob/dev/src/qml/qml/qqmlobjectcreator.cpp</a></p>

<p><strong>PROJECT: popuptest</strong></p>

<p><strong>popuptest.pro</strong></p>

<pre><code>TEMPLATE = app

QT += gui qml quick quickcontrols2
QT_PRIVATE += quick-private core-private gui-private qml-private quickcontrols2-private quicktemplates2-private

CONFIG += c++11

SOURCES += main.cpp \
    custompopup.cpp

RESOURCES += qml.qrc

# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =

# Default rules for deployment.
include(deployment.pri)

HEADERS += \
    custompopup.h
</code></pre>

<p><strong>custompopup.h</strong></p>

<pre><code>#ifndef CUSTOMPOPUP_H
#define CUSTOMPOPUP_H

#include &lt;private/qquickpopup_p.h&gt;

class CustomPopup : public QQuickPopup
{

    Q_OBJECT
    //Q_PROPERTY(QQmlListProperty&lt;QObject&gt; contentData READ contentData FINAL)
    //Q_CLASSINFO("DefaultProperty", "contentData")
public:
    CustomPopup(QObject *parent = nullptr);

protected:
    bool overlayEvent(QQuickItem *item, QEvent *event) override;

private:
    /*Q_DISABLE_COPY(CustomPopup)
    Q_DECLARE_PRIVATE(QQuickPopup)*/
};


QML_DECLARE_TYPE(CustomPopup)

#endif // CUSTOMPOPUP_H
</code></pre>

<p><strong>custompopup.cpp</strong></p>

<pre><code>#include "custompopup.h"

CustomPopup::CustomPopup(QObject *parent) : QQuickPopup(parent)
{

}

bool CustomPopup::overlayEvent(QQuickItem *item, QEvent *event)
{
        /*QQuickPopup implementation
        Q_D(QQuickPopup);
        switch (event-&gt;type()) {
        case QEvent::KeyPress:
        case QEvent::KeyRelease:
        case QEvent::MouseMove:
        case QEvent::Wheel:
            if (d-&gt;modal)
                event-&gt;accept();
            return d-&gt;modal;

        case QEvent::MouseButtonPress:
        case QEvent::MouseButtonRelease:
            if (d-&gt;modal)
                event-&gt;accept();
            d-&gt;tryClose(item, static_cast&lt;QMouseEvent *&gt;(event));
            return d-&gt;modal;

        default:
            return false;
        }
        */
   // Q_D(QQuickPopup);
    return QQuickPopup::overlayEvent(item, event);
}
</code></pre>

<p><strong>main.cpp</strong></p>

<pre><code>#include &lt;QGuiApplication&gt;
#include &lt;QQmlApplicationEngine&gt;
#include "custompopup.h"

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

    QQmlApplicationEngine engine;

    qmlRegisterType&lt;CustomPopup&gt;("Custom", 1, 0, "CPopup");

    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

    return app.exec();
}
</code></pre>

<p><strong>main.qml</strong></p>

<pre><code>import QtQuick 2.7
import QtQuick.Controls 1.5

ApplicationWindow {
    visible: true
    width: 600
    height: 480

    MyItem {
        anchors.fill: parent
    }
}
</code></pre>

<p><strong>MyItem.qml</strong></p>

<pre><code>import QtQuick 2.0
import QtQuick.Controls 2.0
import Custom 1.0

Item {

    MouseArea {
        anchors.fill: parent
        acceptedButtons: Qt.RightButton
        onClicked: {
            menu.x = mouse.x
            menu.y = mouse.y
            menu.open()
        }

    }

    CPopup {
        id: menu
        Rectangle {
            width: 100
            height: 100
            color: "red"
        }
    }
}
</code></pre>