Qt 6.11 is out! See what's new in the release
blog
Issues loading QWidgets containing QQuickWidget into QStackedWidget in Qt5.15
-
Hello,
I'm developing a Qt application and would like to incorporate QML throughQQuickWidgets, but am running into some issues. To give some context, I created a simple project with the goal of adding twoQWidgetscontainingQQuickWidgetsto aQStackedWidgetand 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
showNextWidgetInStackandshowPreviousWidgetInStackincreases/decreases the index of theQStackedWidgetto display the next element andQQuickPageis a widget containing aQLabeland aQQuickWidget: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!ZNK7QObject8propertyEPKcin the call stack.What's strange is that:
- If add one
QQuickPageit works as intended if theQMLpage that is loaded is usingQtQuick.Controls 1, but fails if usingQtQuick.Controls 2 - If adding
QQuickWidgetsto theQStackedWidgetdirectly they appear without issue, regardless of ifQtQuick.Controls 1orQtQuick.Controls 2is 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 qtwebchannelthings no longer work.
Any advice/input/help on this would be greatly appreciated!
Thanks in advance
- If add one