Results 1 to 15 of 15

Thread: Updating Table Values.

  1. #1
    Join Date
    Feb 2007
    Posts
    22
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Updating Table Values.

    Hi All,

    I am new to Qt Designer. My query is has follows

    I have two dialog boxes. In the first one I have a table. In the second dialog box I have a push button which when clicked should set the value in the table of the first dialog box.

    For which I have used the following code segment.

    void Parameter_Selection_Dlg::ProcessParams()
    {
    a.table1->setText( 1, 1, "qqq" );
    this->close();
    }

    Now The problem is the value is not been updated in the table. I dont know why?
    I used repaint, show, update in both this dialog box and init function of the first dialog box.

    Can Anyone Please Help Me Solve This Problem..........

    Thanks and Regards In Advance,
    Kenny

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Updating Table Values.

    How many rows and columns your table has?

  3. #3
    Join Date
    Feb 2007
    Posts
    22
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Updating Table Values.

    18 rows and 4 columns

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Updating Table Values.

    How did you declare "a"?

  5. #5
    Join Date
    Feb 2007
    Posts
    22
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Updating Table Values.

    RawValueDisplay *a = new RawValueDisplay(this);

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Updating Table Values.

    Quote Originally Posted by kenny_isles View Post
    RawValueDisplay *a = new RawValueDisplay(this);
    Are you sure? In such case this:
    Qt Code:
    1. a.table1->setText( 1, 1, "qqq" );
    To copy to clipboard, switch view to plain text mode 
    shouldn't even compile. Maybe you have two "a" variables?

  7. #7
    Join Date
    Feb 2007
    Posts
    22
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Updating Table Values.

    This is the code segment I am working with from morning. But None Seems to be working.

    //-----------------------------------------------------------------------------------------------------
    void Parameter_Selection_Dlg::ProcessParams()
    {
    // class QTable();
    RawValueDisplay *a = new RawValueDisplay(this);


    // this->table_1 = new QTable();
    a->table1->setText( 1, 1, "qqq" );

    // a->table1->hideColumn(1);
    this->close();
    // a->setUpdatesEnabled(TRUE);
    // a->close();

    // a->repaint(TRUE);
    // a->exec();
    // a->init();

    // a->showMaximized();

    }
    //--------------------------------------------------------------------------------------------

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Updating Table Values.

    Quote Originally Posted by kenny_isles View Post
    void Parameter_Selection_Dlg::ProcessParams()
    {
    // class QTable();
    RawValueDisplay *a = new RawValueDisplay(this);
    ...
    }
    Here you are creating a new widget. If you want to update the table in existing one, you need a pointer to that previously created widget.

  9. #9
    Join Date
    Feb 2007
    Posts
    22
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Updating Table Values.

    Well RawValueDisplay is the first dialog box. It is a class. So I am creating a object to that class to access the member table.

    I am doing this is in VC++ style.

    So Please tell me how to use that existing widget object.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Updating Table Values.

    Quote Originally Posted by kenny_isles View Post
    Well RawValueDisplay is the first dialog box. It is a class. So I am creating a object to that class to access the member table.
    OK, but do you displaycreate RawValueDisplay first, then show Parameter_Selection_Dlg or the other way around (i.e. you show Parameter_Selection_Dlg first and then you want to show a new RawValueDisplay)?

  11. #11
    Join Date
    Feb 2007
    Posts
    22
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Updating Table Values.

    Yes. I am able to launch the dialog boxes properly. But not able to set the values.

    RawValueDisplay has the table and is the first DLG.

    Parameter..............is the second DLG having a push button.

    Once push button is pressed value should be displayed in table.

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Updating Table Values.

    There are three solutions:

    1) pass a pointer to the first dialog
    Qt Code:
    1. SecondDialog::SecondDialog( FirstDialog *ptr, QWidget *parent )
    2. : QDialog( parent ), _firstDialogPtr( ptr )
    3. {
    4. ...
    5. }
    6.  
    7. ...
    8.  
    9. void SecondDialog::processParams()
    10. {
    11. ...
    12. _firstDialogPtr->setSomenting( whatever );
    13. ...
    14. }
    To copy to clipboard, switch view to plain text mode 
    This is quite easy solution, but it also the worst one (except for the one with global variables which I won't even mention). It's bad, because both dialogs are tightly coupled.

    2) use accessor methods to retrieve data from the SecondDialog:
    Qt Code:
    1. void FirstDialog::doSomething()
    2. {
    3. SecondDialog dlg( this );
    4. if( dlg.exec() == Qt::Accepted ) {
    5. someWidget->setSomething( dlg.something() ); // SecondDialog::something() returns the data you need
    6. ...
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 
    This is a bit better approach, since you can reuse SecondDialog for other purposes.

    3) Use signals and slots:
    Qt Code:
    1. void FirstDialog::showSecondDialog()
    2. {
    3. SecondDialog *dlg = new SecondDialog( this );
    4. dlg->setWFlags( dlg->getWFlags() | Qt::WDestructiveClose );
    5.  
    6. connect( dlg, SIGNAL( somethingChanged( int ) ),
    7. this, SLOT( setSomething( int ) ) );
    8. ...
    9.  
    10. dlg->show();
    11. }
    To copy to clipboard, switch view to plain text mode 
    This is the version with minimal coupling, but it also requires a bit more work than other ones.

  13. #13
    Join Date
    Feb 2007
    Posts
    22
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Updating Table Values.

    Hi

    The code is working however i want to know why the following approach dosnt work.
    I will attach the code segment also.

    Parameter_Selection_Dlg *b = new Parameter_Selection_Dlg(this);
    b->show();
    b->ChoosenParam_lb->setCurrentItem(0);
    table1->setText(1,1,b->ChoosenParam_lb->currentText());

    A is a dialog box which has a table and B is another class that has a list box.
    As the above I am trying to upload the values into from B to A.
    So ChoosenParam_lb is the List box name residing in Class B.
    table1 is the name of the table.

    Plz tell me as to why it is not showing the values.

    With Regards
    Kenny.

  14. #14
    Join Date
    Feb 2007
    Posts
    22
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Updating Table Values.

    This is the second method u suggested

  15. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Table Value not updating

    Quote Originally Posted by kenny_isles View Post
    Plz tell me as to why it is not showing the values.
    Most likely because show() is a non-blocking call and "ChoosenParam_lb" is still empty when you check its current text. Try exec() instead of show() --- this way you will have a modal dialog. Otherwise you will need two methods: one that shows the dialog and another one that retrieves data from it after it was closed.

    PS. Please, don't post the same question multiple times.
    Last edited by jacek; 13th February 2007 at 11:13.

Similar Threads

  1. Replies: 11
    Last Post: 7th September 2006, 23:15
  2. displaying any table on a qdatatable
    By Philip_Anselmo in forum Newbie
    Replies: 4
    Last Post: 9th May 2006, 22:12
  3. creating table plugin
    By mgurbuz in forum Qt Programming
    Replies: 3
    Last Post: 28th April 2006, 13:50
  4. Adding row in a Table after selected row
    By ankurjain in forum Qt Programming
    Replies: 3
    Last Post: 20th April 2006, 18:06
  5. adding in values to table
    By therealjag in forum Qt Programming
    Replies: 2
    Last Post: 9th February 2006, 16: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.