Results 1 to 2 of 2

Thread: Advise:Do I need QDataWidgetMapper?

  1. #1
    Join Date
    Nov 2010
    Posts
    142
    Thanks
    24
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Advise:Do I need QDataWidgetMapper?

    I want a table view with 2 columns:
    • one simple cell
    • one qcombobox

    I set up the QCombobox delegate and two different views just to be sure that the database gets the values the user inserts.

    The user inserts a string in the empty cell and a value from the combobox.
    Then he pushes the addNewRow button to insert a new record.

    I am about to create a button which is going to send the database values (that the user inserted) into a txt file.

    My question is,
    Do I need to implement a QDataWidgetMapper?

    Qt Code:
    1. MyDialog::MyDialog(QWidget *parent)
    2. : QWidget(parent)
    3. {
    4.  
    5. model = new QStandardItemModel(1, 2);
    6. tableView = new QTableView(this);
    7. tableView->setModel(model);
    8.  
    9. delegate = new ComboBoxDelegate;
    10. tableView->setItemDelegateForColumn(1,delegate);
    11.  
    12.  
    13. view2 = new QTableView(this);
    14. view2->setModel(model);
    15. view2->setItemDelegateForColumn(1,delegate);
    16.  
    17. for ( int i = 0; i < model->rowCount(); ++i )
    18. tableView->openPersistentEditor( model->index(i, 1, QModelIndex()) );
    19.  
    20. QLineEdit* le = new QLineEdit();
    21.  
    22. QPushButton *newRowBtn = new QPushButton;
    23. newRowBtn->setText("add new row");
    24. connect(newRowBtn,SIGNAL(clicked()),this,SLOT(addNewRow()));
    25.  
    26.  
    27. vboxlayout = new QVBoxLayout(this);
    28. vboxlayout->addWidget(tableView);
    29. vboxlayout->addWidget(view2);
    30. vboxlayout->addWidget(new QLabel("Vorgang2"));
    31. vboxlayout->addWidget(le);
    32. vboxlayout->addWidget(newRowBtn);
    33. setLayout(vboxlayout);
    34. }
    35.  
    36.  
    37.  
    38. void MyDialog::addNewRow()
    39. {
    40.  
    41. QModelIndex index;
    42. int row = model->rowCount();
    43. model->insertRow(row);
    44. index = model->index(row, 0);
    45. tableView->setCurrentIndex(index);
    46. tableView->edit(index);
    47. tableView->openPersistentEditor( model->index(row, 1, QModelIndex()) );
    48.  
    49. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Advise:Do I need QDataWidgetMapper?

    No, you don't.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    fatecasino (4th March 2011)

Similar Threads

  1. Advise sought on working with binary files across OSes
    By TorAn in forum General Programming
    Replies: 2
    Last Post: 19th September 2010, 06:44
  2. Replies: 4
    Last Post: 1st June 2010, 11:42
  3. advise sought on TreeView model design
    By QPlace in forum Qt Programming
    Replies: 0
    Last Post: 25th June 2009, 14:36
  4. Need some advise with thumbnails and loading image
    By nmuntz in forum Qt Programming
    Replies: 2
    Last Post: 9th June 2009, 14:32
  5. Replies: 8
    Last Post: 27th August 2007, 15:45

Tags for this Thread

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.