Results 1 to 10 of 10

Thread: QTableView refresh

  1. #1
    Join Date
    Nov 2006
    Posts
    96

    Default QTableView refresh

    Hi.

    I created a QTableView which look like this: http://doc.trolltech.com/4.3/sql-rel...ablemodel.html

    But the problem is when I add a row (I use QDialog for that).

    So, a QDialog pops up and I fill out all the required fields and then I press ok (to save all the data to mysql table and close the QDialog)

    What I want to do now is: when this QDialog window is closed I want to refresh the QTableView, so it will reflect the currently added row.

    Now I have to reopen the program (reconnect to the database/table) in order to do that.

    Is there an option for that?

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView refresh

    Try calling model->select again. I am not sure if it works.

    But why do you do it like this? You could add another row in the model and let the model submit the data. You shouldn't insert it manually. Then why use a model anyway? Just for reading data?

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTableView refresh

    Hi eleanor

    Try QSqlTableModel::select()
    J-P Nurmi

  4. #4
    Join Date
    Nov 2006
    Posts
    96

    Default Re: QTableView refresh

    Hi,it's me again.

    Thanks for the advices, it works.

    Now, I need another advice:

    1 ) this is the declaration of a public slot
    void add_changes(QString table_name);

    2) I call it like this
    connect(ok_button,SIGNAL(clicked()),this,SLOT(add_ changes(table)));
    - the table = "town";

    3) the error is:
    Object::connect: No such slot dbWindow::add_changes(table)

    What's wring.



    And I have another question:
    - how can I sort this dropdown menu alphanumerically: http://doc.trolltech.com/4.3/images/relationaltable.png
    Last edited by eleanor; 6th October 2007 at 14:20.

  5. #5
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView refresh

    Now, I need another advice:

    1 ) this is the declaration of a public slot
    void add_changes(QString table_name);

    2) I call it like this
    connect(ok_button,SIGNAL(clicked()),this,SLOT(add_ changes(table)));
    - the table = "town";

    3) the error is:
    Object::connect: No such slot dbWindow::add_changes(table)

    What's wring.
    You can't pass a parameter to a slot like that.
    To make this work it really depends on what you need to do.
    Do you have multiple buttons, one for each table?
    You have to do a mapping from buttons to table names. You can use a QSignalMapper or use sender() in the slot to identify the button and use the correct table name. or you could create multiple slots.

    And I have another question:
    - how can I sort this dropdown menu alphanumerically: http://doc.trolltech.com/4.3/images/relationaltable.png
    That's the QSqlRelationDelegate. I'm afreaid you can't do much about it.

  6. #6
    Join Date
    Nov 2006
    Posts
    96

    Default Re: QTableView refresh

    I don't have buttons for each table. Can you tell me how to do it with multiple slots?

  7. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTableView refresh

    You could also declare the slot with a default parameter like this:
    Qt Code:
    1. void add_changes(QString table_name = "town");
    To copy to clipboard, switch view to plain text mode 
    Then you'd establish the connection without a parameter:
    Qt Code:
    1. connect(ok_button,SIGNAL(clicked()),this,SLOT(add_changes()));
    To copy to clipboard, switch view to plain text mode 
    Whenever the button is clicked, the default parameter "town" will be used. If you want to call the function with another parameter in code, just pass so:
    Qt Code:
    1. add_changes("foo");
    To copy to clipboard, switch view to plain text mode 
    And I have another question:
    - how can I sort this dropdown menu alphanumerically: http://doc.trolltech.com/4.3/images/relationaltable.png
    I guess you would have to subclass QSqlRelationalDelegate and reimplement setEditorData():
    Qt Code:
    1. void MySqlRelationalDelegate::setEditorData(QWidget* editor, const QModelIndex & index) const
    2. {
    3. QSqlRelationalDelegate::setEditorData(editor, index);
    4. if (QComboBox* combo = dynamic_cast<QComboBox*>(editor))
    5. {
    6. proxy->setSourceModel(combo->model());
    7. // combo's current model must be reparented, otherwise QComboBox::setModel() will delete it
    8. combo->model()->setParent(proxy);
    9. combo->setModel(proxy);
    10. combo->model()->sort(0);
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  8. #8
    Join Date
    Nov 2006
    Posts
    96

    Default Re: QTableView refresh

    Thanks for the info.

    Another question:

    /* MENU */
    QMenu *sifrant_meni = new QMenu();
    sifrant_meni->addAction(tr("Kraj"),this,SLOT(open_window()));
    sifrant_meni->addAction(tr("Podjetje"),this,SLOT(open_window()) );
    sifrant_meni->addAction(tr("Zapri"),this,SLOT(close()));

    QMenuBar *top_meni = new QMenuBar(this);
    top_meni->addMenu(tr("Sifrant"));
    top_meni->addMenu(sifrant_meni);



    When i compile this code the Sifrant QMenuBar shows up fine, but when I click it there are no actions, why?

  9. #9
    Join Date
    Nov 2006
    Posts
    96

    Default Re: QTableView refresh

    I sloved it:

    //meni
    QMenu *sifrant_meni = new QMenu(this);
    sifrant_meni->addAction(tr("Kraj"),this,SLOT(open_window()));
    sifrant_meni->addAction(tr("Podjetje"),this,SLOT(open_window()) );
    sifrant_meni->addAction(tr("Zapri"),this,SLOT(close()));
    sifrant_meni->setTitle(tr("Sifrant"));

    QMenuBar *top_meni = new QMenuBar(this);
    top_meni->addMenu(sifrant_meni);

  10. #10
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTableView refresh

    Quote Originally Posted by eleanor View Post
    Another question:
    Could you start a new thread with a meaningful title next time. I mean, don't ask unrelated questions in same thread, please.
    J-P Nurmi

Similar Threads

  1. QTableView currentChanged <> selecting header
    By Everall in forum Qt Programming
    Replies: 4
    Last Post: 1st April 2009, 08:24
  2. QTableView refresh problem
    By tebessum in forum Qt Programming
    Replies: 3
    Last Post: 29th December 2006, 11:22
  3. Replies: 9
    Last Post: 7th November 2006, 15:10
  4. QTableView paints too much
    By Jimmy2775 in forum Qt Programming
    Replies: 2
    Last Post: 26th July 2006, 18:42
  5. Multi-line messages in QTableView
    By Conel in forum Qt Programming
    Replies: 6
    Last Post: 13th April 2006, 13:49

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.