scott_hollen
26th February 2011, 22:28
I've always, since I set down at a teletype in '82, believed in programming things the right, not necessarily in just making something work, so while I've got something working just fine, I wanted to see if anyone had any advice on working with a stacked widget with a tab widget with 2 tabs.
I have a list widget on the left side of my app which can fire off the correct tab widget slot. I'd actually like different functions for both of my tabs but for now the only way I can get the whole tab widget to work is write the code in the following manner (on_RiserPB_clicked receives the signal from my list widget):
void MainWindow::on_RiserPB_clicked()
{
on_RiserTabWidget_currentChanged (0);
}
void MainWindow::on_RiserTabWidget_currentChanged(int index)
{
switch (index)
{
case 0:
//*****************************************
//* Retrieving data for the Flowpath... *
//*****************************************
flowlinemodel = new QSqlTableModel(this);
flowlinemodel->setTable ("flowpath");
flowlinemodel->sort (0, Qt::AscendingOrder);
flowlinemodel->setEditStrategy (QSqlTableModel::OnManualSubmit);
flowlinemodel->select ();
//**********************************************
//* Retrieving data for the Flowpath data... *
//**********************************************
flowpathmodel = new QSqlTableModel(this);
flowpathmodel->setTable ("flowdata");
flowpathmodel->sort (0, Qt::AscendingOrder);
flowpathmodel->setEditStrategy (QSqlTableModel::OnManualSubmit);
flowpathmodel->select ();
break;
case 1:
//* This handles the 2nd tab...
break;
}
}
The experienced, but obviously in other languages, programmer tells me this is kludgy. It *works* but is it the best or correct way to be doing what I'm trying to do?
scott
I have a list widget on the left side of my app which can fire off the correct tab widget slot. I'd actually like different functions for both of my tabs but for now the only way I can get the whole tab widget to work is write the code in the following manner (on_RiserPB_clicked receives the signal from my list widget):
void MainWindow::on_RiserPB_clicked()
{
on_RiserTabWidget_currentChanged (0);
}
void MainWindow::on_RiserTabWidget_currentChanged(int index)
{
switch (index)
{
case 0:
//*****************************************
//* Retrieving data for the Flowpath... *
//*****************************************
flowlinemodel = new QSqlTableModel(this);
flowlinemodel->setTable ("flowpath");
flowlinemodel->sort (0, Qt::AscendingOrder);
flowlinemodel->setEditStrategy (QSqlTableModel::OnManualSubmit);
flowlinemodel->select ();
//**********************************************
//* Retrieving data for the Flowpath data... *
//**********************************************
flowpathmodel = new QSqlTableModel(this);
flowpathmodel->setTable ("flowdata");
flowpathmodel->sort (0, Qt::AscendingOrder);
flowpathmodel->setEditStrategy (QSqlTableModel::OnManualSubmit);
flowpathmodel->select ();
break;
case 1:
//* This handles the 2nd tab...
break;
}
}
The experienced, but obviously in other languages, programmer tells me this is kludgy. It *works* but is it the best or correct way to be doing what I'm trying to do?
scott