Slots/Signals newbie question



  • Hi I am pretty much a newbie to Qt. I tried searching for an answer to this question but I couldn't find I clear question so I hope you can help me with this.

    Basically I am trying to do a simple login program
    What I have is mainwindow and systemlogin window. A button in mainwindow opens the systemlogin window. In the systemlogin window there is a textfield and a button. When this button is clicked I need to compare the string value in the textfield to a table that is implemented in mainwindow.cpp
    I found out that the best way to do this is by using slots and singals

    Here is the code I have so far

    mainwindow.cpp

    @#include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "systemlogin.h"
    #include "userlogin.h"
    #include "hashTable.h"
    #include <fstream>
    #include <string>
    #include <QString>
    #include <QFile>
    #include <QTextStream>
    using namespace std;

    string pass = "admin"; //is actually a hashtable but using string for simplicity

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    void MainWindow::on_pushButton_clicked()
    {
    systemlogin systemLogin;
    systemLogin.setModal(true);
    systemLogin.exec();
    }

    void MainWindow::on_pushButton_3_clicked()
    {
    this->close();
    }

    bool login (string input)
    {
    if (input == pass)
    return true;
    else
    return false;
    }@

    systemlogin.cpp

    @#include "systemlogin.h"
    #include "ui_systemlogin.h"

    systemlogin::systemlogin(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::systemlogin)
    {
    ui->setupUi(this);
    }

    systemlogin::~systemlogin()
    {
    delete ui;
    }

    void systemlogin::on_pushButton_clicked()
    {
    /*Gets a string userinput from the textfield and is supposed to call the login function from mainwindow so it checks
    login(userinput)
    */
    }

    void systemlogin::on_pushButton_2_clicked()
    {
    this->hide();
    }
    @

    I hope my question is not vague
    So how do I go about doing this
    I read that I should add connect to the cpp files. Any pointers on how to do that would be appreciated.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    "This":http://qt-project.org/doc/qt-5/designer-using-a-ui-file.html#a-dialog-without-auto-connect part of the documentation is what you are looking. You have described there the two possible connection technique (i.e. by hand and automatic)

    Hope it helps


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.