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. How to switch to new window after login in.
Qt 6.11 is out! See what's new in the release blog

How to switch to new window after login in.

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 2 Posters 447 Views 1 Watching
  • 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.
  • A Offline
    A Offline
    Antek832
    wrote on last edited by
    #1

    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();
    }
    
    1 Reply Last reply
    0
    • RusticusR Offline
      RusticusR Offline
      Rusticus
      wrote on last edited by
      #2

      You could make the original windows invisible until you have a valid login and with start-up you just load another pop up with the login system

      1 Reply Last reply
      0
      • A Antek832 has marked this topic as solved on

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved