Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Slots/Signals newbie question
Forum Update on Monday, May 27th 2025

Slots/Signals newbie question

Scheduled Pinned Locked Moved Qt Creator and other tools
2 Posts 2 Posters 589 Views
  • 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
    abollo
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

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