Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Issues loading QWidgets containing QQuickWidget into QStackedWidget in Qt5.15
Qt 6.11 is out! See what's new in the release blog

Issues loading QWidgets containing QQuickWidget into QStackedWidget in Qt5.15

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 327 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.
  • M Offline
    M Offline
    mchabala
    wrote on last edited by
    #1

    Hello,
    I'm developing a Qt application and would like to incorporate QML through QQuickWidgets, but am running into some issues. To give some context, I created a simple project with the goal of adding two QWidgets containing QQuickWidgets to a QStackedWidget and navigating between them. Something like this:

    MainWindow::MainWindow(QWidget *parent)
    : QWidget(parent)
    {
       // Create Next PushButton and connect to function that updates current page when clicked
       pb1 = new QPushButton(this);
       pb1->setText("Next");
       connect( pb1, SIGNAL( clicked() ), this, SLOT( showNextWidgetInStack() ) );
    
       // Create Previous PushButton and connect to function that updates current page when clicked
       pb2 = new QPushButton(this);
       pb2->setText("Previous");
       connect( pb2, SIGNAL( clicked() ), this, SLOT( showPreviousWidgetInStack() ) );
    
       // Create QStackedWidget and add two "pages"
       sw = new QStackedWidget();
       QQuickPage *page1 = new QQuickPage( "test_page1", this );
       QQuickPage *page2 = new QQuickPage( "test_page2", this );
       
       // Add "pages" to stacked widget
       sw->addWidget(page1);
       sw->addWidget(page2);
       sw->setCurrentIndex(0);
       
       // Add everything to latout and set it
       QVBoxLayout * mainLayout = new QVBoxLayout;
       mainLayout->addWidget ( pb2 );
       mainLayout->addWidget ( pb1 );
       mainLayout->addWidget ( sw );
       setLayout(mainLayout);
    }
    

    where showNextWidgetInStack and showPreviousWidgetInStack increases/decreases the index of the QStackedWidget to display the next element and QQuickPage is a widget containing a QLabel and a QQuickWidget:

    QQuickPage::QQuickPage( QString product, QWidget *parent )
        : QWidget(parent),
          _product(product)
    {
       QLabel *productLabel = new QLabel;
       testLabel->setText(product);
    
       QString qmlFile = qmlRootDir + "/" + product + ".qml";
    
       // Load .qml page contents into QQuickWidget
       qqw = new QQuickWidget;
       qqw->setSource(QUrl::fromLocalFile(QFileInfo(fileName).canonicalFilePath()));
       if ( qqw->status() == QQuickWidget::Error )
       {
           // Error handling here... 
       }
    
       // Set the background color to specific theme and set resize mode for scaling
       qqw->setClearColor(QColor(qmlBackgroundColor));
       qqw->setResizeMode(QQuickWidget::SizeRootObjectToView);
    
       // Display QLabel and QQuickWidget built from QML
       QVBoxLayout * mainLayout = new QVBoxLayout;
       mainLayout->addWidget(testLabel);
       mainLayout->addWidget(qqw);
       setLayout(mainLayout);
    }
    

    Attempting to do this causes the application to crash, specifically at Qt5Core.dll!ZNK7QObject8propertyEPKc in the call stack.

    What's strange is that:

    • If add one QQuickPage it works as intended if the QML page that is loaded is using QtQuick.Controls 1, but fails if using QtQuick.Controls 2
    • If adding QQuickWidgets to the QStackedWidget directly they appear without issue, regardless of if QtQuick.Controls 1 or QtQuick.Controls 2 is used.
    • I had this working on Qt 5.12.12, but after building locally from source using the following command: ..\qt-everywhere-src-5.15.9\configure -v -prefix D:\buildQt\qt-5.15-install -commercial -release -platform win32-g++ -shared -nomake tests -nomake examples -confirm-license -no-feature-gssapi -no-harfbuzz -no-opengl -no-dbus -qt-libpng -qt-zlib -qt-libjpeg -skip qtx11extras -skip qtwayland -skip qtvirtualkeyboard -skip qttranslations -skip qtspeech -skip qtserialport -skip qtserialbus -skip qtsensors -skip qtscxml -skip qtscript -skip qtremoteobjects -skip qtpurchasing -skip qtnetworkauth -skip qtmultimedia -skip qtmacextras -skip qtlocation -skip qtgamepad -skip qtdoc -skip qtdatavis3d -skip qtconnectivity -skip qtcharts -skip qtcanvas3d -skip qtandroidextras -skip qtactiveqt -skip qt3d -skip qtwebview -skip qtwebsockets -skip qtwebglplugin -skip qtwebengine -skip qtwebchannel things no longer work.

    Any advice/input/help on this would be greatly appreciated!

    Thanks in advance

    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