Results 1 to 9 of 9

Thread: Listwidget->tabwidget->tableview signal to activate

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

    Default Listwidget->tabwidget->tableview signal to activate

    Okay, I know I'm a babe in the woods with Qt, but I *am* figuring out things, but this latest issue is a headscratcher...I think it comes down to something simple...

    I have a list widget consisting of 5 push buttons. These are connected to a stacked widget of 5 tab widgets. On one of these tab widgets (A User admin one) is a TableView populated by a QSqlTableModel. A clicked() signal on on a button connects to a show() slot for this widget; I also have a clicked() signal connected to a slot called MainWindow::On_UserPB_Clicked. This is where I need help.

    If I create my QSqlTableModel in the On_UserPB_Clicked slot and feed it to my TableView, everything works perfectly. I can add to it and edit it, I can click on other push buttons in my list widget and come back to the User tabwidget and all is well. However, according to everything I'm reading, I really should be creating the model and populating the TableView in the MainWindow::MainWindow constructor, but when I do this, my tab widget still gets displayed correctly, but there is no TableView to work with, and I don't know how to get this to appear.

    Is there another signal I need to be capturing? I tried to connect a clicked() signal to a show() and an update() slot for my TableView, but to no avail...

    I'm saving space and not posting the code (plus it's actually working when in the slot), I just don't know how to get it to display if it's defined in the constructor...

    Thanks in advance!

    scott

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Listwidget->tabwidget->tableview signal to activate

    How does your constructor look like?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Default Re: Listwidget->tabwidget->tableview signal to activate

    Here's the constuctor -- from my comment that begins "Retrieve" on down works if instead of here in the constructor it's coded in my slot for the buttonclicked() signal...Right now, if the code is in the constructor, I need some method to display the model...

    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4.  
    5. {
    6. ui->setupUi(this);
    7.  
    8. //*******************************************************
    9. //* Retrieve data from the USER table for managing... *
    10. //*******************************************************
    11. usertablemodel = new QSqlTableModel(this);
    12.  
    13. usertablemodel->setTable ("user");
    14. usertablemodel->sort (0, Qt::AscendingOrder);
    15.  
    16. usertablemodel->setEditStrategy (QSqlTableModel::OnManualSubmit);
    17. usertablemodel->select ();
    18.  
    19. usertablemodel->setHeaderData (0, Qt::Horizontal,
    20. QObject::tr("Username"));
    21. usertablemodel->setHeaderData (1, Qt::Horizontal,
    22. QObject::tr("Password"));
    23. usertablemodel->setHeaderData (2, Qt::Horizontal,
    24. QObject::tr("Full Name"));
    25. usertablemodel->setHeaderData (3, Qt::Horizontal,
    26. QObject::tr("Status"));
    27. usertablemodel->setHeaderData (4, Qt::Horizontal,
    28. QObject::tr("Access Level"));
    29. usertablemodel->setHeaderData (5, Qt::Horizontal,
    30. QObject::tr("User Name"));
    31. usertablemodel->setHeaderData (6, Qt::Horizontal,
    32. QObject::tr("Activity Date"));
    33.  
    34. ui->ManageUsersTV->setModel (usertablemodel);
    35. ui->ManageUsersTV->resizeColumnsToContents ();
    36.  
    37. ui->ManageUsersTV->setEditTriggers (QAbstractItemView::AnyKeyPressed |
    38. QAbstractItemView::DoubleClicked);
    39.  
    40. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Listwidget->tabwidget->tableview signal to activate

    So what's wrong exactly? The model seems to be properly set on the view. Assuming of course ui->ManageUsersTV is the view we're talking about.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Default Re: Listwidget->tabwidget->tableview signal to activate

    Yep, that's the correct view

    Well, I have a clicked() signal attached to a pushbutton, so I had this code in my slot for that signal and it displayed the tableview fine. I thought it would be a better design approach to have this code in the constuctor instead (but I could be wrong), so now, I don't know what to do in my slot to get the tableview to display.

    Here is what my slot previously looked like (identical to the constructor) -- my question is if I put this in the constuctor instead of the slot, how do I get the tableview to display?

    Qt Code:
    1. void MainWindow::on_AdminPB_clicked()
    2. {
    3. //*******************************************************
    4. //* Retrieve data from the USER table for managing... *
    5. //*******************************************************
    6. usertablemodel = new QSqlTableModel(this);
    7.  
    8. usertablemodel->setTable ("user");
    9. usertablemodel->sort (0, Qt::AscendingOrder);
    10.  
    11. usertablemodel->setEditStrategy (QSqlTableModel::OnManualSubmit);
    12. usertablemodel->select ();
    13.  
    14. usertablemodel->setHeaderData (0, Qt::Horizontal,
    15. QObject::tr("Username"));
    16. usertablemodel->setHeaderData (1, Qt::Horizontal,
    17. QObject::tr("Password"));
    18. usertablemodel->setHeaderData (2, Qt::Horizontal,
    19. QObject::tr("Full Name"));
    20. usertablemodel->setHeaderData (3, Qt::Horizontal,
    21. QObject::tr("Status"));
    22. usertablemodel->setHeaderData (4, Qt::Horizontal,
    23. QObject::tr("Access Level"));
    24. usertablemodel->setHeaderData (5, Qt::Horizontal,
    25. QObject::tr("User Name"));
    26. usertablemodel->setHeaderData (6, Qt::Horizontal,
    27. QObject::tr("Activity Date"));
    28.  
    29. ui->ManageUsersTV->setModel (usertablemodel);
    30. ui->ManageUsersTV->resizeColumnsToContents ();
    31.  
    32. ui->ManageUsersTV->setEditTriggers (QAbstractItemView::AnyKeyPressed |
    33. QAbstractItemView::DoubleClicked);
    34.  
    35. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Listwidget->tabwidget->tableview signal to activate

    I don't really see the problem. You show a widget by calling show() on it or on its parent. It doesn't matter where you setup the model. The only part that will not work is resizeColumnsToContents() as it needs the view to be fully initialized to fulfill your request. You can do it on showEvent() or you can change the resize mode of the header to ResizeToContents.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. The following user says thank you to wysota for this useful post:

    scott_hollen (6th March 2011)

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

    Default Re: Listwidget->tabwidget->tableview signal to activate

    I tried a show() but it didn't work, but I'll try it again...I appreciate your help -- glad to know I'm not crazy!! (well, the jury's still out on that one)


    scott

  9. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Listwidget->tabwidget->tableview signal to activate

    Please explain what you mean by "didn't work".
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Default Re: Listwidget->tabwidget->tableview signal to activate

    Sorry for the delay in responding - family issues took me off my project for a few days...

    I resolved this yesterday -- turns out there was nothing wrong with my code, only where it was being executed...If I placed it in the constructor, then, when my slot was fired I would get blank tableview(s)...When the same code was placed *in* my slot, everything displayed fine. Well, when my app first starts up, there is a login screen for my DB connection, and that was taking place *after* the tableviews/models were being defined -- meaning, they had no database to operate on so therefore they had no data...When moved the login to before the construction of my tableviews/models, everything worked perfect...Tableviews need DB connections before they'll work right

    Thanks for you help!


    scott

Similar Threads

  1. Replies: 3
    Last Post: 6th October 2010, 08:33
  2. How I can activate QODBC in Qt4 for windows
    By vcp in forum Qt Programming
    Replies: 6
    Last Post: 2nd July 2010, 06:45
  3. activate window
    By parmar ranjit in forum Qt Tools
    Replies: 12
    Last Post: 30th April 2008, 07:04
  4. TableView navigate signal/event
    By skuda in forum Qt Programming
    Replies: 2
    Last Post: 25th January 2008, 15:52
  5. How to activate another process?
    By gtthang in forum Qt Programming
    Replies: 6
    Last Post: 3rd February 2006, 07:53

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
  •  
Qt is a trademark of The Qt Company.