PDA

View Full Version : Updating Table Values.



kenny_isles
9th February 2007, 10:23
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

jacek
9th February 2007, 10:58
How many rows and columns your table has?

kenny_isles
9th February 2007, 11:05
18 rows and 4 columns

jacek
9th February 2007, 11:23
How did you declare "a"?

kenny_isles
9th February 2007, 11:25
RawValueDisplay *a = new RawValueDisplay(this);

jacek
9th February 2007, 11:27
RawValueDisplay *a = new RawValueDisplay(this);
Are you sure? In such case this:
a.table1->setText( 1, 1, "qqq" );
shouldn't even compile. Maybe you have two "a" variables?

kenny_isles
9th February 2007, 11:27
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();

}
//--------------------------------------------------------------------------------------------
:(

jacek
9th February 2007, 11:33
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.

kenny_isles
9th February 2007, 11:41
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.
:confused:

jacek
9th February 2007, 12:23
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)?

kenny_isles
9th February 2007, 12:35
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.

jacek
9th February 2007, 13:10
There are three solutions:

1) pass a pointer to the first dialog

SecondDialog::SecondDialog( FirstDialog *ptr, QWidget *parent )
: QDialog( parent ), _firstDialogPtr( ptr )
{
...
}

...

void SecondDialog::processParams()
{
...
_firstDialogPtr->setSomenting( whatever );
...
}

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:

void FirstDialog::doSomething()
{
SecondDialog dlg( this );
if( dlg.exec() == Qt::Accepted ) {
someWidget->setSomething( dlg.something() ); // SecondDialog::something() returns the data you need
...
}
}
This is a bit better approach, since you can reuse SecondDialog for other purposes.

3) Use signals and slots:


void FirstDialog::showSecondDialog()
{
SecondDialog *dlg = new SecondDialog( this );
dlg->setWFlags( dlg->getWFlags() | Qt::WDestructiveClose );

connect( dlg, SIGNAL( somethingChanged( int ) ),
this, SLOT( setSomething( int ) ) );
...

dlg->show();
}

This is the version with minimal coupling, but it also requires a bit more work than other ones.

kenny_isles
13th February 2007, 09:01
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.

kenny_isles
13th February 2007, 09:19
This is the second method u suggested

jacek
13th February 2007, 11:04
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.