PDA

View Full Version : Stacked widget, tab widget, tabs



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

tbscope
27th February 2011, 05:39
You can look into a signal mapper.
http://doc.qt.nokia.com/4.7/qsignalmapper.html

By the way, you're leaking memory.

scott_hollen
28th February 2011, 01:13
You can look into a signal mapper.
http://doc.qt.nokia.com/4.7/qsignalmapper.html

By the way, you're leaking memory.

Okay, I'm editing my previous response because I'm brain dead tonight...Thanks for the suggestion about the signal mapping -- I was confused about widget mapping...I'll read up on this because I don't like I've coded it...

BTW, this isn't the completed code -- I guess I should have said that from the start, or at least yanked the SQL part out because I actually need to use a QSqlRelationalTableModel and plan to distribute that data to 2 TableViews...I was in the process of removing code from a failed experiment and just left it there for now...I should have yanked everything out of case 0 before posting...Sorry about the confusion...