Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6231061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:51:56+00:00 2026-05-24T09:51:56+00:00

Im trying to display 3 forms(calender, history, statistics) which has 3 classes into a

  • 0

Im trying to display 3 forms(calender, history, statistics) which has 3 classes into a MainWindow Class which has three tabs created using the designer. When the application runs for the first time, it displays the history form into the tab. But when it is being run the second time, the form is displayed over the tabs that they are not visible.

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{

ui->setupUi(this);
CalenderForm *pCal = new CalenderForm();
lay = new QVBoxLayout(ui->tab);
lay->addWidget(pCal);
connect(ui->tabWidget,SIGNAL(currentChanged(int)),this,SLOT(a(int)));


}


void MainWindow::a(int index)
{
switch(index)
{
case 0:
    callCal();
    break;

case 1:
    callHist();
    break;

default:
    break;
}


}

void MainWindow::callHist()
{

    HistoryForm *pHis = new HistoryForm();
    pHis->DisplayHistory();
    pHis->show();
    lay2 = new QVBoxLayout(ui->tab_2);
    lay2->addWidget(pHis);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T09:51:56+00:00Added an answer on May 24, 2026 at 9:51 am

    Everytime you switch the tab index, you create a new form. I am not sure if this is the cause of your problem, but it definitely is a problem.

    You should ensure the forms are only created once. For example you may create them in the constructor of MainWindow and store pointers to them in member variables. You should also already assign any required layouts there.

    When you switch the index, you just call the DisplayHistory() or equivalent method.

    PS: If you still want to understand your code next year, you should probably find a more speaking name than “a” for that slot 😉

    [Edit]
    Here is a sample header and cpp file. Be adviced that it might not compile as is and you might have to do some adjustments, but I wanna show you the general idea.

    Header file

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QtGui/QMainWindow>
    
    // forward declarations
    class CalendarForm;
    class HistoryForm;
    class StatisticsForm; // or whatever your 3rd form is called
    
    class MainWindow : QMainWindow
    {
    public:
        MainWindow(QWidget *parent);
        ~MainWindow();
    
    private slots:
    
        void currentTabChanged( int tabIndex );
    
    private:
    
        // these are called "member variables" as they are a member of a class
        // Sample naming convention: m_ for members, p for Pointer, you can use 
        // whatever you prefer, as long as you use it consistently.
    
        CalendarForm*   m_pCalendar;
        HistoryForm*    m_pHistory;
        StatisticsForm* m_pStatistics;
    
    
        // not sure about this part but it is generated by Qt anyway
        Ui::MainWindowClass* ui;
    
    
    };
    
    // not sure about this part but it is generated by Qt anyway
    namespace Ui {
        class MainWindowClass;
    }
    #endif // MAINWINDOW_H
    

    CPP File:

    // these includes should be present already anyway
    #include "MainWindow.h"
    #include "ui_mainwindow.h"
    
    #include "CalendarForm.h"
    #include "HistoryForm.h"
    #include "StatisticsForm.h"
    
    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
        m_pCalendar   = new CalendarForm();
        m_pHistory    = new HistoryForm();
        m_pStatistics = new StatisticsForm();
    
        ui->tabWidget->addTab( m_pCalendar );
        ui->tabWidget->addTab( m_pHistory );
        ui->tabWidget->addTab( m_pStatistics );
    
        connect( ui->tabWidget, SIGNAL( currentChanged   ( int ) ),
                 this         , SLOT  ( currentTabChanged( int ) );
    }
    
    MainWindow::~MainWindow()
    {
        delete m_pCalendar;
        delete m_pHistory;
        delete m_pStatistics;
    }
    
    void MainWindow::currentTabChanged( int tabIndex )
    {
        switch( tabIndex )
        {
        case 0:
            // update calculator if necessary
            break;
        case 1:
            // Assumption: You need to update the view every time you activate 
            // the tab. If this assumption is wrong, you don't need this slot
            // at all, just call the method once in the constructor.
            m_pHistory->DisplayHistory();
            break;
        case 2:
            // update statistics if necessary
            break;
        default:
            break;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have my own textbox which inherits System.Windows.Forms.TextBox I am trying to display texts
I'm trying to create a rendering template for my forms which need complex validations
i'm trying to check whether my forms(Zend_Form) are being well processed and display whatever
I'm trying to display one form relative to a Button on a control below
I'm trying to display a form on a template, but I get a fantastic
Trying to display current time with PHP (using this ): $date = date('m/d/Y h:i:s
When trying to display a byte stream from HLDS (Half-Life Dedicated Server) in a
I've been trying to display text using a Quartz context, but no matter what
I'm trying to display a series of titles varying from 60 characters to 160
I am trying to display a list of all files found in the selected

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.