Qt 6.11 is out! See what's new in the release
blog
How to switch to new window after login in.
-
Hello, I want to create simple app where after typing username: "user" and password: "12345" login window will be closed and new windows with actuall content will apear. My first idea was connect signal emmited by button with C++ class that will validate data and later destroy actual window and create new one from another QML file. This approach demands from me interacting with C++. Can I deal with it using only QML or at least constrain C++ usage? For example: login window won't be destroyed but it's content will be replaced. Below is what I have already done.
QML code
import QtQuick import QtQuick.Controls import QtQuick.Layouts Window { width: 240 height: 380 visible: true title: qsTr("login window") ColumnLayout{ anchors.centerIn: parent spacing: 15 Text{ text: "Username" Layout.fillWidth: true } TextField{ id: usernameTextField placeholderText: "type username" Layout.fillWidth: true } Text{ text: "Password" Layout.fillWidth: true } TextField{ id: passwordTextField placeholderText: "type password" echoMode: TextInput.Password Layout.fillWidth: true } Button{ objectName: "loginButton" signal sendLoginData(string username, string password) text: "Login in" Layout.fillWidth: true onClicked: sendLoginData(usernameTextField.text, passwordTextField.text) } } }main.cpp
#include <QGuiApplication> #include <QQmlApplicationEngine> #include <QQuickView> #include <QQuickItem> #include <QString> #include <QUrl> #include "loginlogic.h" int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; loginLogic logger; QQmlComponent component(&engine, QUrl(QStringLiteral("qrc:/simpleLoginInSystem/main.qml"))); QObject *sender = component.create(); sender = sender->findChild<QObject*>("loginButton"); QObject::connect(sender, SIGNAL(sendLoginData(QString, QString)), &logger, SLOT(getUsernameAndData(QString, QString))); return app.exec(); } -
A Antek832 has marked this topic as solved on