Having difficulty with managing widgets



  • I Have a Class Named "Student" (this class dose have Form) And In my MainWindow I have A QVector From This Class ! Now I want To Show The form Of each Member Of the QVector But I Can't ! (I'm Doing this because I want that any Student have an Special Page For it self ! Witch saves any Change especial For themselves) This Is my Code :

    In My Main Window :

    @StHead = new QVector <Student> ;

    void MainWindow::StudentSignIn (QString User,QString Pass)
    {
    ///////Sign in things !
    int index = StudentSearch(User);
    Student* at = StHead->data();
    if (at[index].GetPass() == Pass)
    emit Hide_StuLog();
    qDebug()<<"This Slot happens";
    (*StHead)[index].show();
    }@

    BUT , When it shows , it's An empty page ! What the problem ?! Is What I'm doing Even Possible ?!



  • And this is Also how I add Member To my QVector
    @void MainWindow::StudentAdder(Student s)
    {
    StHead->append(s);
    }@


  • Moderators

    AFAIK as i can read out of this redundant and error prone written code seems correct. But the interesting parts are missing.

    What do you mean with "empty page"?
    Is the student page opened but doesn't display anything?
    Or is the main window just blank?
    Whats the base class of "Student"?
    Where is the Student object created?



  • When I sign in , A page Opens And there is nothing in it ! (it doesn't show the buttons witch I have In Student Ui)

    This is my main window.h:
    @#ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>
    #include <QDebug>
    #include <QVector>
    #include "admin.h"
    #include "student.h"
    #include "stulogpage.h"
    #include "firstpage.h"
    #include "studentadd.h"
    #include "addcharge.h"
    #include "stufoodlist.h"
    #include <iostream>
    using namespace std;

    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

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

    private slots:
    void StudentAdder(Student s);
    void StudentCharger (QString s,int charge);
    void StudentSignIn (QString User,QString Pass);
    int StudentSearch (QString s);

    signals:
    void Hide_StuLog ();

    private:
    Ui::MainWindow ui;
    QVector <Student>
    StHead;
    Admin * admin;
    StuLogPage* StLgPg;
    FirstPage* FrstPg;
    StudentAdd* StuAdd;
    AddCharge* AddChrg;
    StuFoodList* StFdLst;
    };

    #endif // MAINWINDOW_H
    @

    this is Main Window.cpp:
    @#include "mainwindow.h"
    #include "ui_mainwindow.h"

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    StHead = new QVector <Student>;
    admin = new Admin (this);
    StLgPg = new StuLogPage (this);
    FrstPg = new FirstPage (this);
    StuAdd = new StudentAdd (this);
    AddChrg = new AddCharge (this);
    StFdLst = new StuFoodList (this);
    connect (FrstPg,SIGNAL(admin_enter()),admin,SLOT(show()));
    connect (FrstPg,SIGNAL(student_enter()),StLgPg,SLOT(show()));
    connect (admin,SIGNAL(student_add()),StuAdd,SLOT(show()));
    connect (StuAdd,SIGNAL(DataTransfer(Student)),this,SLOT(StudentAdder(Student)));
    connect (admin,SIGNAL(charge_add()),AddChrg,SLOT(show()));
    connect (AddChrg,SIGNAL(Charge_Transfer(QString,int)),this,SLOT(StudentCharger(QString,int)));
    connect (admin,SIGNAL(Back()),FrstPg,SLOT(show()));
    connect (StuAdd,SIGNAL(Back()),admin,SLOT(show()));
    connect (AddChrg,SIGNAL(Back()),admin,SLOT(show()));
    connect (StLgPg,SIGNAL(DataTranfer(QString,QString)),this,SLOT(StudentSignIn(QString,QString)));
    connect (this,SIGNAL(Hide_StuLog()),StLgPg,SLOT(hide()));

    //connect (this,SIGNAL(Hide_StuLog()),StFdLst,SLOT(show()));
    StLgPg->hide();
    admin->hide();
    StuAdd->hide();
    AddChrg->hide();
    StFdLst->hide();
    

    }

    void MainWindow::StudentAdder(Student s)
    {
    //qDebug()<<"User:"<<s.User<<endl<<"Pass:"<<s.Pass<<endl;
    StHead->append(s);
    //Student* at = StHead->data();
    //if (StHead->size()>2)
    //{
    //qDebug()<<at[1].User<<endl;
    //}
    }

    void MainWindow::StudentCharger (QString s,int charge)
    {
    //qDebug()<<"Recived:"<<s;
    int index = StudentSearch(s);
    Student* at = StHead->data();
    at[index].AddCharge(charge);
    //qDebug()<<at[index].Charge;
    ///////////////////////////Age dorost nabud error bede !
    }

    int MainWindow::StudentSearch(QString s)
    {
    int i;
    Student* at = StHead->data();
    for (i=0 ; i<StHead->size() ; i++)
    {
    if (at[i].GetUser() == s)
    return i;
    }
    return NULL;
    }

    void MainWindow::StudentSignIn (QString User,QString Pass)
    {
    ///////Sign in things !
    int index = StudentSearch(User);
    Student* at = StHead->data();
    if (at[index].GetPass() == Pass)
    emit Hide_StuLog();
    qDebug()<<"Hide Mishe !";
    (*StHead)[index].show();
    //at[index].show();
    }

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

    this is my student.h:

    @#ifndef STUDENT_H
    #define STUDENT_H

    #include "shakhs.h"

    namespace Ui {
    class Student;
    }

    class Student : public QWidget ,public Shakhs
    {
    Q_OBJECT

    public:
    explicit Student(QWidget *parent = 0);
    Student (const Student &);
    Student (QString , QString , QString , QString);
    Student& operator = (const Student &);
    ~Student();

    public slots:
    void AddCharge (int a);

    signals:
    void Back();

    private slots:
    void on_Back_clicked();

    private:
    //public:
    int Charge;
    Ui::Student *student_ui;
    };

    #endif // STUDENT_H
    @

    and this is Student.cpp
    @#include "student.h"
    #include "ui_student.h"

    Student::Student(QWidget *parent) :
    QWidget(parent),
    student_ui(new Ui::Student)
    {
    student_ui->setupUi(this);
    }

    Student::Student (const Student &Copy)
    {
    //Name = Copy.Name;
    //Family = Copy.Family;
    //User = Copy.User;
    //Pass = Copy.Pass;
    *this = Copy;
    }

    Student::Student (QString name , QString family,QString user, QString pass)
    {
    Name = name;
    Family = family;
    User = user;
    Pass = pass;
    Charge = 40000;
    }

    Student::~Student()
    {
    delete student_ui;
    }

    Student& Student::operator = (const Student &a)
    {
    Name = a.Name;
    Family = a.Family;
    User = a.User;
    Pass = a.Pass;
    Charge = a.Charge;
    return *this;
    }

    void Student::AddCharge (int a)
    {
    Charge += a;
    }

    void Student::on_Back_clicked()
    {
    emit Back();
    }
    @


Log in to reply
 

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