Results 1 to 3 of 3

Thread: Passing data to dialog via dialog or a method

  1. #1
    Join Date
    Jan 2012
    Posts
    46
    Thanks
    11
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Passing data to dialog via dialog or a method

    I'm currently passing data to a popup dialog in the following manner:

    mainwindow.cpp
    Qt Code:
    1. RAO_Edit = new RAOEntryDialog();
    2. RAO_Edit->edit_rao(surgemodel);
    3. RAO_Edit->exec();
    To copy to clipboard, switch view to plain text mode 

    RAOEntryDialog
    Qt Code:
    1. void RAOEntryDialog::edit_rao(QSqlTableModel *process_model)
    2. {
    3. ...
    4. }
    To copy to clipboard, switch view to plain text mode 

    But I can also do it like this:
    mainwindow.cpp
    Qt Code:
    1. RAO_Edit = new RAOEntryDialog(surgemodel);
    2. RAO_Edit->edit_rao();
    3. RAO_Edit->exec();
    To copy to clipboard, switch view to plain text mode 

    RAOEntryDialog
    Qt Code:
    1. RAOEntryDialog::RAOEntryDialog(QSqlTableModel *process_model, QWidget *parent) :
    2. QDialog(parent),
    3. ui(new Ui::RAOEntryDialog)
    4. {
    5. ...
    6. }
    To copy to clipboard, switch view to plain text mode 

    It's not necessary but I'd like to be able to operate on this model from several of the methods within my RAOEntryDialog class and that's got me a little perplexed as to how, so is there one way of getting the model into the dialog better than the other? This is a QSqlTableModel and I'm planning on transferring the data to a QTableWidget to allow me to treat the data in a spreadsheet fashion (insert, delete, copy, paste), then pass the data back to my mainwindow via signal/slot mechanism...

    Thanks!


    Kodi

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,592
    Thanks
    13
    Thanked 1,587 Times in 1,516 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Passing data to dialog via dialog or a method

    In large part I think this is a personal preference thing. If the RAO_Edit cannot function without the model then it makes sense to construct it with one or at least offer a constructor that does. If the model can changed on-the-fly then you need to offer a setModel() function of some sort. For consistency with the Qt classes you would use setModel() but make sure that you handle things gracefully if a model has not yet been set.

  3. #3
    Join Date
    Jan 2012
    Posts
    46
    Thanks
    11
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Passing data to dialog via dialog or a method

    The reason behind the dialog is that there's a widget displaying data in the mainwindow (from this model) that's too small to make editing useful, so upon clicking an "Edit" pushbuttom this RAOEntrydialog dialog will pop up; it is much larger and will facilitate easier editing of the model's data...Where it gets tricky is that I need to be able to offer cut-and-paste functionality and a tableview sitting on top of a QSqlTableModel would be hard to manage so what I'm thinking I'll do is copy the data from the model to a tablewidget, implement the editing and then when the "okay" pushbutton on the dialog is clicked, pass the data back to the mainwindow via a slot and repopulate the original QSqlTableModel there...Ideally it would be nice to operate directly on the model inside the popup dialog with a QSqlTableView, but dealing with the management of cutting and pasting seems to be a more cumbersome methodology...

    I'm fairly weak in C++ (databases are my expertise) so trying to figure out how to make the model accessible to the popup dialog across multiple methods is a bit of a stretch so I thought passing in via the constructor might help that happen, but I'm still at a loss as to how to get that data to the methods (I was getting an error earlier when I was trying to assign the parameter to a variable name in the constructor), so if that direction doesn't buy me anything I may as well stick to how I've dealt with other parts of my app and that's that pass the data thru on a signal/slot mechanism and pass edited data back and repopulate the model there in my mainwindow

    Thanks for opinion!!!

    Kodi

Similar Threads

  1. How to access objects of parent Dialog from Child Dialog .
    By ranjit.kadam in forum Qt Programming
    Replies: 4
    Last Post: 18th April 2011, 06:39
  2. passing date from a dialog to another one
    By erdomester in forum Qt Programming
    Replies: 7
    Last Post: 25th April 2010, 14:10
  3. passing data when closing a dialog
    By jimiq in forum Newbie
    Replies: 4
    Last Post: 4th November 2009, 16:48
  4. Passing Pixmaps between MainWindow and Dialog
    By ramstormrage in forum Qt Programming
    Replies: 28
    Last Post: 20th April 2008, 13:32
  5. control not passing from dialog to code
    By quickNitin in forum Newbie
    Replies: 3
    Last Post: 28th June 2006, 11:35

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.