Have no idea how to create multiple windows!



  • I've been trying ways to figure it out but i cant seem to get it working or get it seem to go in the right direction.

    All i want to do is have my MainWindow simply show another window. For example, have a MainWindow with a QButton, that upon clicking it, will show another window that has perhaps a label. I have no idea how to approach this! I might be asking anyone a lo here but this issue is holding me up greatly since i cant seem to fully understand Qt yet! I'd appreciate it if anyone can help !


  • Moderators

    All you need to do to create a separate window in Qt is to create a QWidget (like QPushButton, QLabel, etc.) without a parent (meaning: parent == 0).

    Or, alternatively, you can use QDialog.



  • [quote author="sierdzio" date="1419321382"]All you need to do to create a separate window in Qt is to create a QWidget (like QPushButton, QLabel, etc.) without a parent (meaning: parent == 0).

    Or, alternatively, you can use QDialog.[/quote]

    I personally do not know how to approach this?
    Here is the source code i have so far, were can i insert a QDialog:

    login_window.h
    @
    #ifndef LOGIN_WINDOW_H
    #define LOGIN_WINDOW_H

    #include <QWidget>
    #include <vector>

    namespace Ui {
    class LoginWindow;
    }

    class LoginWindow : public QWidget
    {
    Q_OBJECT

    public:
    explicit LoginWindow(QWidget *parent = 0);
    ~LoginWindow();

    bool checkStudentElement(int &refString, std::vector<int> &refVector);
    

    private slots:
    void on_loginButton_clicked();

    private:
    Ui::LoginWindow *ui;
    std::vector<int> *studentIDList;
    };

    #endif // LOGIN_WINDOW_H
    @

    login_window.cpp
    @
    #include "login_window.h"
    #include "ui_loginwindow.h"

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

    }

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

    void LoginWindow::on_loginButton_clicked()
    {
    std::string student_ID = (ui->le_studentID->text()).toStdString(); //convert to string
    //Must then check if it is already in the system

    if(checkStudentElement(student_ID, studentIDList) == true) //need to run function for check
    {
        ui->loginStatus->setText("Login Successful");
        break;
    }else{
        ui->loginStatus->setText("Login Failed");
        studentIDList->push_back(student_ID); //push the ID into the vector
    
    }
    

    }

    bool LoginWindow::checkStudentElement(int &refString, std::vector<int> &refVector)
    {
    int counter = refString.Length();
    if(counter > refString)
    {

    }
    for(int i = 0; i <= refVector.size(); i++)
    {
        //Will loop thru the elements to check for similar vector
        if(/*refVector.()begin == refVector*/)
        {
            //if it contain it
            break;
    
        }else{
            return false;
        } //else make sure to return that value
    }
    

    }
    @


Log in to reply
 

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