Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Have no idea how to create multiple windows!

Have no idea how to create multiple windows!

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 933 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.
  • J Offline
    J Offline
    JonathanAV95
    wrote on last edited by
    #1

    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 !

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      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.

      (Z(:^

      1 Reply Last reply
      0
      • J Offline
        J Offline
        JonathanAV95
        wrote on last edited by
        #3

        [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
        }
        

        }
        @

        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