Results 1 to 3 of 3

Thread: Load data from different ui

  1. #1
    Join Date
    Sep 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Load data from different ui

    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.
    Qt Code:
    1. ui->tablewidget->item(column, row)
    To copy to clipboard, switch view to plain text mode 

    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:
    Qt Code:
    1. dbase::dbase(QWidget *parent) :
    2. QDialog(parent),
    3. ui(new Ui::dbase)
    4. {
    5. ui->setupUi(this);
    6. }
    To copy to clipboard, switch view to plain text mode 

    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
    Qt Code:
    1. ui->tablewidget->item(column, row)
    To copy to clipboard, switch view to plain text mode 

    Thank's in advance for you help.

  2. #2
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Thanks
    10
    Thanked 31 Times in 25 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Load data from different ui

    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

  3. #3
    Join Date
    Sep 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Load data from different ui

    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....html?aba55582

Similar Threads

  1. QPixmap cannot load data on Windows Mobile 6.1
    By _Stefan in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 31st August 2010, 11:57
  2. Way to load all of data from 2 tables into one QTableView?
    By Kevin Hoang in forum Qt Programming
    Replies: 8
    Last Post: 3rd April 2010, 09:42
  3. Replies: 6
    Last Post: 26th March 2009, 05:45
  4. Corrupt JPEG data: premature end of data segment
    By node_ex in forum Qt Programming
    Replies: 1
    Last Post: 19th August 2008, 08:57
  5. How to convert binary data to hexadecimal data
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 8th March 2006, 16:17

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
  •  
Qt is a trademark of The Qt Company.