Results 1 to 3 of 3

Thread: Stacked widget, tab widget, tabs

  1. #1
    Join Date
    Jan 2011
    Location
    Richmond, VA
    Posts
    94
    Thanks
    14
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Stacked widget, tab widget, tabs

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

    Qt Code:
    1. void MainWindow::on_RiserPB_clicked()
    2. {
    3. on_RiserTabWidget_currentChanged (0);
    4. }
    5.  
    6. void MainWindow::on_RiserTabWidget_currentChanged(int index)
    7. {
    8.  
    9. switch (index)
    10. {
    11. case 0:
    12.  
    13. //*****************************************
    14. //* Retrieving data for the Flowpath... *
    15. //*****************************************
    16. flowlinemodel = new QSqlTableModel(this);
    17. flowlinemodel->setTable ("flowpath");
    18. flowlinemodel->sort (0, Qt::AscendingOrder);
    19.  
    20. flowlinemodel->setEditStrategy (QSqlTableModel::OnManualSubmit);
    21. flowlinemodel->select ();
    22.  
    23.  
    24. //**********************************************
    25. //* Retrieving data for the Flowpath data... *
    26. //**********************************************
    27. flowpathmodel = new QSqlTableModel(this);
    28. flowpathmodel->setTable ("flowdata");
    29. flowpathmodel->sort (0, Qt::AscendingOrder);
    30.  
    31. flowpathmodel->setEditStrategy (QSqlTableModel::OnManualSubmit);
    32. flowpathmodel->select ();
    33.  
    34. break;
    35.  
    36. case 1:
    37. //* This handles the 2nd tab...
    38. break;
    39. }
    40. }
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Stacked widget, tab widget, tabs

    You can look into a signal mapper.
    http://doc.qt.nokia.com/4.7/qsignalmapper.html

    By the way, you're leaking memory.

  3. #3
    Join Date
    Jan 2011
    Location
    Richmond, VA
    Posts
    94
    Thanks
    14
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Stacked widget, tab widget, tabs

    Quote Originally Posted by tbscope View Post
    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...
    Last edited by scott_hollen; 28th February 2011 at 01:23. Reason: My brain is mush

Similar Threads

  1. problem in stacked widget
    By wagmare in forum Qt Programming
    Replies: 4
    Last Post: 24th February 2009, 08:28
  2. Stacked widget mouse propagation
    By bunjee in forum Qt Programming
    Replies: 3
    Last Post: 14th November 2008, 17:54
  3. Stacked Widget Scroll
    By csvivek in forum Qt Programming
    Replies: 6
    Last Post: 27th May 2008, 11:36
  4. Stacked Layout. & Widget.
    By csvivek in forum Qt Programming
    Replies: 1
    Last Post: 13th May 2008, 08:56
  5. Acces a stacked widget...?
    By ucomesdag in forum Qt Programming
    Replies: 5
    Last Post: 25th November 2006, 14:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.