Results 1 to 9 of 9

Thread: Ho two access ui of another widget?

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

    Default Ho two access ui of another widget?

    I have main widget consisting of tableview and button.
    When click on the button QDialog appears.
    I put some data and execute query.When click update in QDialog i close() the dialog and want to update the table in the Widget.
    If i wanted to update the dialog i would make like this

    ui->this->tableView->repaint(); or call another method.

    But how to reach and trigger the UI of another widget?From the dialog to update the table in the widget?

  2. #2
    Join Date
    Nov 2008
    Posts
    39
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Ho two access ui of another widget?

    QDialog has a signal finished(int), emitted when the dialog closes, using the signal updated the table.

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

    Default Re: Ho two access ui of another widget?

    Ok, but i want to update the table not in the dialog but in the widget
    The problem is not the signal but the slot and mainly how to trigger it.
    Last edited by unix7777; 13th December 2011 at 10:57.

  4. #4
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Ho two access ui of another widget?

    I'm confused.

    If you want to update a widget, you update the widget.
    If you want to update your table, you connect a signal from some other source (ie your dialog) to your table and that's it.

    If you asking how to get a pointer to your table to connect a signal then I say - you should have it.
    If you don't or can't have it, create a slot in parent of the table that will know what to do.

    If you don't want to use connect() then you can use QMetaObject:invokeMethod() but the principle is the same - you need to have an access to the object you want to connect/invoke method on.

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

    Default Re: Ho two access ui of another widget?

    i'm confused too.

    In the dialog with name groupsadddialog.cpp , .h, .ui i have pushbutton and i in the cpp file i have the following:

    void GroupsAddDialog:n_pushButton_add_clicked()
    {
    //ADDING NEW CUSTOMER
    QSqlQuery query;
    query.prepare("INSERT INTO customers (customer_id, name, address)"
    "VALUES (?, ?, ?)");
    query.addBindValue(ui->lineEdit_eik->text());
    query.addBindValue(ui->lineEdit_name->text());
    query.addBindValue(ui->lineEdit_address->text());
    query.exec();
    //here
    this->close();
    }

    i have widget with name groups.ui .cpp, .h and in this widget i have an object with name tableGroups

    Please tell me what could you write in the source when i comment with //here in order to update/redraw the table.The method doesn't matter , i just want to know how you'll get access to the object of the widget from the dialog.

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Ho two access ui of another widget?

    How is the table view connected to the content of the table? Are you using QSqlTableModel/QTableView or manually loading the data from the table into a QTableWidget? For the former you need to call QSqlTableModel::select() to requery the table, for the latter rerun your load function. You do this in a slot in your primary view. That slot is the target of a connection between a custom signal in your dialog and your primary view. At "//here" you emit that signal.

    There are other ways to architect this.

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

    Default Re: Ho two access ui of another widget?

    i use QSqlTableModel and QTableView

    Could you give me joker about other design patterns?
    Last edited by unix7777; 14th December 2011 at 10:52.

  8. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Ho two access ui of another widget?

    At the moment you are directly changing the table underneath the model. The model has no way to know this, so you have to manually cause the QSqlTableModel to re-read the table (which has the side-effect of invalidating selections, indexes etc). If your dialog is opened modal then you can do this when the exec() call returns and the user did not cancel the operation.

    If your dialog used the model, and updated the values in the model using the setData() method, then the other views would automatically update to the new values. You still have to manage when this is committed to the database and be careful of invalidating model indexes you still need.

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

    Default Re: Ho two access ui of another widget?

    Ok, this approach sounds reasonable!!!
    The problem with accessing the model remains.I mean i don't know how to do it.I f you want to spend 5 min to post some code i'll be very gratefull.
    You can do it for example with QWidget with QButton, and QDialog that opens when the button is clicked.And when you click in the QDialog button to update Qlabel that belongs to QWidget for instance.
    It's the easiest example i can figure out.

    Than you in advance

Similar Threads

  1. Own widget access causes crash
    By p3t3 in forum Newbie
    Replies: 1
    Last Post: 24th March 2011, 02:13
  2. how can i access other form widget
    By crissti_cta in forum Newbie
    Replies: 2
    Last Post: 14th December 2010, 21:51
  3. Can you access the parent widget of a subclass
    By jshafferman in forum Qt Programming
    Replies: 4
    Last Post: 8th December 2010, 18:30
  4. Access form's widget's in other class
    By p3c0 in forum Newbie
    Replies: 3
    Last Post: 12th June 2010, 15:20
  5. access the widget dynamically
    By mohanakrishnan in forum Qt Programming
    Replies: 4
    Last Post: 26th November 2009, 13:37

Tags for this Thread

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.