PDA

View Full Version : Load data from different ui



Xtresis
29th September 2010, 08:13
Dear all,

Currently i'm trying to export data (which is in stored in a QTableWidget) to a MySQL database. No problem so far with the database. The following is driving me mad though...

The QTableWidget is placed in MainWidow.ui where data simply can be extracted with the following code.

ui->tablewidget->item(column, row)

When I would like to export the items in the tablewidget, I push a button where a new QDialog pops up. In this dialog, I need to fill some value's in a few LineEdit's and comboBoxes.These values also will be exported to the MySQL database. Because it's a new QDialog, a new ui has been set up by the code:


dbase::dbase(QWidget *parent) :
QDialog(parent),
ui(new Ui::dbase)
{
ui->setupUi(this);
}


The question now is, how to get the data from the QWidgetTable which is in MainWindow.ui without closing the QDialog window? The following doenst work, because the new QDialog hasn't a QTableWidget


ui->tablewidget->item(column, row)


Thank's in advance for you help.

marcvanriet
29th September 2010, 11:44
Hi,

Basically, you want to access the widgets of one dialog from another dialog. Because your dialog and mainwindow are C++ classes, and the widgets are members of these classes, it is just a matter of exposing members of one class to another. So this is a C++ question.

A quick-and-dirty way would be to have a static public member in your maindialog class which is a pointer to the tablewidget. In the constructor of your mainwindow, and after the ui->setupUi(this), assign this pointer to your tablewidget.

In your second dialog, include the header file of your mainwindow, and just use the pointer in the mainwindow class.

Note that this is very, very, dirty programming. There are better ways to solve this, which have already been discussed many times in this forum.

Best regards,
Marc

Xtresis
29th September 2010, 11:57
Thank you for your reply. Solved it on the way which you discribed Marc. Found it also on qtforum.org

http://www.qtforum.org/article/33172/how-to-clear-n-repopulate-the-combobox-which-is-parent-window-from-the-child-window.html?aba55582