Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to refresh each Form on click of tabs
QtWS25 Last Chance

How to refresh each Form on click of tabs

Scheduled Pinned Locked Moved Mobile and Embedded
4 Posts 2 Posters 4.0k 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.
  • G Offline
    G Offline
    gogoi
    wrote on last edited by
    #1

    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);
    

    }@

    1 Reply Last reply
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by
      #2

      Hi alfah,

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

      Qt Certified Specialist
      www.edalsolutions.be

      1 Reply Last reply
      0
      • G Offline
        G Offline
        gogoi
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • EddyE Offline
          EddyE Offline
          Eddy
          wrote on last edited by
          #4

          in your MainWindow constructor do something like this :

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

          Qt Certified Specialist
          www.edalsolutions.be

          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