How to refresh each Form on click of tabs



  • hello friends

    Actually i have created three tabs..on selecting each tab i have started a new activity..at the first load its fine..now when i make changes and again selected the particular tab..the changes that i have made is not shown..but when i exit the application and again run the app the changes i made in each form is shown..so why this happen..i have send my code..if anyone please check it..

    code for first class file

    @MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    QVBoxLayout *lay;

    CalenderForm *pCal = new CalenderForm();
    lay = new QVBoxLayout(ui->tab);
    lay->addWidget(pCal);
    
    HistoryForm *pHis = new HistoryForm();
    lay = new QVBoxLayout(ui->tab_2);
    lay->addWidget(pHis);
    pHis->DisplayHistory();
    
    
    ui->setupUi(this);
    StatsForm *pStat = new StatsForm();
    lay = new QVBoxLayout(ui->tab_3);
    pStat->InitMemberVariable();
    lay->addWidget(pStat);   
    

    }
    @

    code for history form

    @HistoryForm::HistoryForm(QWidget *parent) :QMainWindow(parent),ui(new Ui::HistoryForm)
    {
    ui->setupUi(this);
    CycleManager *pCycMan=new CycleManager();
    QDate dtStartDate = pCycMan->GetStartDate();
    QDate dtDefault = pCycMan->GetDefaultDate();
    delete pCycMan;
    if(dtStartDate==dtDefault)
    ui->addNewBut->setEnabled(false);
    connect(ui->addNewBut,SIGNAL(clicked()),this,SLOT(addPreviousCycledate()));
    connect(ui->backBut,SIGNAL(clicked()),this,SLOT(closeHistoryFrm()));

    }

    void HistoryForm::DisplayHistory()
    {

        CycleManager* pCycMan = new CycleManager();
        int iHistCount = pCycMan->GetHistoryCount();
        QString strDisplay;
        int i;
        bool bStarred = false;
        for (i=0; i<iHistCount; i++)
        {
                strDisplay=" ";
                QDate dtHist = pCycMan->GetHistoryDate(i);
    
                strDisplay=dtHist.toString();
    
    
                QLabel *pLabelHistory1 = new QLabel();
    
                pLabelHistory1->setText(strDisplay);
    
    
                ui->controlLayout->setAlignment(Qt::AlignTop);
                ui->controlLayout->addWidget(pLabelHistory1);
    
    
                strDisplay=" ";
                 if (i == 0)
                        if (pCycMan->IsCycleStopped())
                                strDisplay = "Stopped";
                        else
                                strDisplay = "In progress";
               else
               {
                        QDate dtNextHist = pCycMan->GetHistoryDate(i-1);
                        long lDiff =dtHist.daysTo(dtNextHist);
    
                        strDisplay.append(QString::number(lDiff));
                        if (lDiff<CYCLE_MIN_LENGTH or lDiff>CYCLE_MAX_LENGTH)
                        {
                                strDisplay.append(" *");
                                bStarred = true;
                        }
                }
    
                   QLabel *pLabelHistory2 = new QLabel();
                   pLabelHistory2->setText(strDisplay);
                   ui->controlLayoutSec->setAlignment(Qt::AlignTop);
                   ui->controlLayoutSec->addWidget(pLabelHistory2);
    
        }
    
    
        strDisplay=" ";
        if (bStarred)
                strDisplay.append("* Shorter or longer than accepted");
        else
                strDisplay.append("");
    
        ui->secondLbl->setText(strDisplay);
    

    }@


  • Moderators

    Hi alfah,

    you could connect the currentChanged signal of the QTabWidget to displayHistory(is this a slot? if not make it a slot)



  • yeh display history is a slot..so how that can be done can you please explain that.


  • Moderators

    in your MainWindow constructor do something like this :

    @connect(ui->tabWidget, SIGNAL(currentChanged(int)),
    pHis, SLOT(DisplayHistory() ));@


Log in to reply
 

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