Page 2 of 2 FirstFirst 12
Results 21 to 29 of 29

Thread: tableview and pushbutton connection

  1. #21
    Join Date
    Nov 2009
    Posts
    129
    Thanks
    4
    Thanked 29 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: tableview and pushbutton connection

    I don’t know what all is in updateClientTable, but I’m going to suggest trying:
    Qt Code:
    1. Clients::Clients(QWidget *parent) :
    2. QDialog(parent),
    3. ui(new Ui::Clients)
    4. {
    5. ui->setupUi(this);
    6.  
    7. updateClientTable();
    8.  
    9. setBool();
    10.  
    11. connect(ui->tableView_clients->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
    12. this, SLOT(setBool()));
    13.  
    14. }
    To copy to clipboard, switch view to plain text mode 
    and seeing if it makes any difference.

  2. #22
    Join Date
    Mar 2009
    Posts
    104
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: tableview and pushbutton connection

    Doing so the button is enabled even i don't select a row.
    I use updateClientTable() to update the content of TableView after every manipulation (search, add, delete etc.)
    What i understand is that on this way the SLOT is always called!
    Last edited by unix7777; 2nd September 2012 at 22:29.

  3. #23
    Join Date
    Nov 2009
    Posts
    129
    Thanks
    4
    Thanked 29 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: tableview and pushbutton connection

    Quote Originally Posted by unix7777 View Post
    Doing so the button is enabled even i don't select a row.
    I use updateClientTable() to update the content of TableView after every manipulation (search, add, delete etc.)
    What i understand is that on this way the SLOT is always called!
    OK... now bear with me... just trying to find a way to debug this...

    Change the declaration of setBool to:
    Qt Code:
    1. void setBool(const QModelIndex& current, const QModelIndex& previous);
    To copy to clipboard, switch view to plain text mode 
    change the definition to:
    Qt Code:
    1. void Clients::setBool(const QModelIndex& current, const QModelIndex& previous) {
    2. qDebug() << "At setBool" << current << previous << ui->tableView_clients->currentIndex();
    3. ui->pushButton_select->setEnabled(ui->tableView_clients->currentIndex().isValid());
    4. }
    To copy to clipboard, switch view to plain text mode 
    and change the Clients constructor to:
    Qt Code:
    1. Clients::Clients(QWidget *parent) :
    2. QDialog(parent),
    3. ui(new Ui::Clients)
    4. {
    5. ui->setupUi(this);
    6. updateClientTable();
    7. setBool(ui->tableView_clients->currentIndex(), QModelIndex());
    8. connect(ui->tableView_clients->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), this, SLOT(setBool(QModelIndex,QModelIndex)));
    9. }
    To copy to clipboard, switch view to plain text mode 
    and let’s see if we can spot anything unexpected going on in the debug output. Watch to see when setBool is called and that the previous and current indices are what you would expect.

    I know you said you have a problem with seeing the debug output because of difficulty connecting to your SQLite file under QtCreator. I can’t help you there, but it’s probably worth finding a way to make it work.

  4. #24
    Join Date
    Mar 2009
    Posts
    104
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: tableview and pushbutton connection

    Qt Code:
    1. Qt_SDK__Debug/../Faktura/clients.h:41: error: expected ',' or '...' before '&' token
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. Qt_SDK__Debug/../Faktura/clients.h:41: error: ISO C++ forbids declaration of 'QModelIndex' with no type
    To copy to clipboard, switch view to plain text mode 

  5. #25
    Join Date
    Mar 2009
    Posts
    104
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: tableview and pushbutton connection

    I debugged the problem but i still have no solution.
    The problem is that the slot is triggered immediately after creating the dialog/tableview.After that when the selection changes the slot is called.
    This means that at first i don't use the right signal (the signal i use is for change selection, but not when the there is selection) and secondly why the signal calls immediately after creating the tableview.
    PLEASE HELP, i really fed up with this

  6. #26
    Join Date
    Nov 2009
    Posts
    129
    Thanks
    4
    Thanked 29 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: tableview and pushbutton connection

    Quote Originally Posted by unix7777 View Post
    I debugged the problem but i still have no solution.
    The problem is that the slot is triggered immediately after creating the dialog/tableview.After that when the selection changes the slot is called.
    This means that at first i don't use the right signal (the signal i use is for change selection, but not when the there is selection) and secondly why the signal calls immediately after creating the tableview.
    PLEASE HELP, i really fed up with this
    I’m a bit confused as to what is the problem.

    You say that the slot is being called when the selection changes, but then that it’s not the right signal to tell whether there is a selection.

    Is the slot not being called when the selection changes from “something is selected” to “nothing is selected”?

    Or are you having trouble distinguishing, within the slot, whether something is selected or not?

    The slot might be called in cases where you don’t need to do anything; but that shouldn’t be a problem, so long as it is being called whenever you do need to do something, and you can tell in the slot whether the button needs to be enabled or disabled at that time.

    As far as being triggered “immediately after creating the dialog/tableview”... you did take out the explicit call to setBool() before the connect, if you don’t want it called there?

  7. #27
    Join Date
    Mar 2009
    Posts
    104
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: tableview and pushbutton connection

    I have changed the code to:
    Qt Code:
    1. Clients::Clients(QWidget *parent) :
    2. QDialog(parent),
    3. ui(new Ui::Clients)
    4. {
    5. ui->setupUi(this);
    6.  
    7. updateClientTable();
    8.  
    9. connect(ui->tableView_clients->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
    10. this, SLOT(setBool()));
    11. }
    To copy to clipboard, switch view to plain text mode 

    and

    Qt Code:
    1. void Clients::setBool()
    2. {
    3. ui->pushButton_select->setEnabled(ui->tableView_clients->currentIndex().isValid());
    4. //QMessageBox::information(this, "", "SLOT IS TRIGGERED");
    5. }
    To copy to clipboard, switch view to plain text mode 

    With this code we have some partial success.When the dialog is created the button is disabled.When i select some row it becomes enabled.But!But it doesn't do it on reverse, when again nothing is selected it doesn't become disabled again!

  8. #28
    Join Date
    Nov 2009
    Posts
    129
    Thanks
    4
    Thanked 29 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: tableview and pushbutton connection

    Quote Originally Posted by unix7777 View Post
    With this code we have some partial success.When the dialog is created the button is disabled.When i select some row it becomes enabled.But!But it doesn't do it on reverse, when again nothing is selected it doesn't become disabled again!
    What causes nothing to be selected? I mean, what method do you call under what circumstances... how does the selection get set to nothing?

    Did your testing (when you had the QMessageBox uncommented) show that the slot was being called at all when that happened? (If it’s not being called, that’s one problem; if it’s being called but currentIndex().isValid() is returning true when we expect it to be false, that’s something else.)

    It is possible that I’ve let you astray... I see that there is a subtle difference between “current” and “selected” in a tableview and apparently they need not always be the same, even when the selection mode is SingleSelection. I didn’t run into this distinction in my program, but it might be relevant to yours. I’m not certain under just what conditions it becomes important to distinguish between the two. If your logic is causing the selection to be set to nothing but leaving the current item valid, then my suggestion to use currentIndex().isValid() was wrong. I’m not sure of this, because I haven’t used it, but it could be that ui->tableView_clients->selectionModel()->hasSelection() is what you need instead of ui->tableView_clients->currentIndex().isValid().

  9. #29
    Join Date
    Mar 2009
    Posts
    104
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: tableview and pushbutton connection

    It was exactly what i need.And of course it works perfect.THANK YOU!
    You ask why i need to check whether some row is selected instead to get whether the selected row has changed.The answer is simple.If there are no too much records in the table there is some blank space.When you click on this space no row is selected.The same occurs when you click on lineEdit above.


    Added after 41 minutes:


    Something strange happens, after updating the model, meaning delete, add or edit, the signal doesn't work.
    Last edited by unix7777; 7th September 2012 at 07:09.

Similar Threads

  1. PushButton
    By acuce in forum Qt Programming
    Replies: 2
    Last Post: 13th July 2012, 20:06
  2. Replies: 0
    Last Post: 11th November 2011, 19:18
  3. Replies: 3
    Last Post: 29th April 2011, 08:54
  4. How to use a QPolygon as a Pushbutton?
    By Manish.S in forum Newbie
    Replies: 4
    Last Post: 6th December 2010, 10:57
  5. Replies: 1
    Last Post: 2nd April 2010, 06:42

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.