how to open one window from another with qml
-
hi everyone sorry for the silly question but i'm a newbie so how can i open one window from another
-
Have qml component with root item as window. Based on some signal show the object of window. It will launch in another window.
-
@dheerendra hi, thanks for the fast reply , can you give me any example please?
-
You can check my GIT
-
@dheerendra thanks it works but know i would like to know how to close the first window, the one i used to lunch the other one
-
Assign the id property for the first window. Inside the handler you can say id.visible = false;
-
@dheerendra realized now that the second window does not open as a new window , it opens inside the first window and when i give the command to set as false the first window visibility it closes both windows
-
show me the code change you have done.
-
import QtQuick 2.9
import QtQuick.Controls 2.4ApplicationWindow {
id: lol visible: true width: 640 height: 480 title: qsTr("Hello World") Loader{ id : ld } Frame { width: 300 height: 400 anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent.verticalCenter
Column {
anchors.horizontalCenter: parent.horizontalCenter;
anchors.verticalCenter: parent.verticalCenter;spacing: 5; Label{ width: 200 height: 30 anchors.horizontalCenter: Column.horizontalCenter; //anchors.verticalCenter: Column.verticalCenter text: "FACEBOOK" color: "black" visible: true } TextField{ text: "username " width: 200 height: 30 anchors.horizontalCenter: Column.horizontalCenter; anchors.verticalCenter: Column.verticalCenter; visible: true } TextField{ text: "password " width: 200 height: 30 anchors.horizontalCenter: Column.horizontalCenter; anchors.verticalCenter: Column.verticalCenter; visible: true } Button{ width: 200 height: 30 anchors.horizontalCenter: Column.horizontalCenter; anchors.verticalCenter: Column.verticalCenter; text: "loggin" visible: true onClicked: { console.log("Dheerendra Window Clicked") ld.source = "page2.qml" lol.visible = false } } }
}
}
-
![alt text]( image url)
-
After looking at this image I have question. Why do you want to show another windows ? Is it the error message you wanted to show ? if this the case you can show dialog.
-
I tried with you code now. When I launch it starts the user/password window. When I click on log button, it closes user/pass windows and shows the new window. Can you show what is available in Page2.qml ? Is it starting from Window as root element ? Looks like your Page2.qml qml root is not Window. Confirm the same.
-
@dheerendra i wanted to open the program main window from the login button
-
@dheerendra it doesn't shows the new window to me.
yes the page 2 window is not starting as a root element -
it shows this output
-
thank you sir , just made it , it opens the second window, i'm really grateful