Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How can i get quickview pointer from QWidget when use QWidget::createWindowContainer(quickview, this);
Forum Update on Monday, May 27th 2025

How can i get quickview pointer from QWidget when use QWidget::createWindowContainer(quickview, this);

Scheduled Pinned Locked Moved Solved Mobile and Embedded
3 Posts 2 Posters 390 Views
  • 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.
  • T Offline
    T Offline
    tony_yuan
    wrote on last edited by tony_yuan
    #1
    class TestPage : public QWidget
    {
        Q_OBJECT
    public:
        explicit TestPage(QWidget *parent = nullptr);
        ~TestPage();
    private:
        QStackedLayout *l;
        QQuickView *quickview;
    };
    TestPage::TestPage(QWidget *parent) : QWidget(parent)
    {
        quickview = nullptr;
        quickview = new QQuickView();
        QWidget *container = QWidget::createWindowContainer(quickview, this);
        container->setMinimumSize(400, 400);
        container->setMaximumSize(400, 400);
        quickview->setSource(QUrl("qrc:/test.qml"));
        //embedded qquickview to qwidget
        l = new QStackedLayout(this);
        l->addWidget(container);
        this->setLayout(l);
    }
    

    For some reason ,I would like to get the quickview pointer (which emedded in QWidget with QWidget::createWindowContainer) from another thread. First i have got the TestPage pointer of my widget, then enumerate childdren of widget, i get the container pointer. But how can i get the pointer of quickview through container pointer.

    QWidget::createWindowContainer return a QWidget pointer. QWidget have a function windowHandle. i tried container->windowHandle() ,but return nullptr.

    eyllanescE 1 Reply Last reply
    0
    • T tony_yuan
      class TestPage : public QWidget
      {
          Q_OBJECT
      public:
          explicit TestPage(QWidget *parent = nullptr);
          ~TestPage();
      private:
          QStackedLayout *l;
          QQuickView *quickview;
      };
      TestPage::TestPage(QWidget *parent) : QWidget(parent)
      {
          quickview = nullptr;
          quickview = new QQuickView();
          QWidget *container = QWidget::createWindowContainer(quickview, this);
          container->setMinimumSize(400, 400);
          container->setMaximumSize(400, 400);
          quickview->setSource(QUrl("qrc:/test.qml"));
          //embedded qquickview to qwidget
          l = new QStackedLayout(this);
          l->addWidget(container);
          this->setLayout(l);
      }
      

      For some reason ,I would like to get the quickview pointer (which emedded in QWidget with QWidget::createWindowContainer) from another thread. First i have got the TestPage pointer of my widget, then enumerate childdren of widget, i get the container pointer. But how can i get the pointer of quickview through container pointer.

      QWidget::createWindowContainer return a QWidget pointer. QWidget have a function windowHandle. i tried container->windowHandle() ,but return nullptr.

      eyllanescE Offline
      eyllanescE Offline
      eyllanesc
      wrote on last edited by eyllanesc
      #2

      @tony_yuan Demo:

      #include <QApplication>
      #include <QGuiApplication>
      #include <QQuickView>
      #include <QVBoxLayout>
      #include <QWidget>
      #include <QWindow>
      
      #include <QDebug>
      
      
      int main(int argc, char *argv[])
      {
      #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
          QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
      #endif
          QApplication app(argc, argv);
      
          QWidget widget;
          widget.resize(640, 480);
          QVBoxLayout *layout = new QVBoxLayout(&widget);
      
          QQuickView *view = new QQuickView;
          view->setObjectName("Fooview");
          view->setSource(QUrl("qrc:/main.qml"));
      
          QWidget *container = QWidget::createWindowContainer(view);
          layout->addWidget(container);
      
          // method 1
          for(QWindow *window : QGuiApplication::allWindows()){
              QQuickView *qview;
              if((qview = qobject_cast<QQuickView*>(window)) && (qview->objectName() == "Fooview")){
                  qDebug() << "METHOD 1:" << qview;
              }
          }
      
          // method 2: show() must be called to create the QWindow
          widget.show();
      
          if(QWindow *window = container->window()->windowHandle()){
              QQuickView *view = window->findChild<QQuickView *>("Fooview");
              qDebug() << "METHOD 2:" << view;
          }
      
          return app.exec();
      }
      

      Output:

      METHOD 1: QQuickView(0x557bc723ff10, visibility=QWindow::Hidden, flags=QFlags<Qt::WindowType>(Window), name="Fooview", parent=0x557bc7338440, geometry=0,0 640x480)
      METHOD 2: QQuickView(0x557bc723ff10, visibility=QWindow::Windowed, flags=QFlags<Qt::WindowType>(Window), name="Fooview", parent=0x557bc7423fb0, geometry=9,9 622x462)
      

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      T 1 Reply Last reply
      2
      • eyllanescE eyllanesc

        @tony_yuan Demo:

        #include <QApplication>
        #include <QGuiApplication>
        #include <QQuickView>
        #include <QVBoxLayout>
        #include <QWidget>
        #include <QWindow>
        
        #include <QDebug>
        
        
        int main(int argc, char *argv[])
        {
        #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
            QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
        #endif
            QApplication app(argc, argv);
        
            QWidget widget;
            widget.resize(640, 480);
            QVBoxLayout *layout = new QVBoxLayout(&widget);
        
            QQuickView *view = new QQuickView;
            view->setObjectName("Fooview");
            view->setSource(QUrl("qrc:/main.qml"));
        
            QWidget *container = QWidget::createWindowContainer(view);
            layout->addWidget(container);
        
            // method 1
            for(QWindow *window : QGuiApplication::allWindows()){
                QQuickView *qview;
                if((qview = qobject_cast<QQuickView*>(window)) && (qview->objectName() == "Fooview")){
                    qDebug() << "METHOD 1:" << qview;
                }
            }
        
            // method 2: show() must be called to create the QWindow
            widget.show();
        
            if(QWindow *window = container->window()->windowHandle()){
                QQuickView *view = window->findChild<QQuickView *>("Fooview");
                qDebug() << "METHOD 2:" << view;
            }
        
            return app.exec();
        }
        

        Output:

        METHOD 1: QQuickView(0x557bc723ff10, visibility=QWindow::Hidden, flags=QFlags<Qt::WindowType>(Window), name="Fooview", parent=0x557bc7338440, geometry=0,0 640x480)
        METHOD 2: QQuickView(0x557bc723ff10, visibility=QWindow::Windowed, flags=QFlags<Qt::WindowType>(Window), name="Fooview", parent=0x557bc7423fb0, geometry=9,9 622x462)
        
        T Offline
        T Offline
        tony_yuan
        wrote on last edited by tony_yuan
        #3

        @eyllanesc Thanks for your reply, your solution works properly and is really userful for me.

        1 Reply Last reply
        0

        • Login

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