Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-54347

Runtime error when used custom popup based on QQuickPopup from Quick Controls 2

XMLWordPrintable

    • 0e3636a4692c9cf89d994f3fe5c1c110b4c6ee61

      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
      -developer-build flag so private symbols (QQuickPopup class) are exported).

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

      ERROR: ASSERT: "_currentList.object" in file qml/qqmlobjectcreator.cpp, line 945

      https://github.com/qt/qtquickcontrols2/blob/5.7/src/quicktemplates2/qquickpopup_p.h
      https://github.com/qt/qtquickcontrols2/blob/5.7/src/quicktemplates2/qquickpopup.cpp
      https://github.com/qt/qtdeclarative/blob/dev/src/qml/qml/qqmlobjectcreator_p.h
      https://github.com/qt/qtdeclarative/blob/dev/src/qml/qml/qqmlobjectcreator.cpp

      PROJECT: popuptest

      popuptest.pro
          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
      
      custompopup.h
      
          #ifndef CUSTOMPOPUP_H
          #define CUSTOMPOPUP_H
          
          #include <private/qquickpopup_p.h>
          
          class CustomPopup : public QQuickPopup
          {
          
              Q_OBJECT
              //Q_PROPERTY(QQmlListProperty<QObject> 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
      
      custompopup.cpp
          #include "custompopup.h"
          
          CustomPopup::CustomPopup(QObject *parent) : QQuickPopup(parent)
          {
          
          }
          
          bool CustomPopup::overlayEvent(QQuickItem *item, QEvent *event)
          {
                  /*QQuickPopup implementation
                  Q_D(QQuickPopup);
                  switch (event->type()) {
                  case QEvent::KeyPress:
                  case QEvent::KeyRelease:
                  case QEvent::MouseMove:
                  case QEvent::Wheel:
                      if (d->modal)
                          event->accept();
                      return d->modal;
          
                  case QEvent::MouseButtonPress:
                  case QEvent::MouseButtonRelease:
                      if (d->modal)
                          event->accept();
                      d->tryClose(item, static_cast<QMouseEvent *>(event));
                      return d->modal;
          
                  default:
                      return false;
                  }
                  */
             // Q_D(QQuickPopup);
              return QQuickPopup::overlayEvent(item, event);
          }
      
      main.cpp
          #include <QGuiApplication>
          #include <QQmlApplicationEngine>
          #include "custompopup.h"
          
          int main(int argc, char *argv[])
          {
              QGuiApplication app(argc, argv);
          
              QQmlApplicationEngine engine;
          
              qmlRegisterType<CustomPopup>("Custom", 1, 0, "CPopup");
          
              engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
          
              return app.exec();
          }
      
      main.qml
      
          import QtQuick 2.7
          import QtQuick.Controls 1.5
          
          ApplicationWindow {
              visible: true
              width: 600
              height: 480
          
              MyItem {
                  anchors.fill: parent
              }
          }
      
      MyItem.qml
      
          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"
                  }
              }
          }
      
      

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            Unassigned Unassigned
            jhribal Jaromír Hřibal
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes