December 11, 2010

xeroblast xeroblast
Lab Rat
68 posts

[SOLVED] mainwindow pass data to dialog

 

hi,

i have this problem that dont know how to implement it.

i have this mainwindow that have a qtablewidget that you select an item in the qtablewidget and click the button to view its details.

the problem is i dont know how to pass the data from qtablewidget to the newly opened qdialog. i know how to get the data in the qtablewidget but i dont know how to pass it to qdialog.

this is how i open a qdialog..

  1. MainWindow::MainWindow()
  2. {
  3.  NewDialog dialog(this);
  4.  dialog.exec();
  5. }

4 replies

December 11, 2010

Vass Vass
Ant Farmer
706 posts

You may add new method for your dialog and set data into it, for example.

  1. dialog.cpp
  2.  
  3. dialog.setData(myType myData)
  4. {
  5.      ui.editText.setText(myData.textForEdit);
  6.      .......
  7. }
  8.  
  9. .....
  10. mainwindow.cpp
  11.  
  12. MainWindow::MainWindow()
  13. {
  14.      NewDialog dialog(this);
  15.      dialog.setData(myData);
  16.      dialog.exec();
  17. }

 Signature 


Vasiliy

December 11, 2010

xeroblast xeroblast
Lab Rat
68 posts

thanx. i got it now and really thank you…

December 11, 2010

Bradley Bradley
Lab Rat
300 posts

xeroblast, note that the markup for code is “@…@”, not [CODE][/CODE]

 Signature 

Nokia Certified Qt Specialist.

April 17, 2013

koleygr koleygr
Lab Rat
25 posts

Vass wrote:
You may add new method for your dialog and set data into it, for example.
@
dialog.cpp

dialog.setData(myType myData)
{ ui.editText.setText(myData.textForEdit); …….
}

…..
mainwindow.cpp

MainWindow::MainWindow()
{ NewDialog dialog(this); dialog.setData(myData); dialog.exec();
}
@

I tried this method and it’s fine… it solved many problems i had with external variables…

The problem is that if i don’t use a pushbutton or something the dialog don’t realy recognize my new data…

I can’t understand why…

Edit: I finally dont need to use my variables before a simple click…
I suppose this is why we call it a dialog…

 Signature 

Using:Qt Creator 2.4.1 under UBUNTU

 
  ‹‹ How C++ lambdas affect Qt?      [SOLVED] The Animation Framework / How can I dynamically change EndValue during the animation? ››

You must log in to post a reply. Not a member yet? Register here!