Unsolved QQuickWidget
-
Hello , In my project I have file1.qml and file2.qml .
Currently I have a file1.qml displayed on Qquickwidget . In my file1.qml I have a button .
what i want is when i click on button , file2.qml displayed on the same qquickwidgets and the file1.qml hide .
How can i do this ?
Please Help me I am blocked since 7 days .
thank you -
@dziko147
Hi,
I'm usually not QML developer!
I hope my example is helpful for you, maybe it is possible to implement better.I can't upload a zip file :(, or it seems so.
I copy here my qml file and mainwindow.cpp, this simple example runs for me. at startup quickWidget is set with form1.qml
-- form1.qml
import QtQuick 2.0
import QtQuick.Controls 2
Item {
signal qmlSignal()Text { id: text1 x: 15 y: 29 width: 143 height: 49 text: qsTr("FORM1") font.pixelSize: 35 minimumPixelSize: 35 } Button { x: 15 y: 100 text: "Ok" onClicked: qmlSignal() }
}
-- form2.qml
import QtQuick 2.0Item {
Text {
id: text1
x: 143
y: 147
width: 419
height: 134
text: qsTr("FORM2")
font.pixelSize: 35
minimumPixelSize: 35
}
}-- mainwindow.cpp
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);auto rootObject = ui->quickWidget->rootObject(); QObject::connect(rootObject, SIGNAL(qmlSignal()), this, SLOT(onSwitchClicked()));
}
MainWindow::~MainWindow()
{
delete ui;
}void MainWindow::onSwitchClicked()
{
ui->quickWidget->setSource(QUrl(QStringLiteral("qrc:/QML/Form2.qml")));
} -
@dziko147
Only one thing, as a personal opinion, I prefer to have two quickWidgets and show or hide one or other -
@CP71 thanks for your reply <3
I tried your example but i get this error :
QObject::connect: No such signal QQuickItem_QML_15::qmlSignal() in ../MyApp/mainwindow.cpp:37
QObject::connect: (receiver name: 'MainWindow')
qrc:/qml/FeatureButton.qml:70: ReferenceError: qmlSignal is not definedDo you know how to solve this ?
thank you very much -
@dziko147
I don't know exactly!
try to include in mainwindows.cpp : #include <QQuickItem>Without this include I have an error but is not the same to you
Sorry
-
Anyway thank for Help <3