Results 1 to 5 of 5

Thread: things on QSqlRelationalTableModel , QDataWidgetMapper and QTableView

  1. #1
    Join Date
    May 2010
    Location
    China
    Posts
    66
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Smile things on QSqlRelationalTableModel , QDataWidgetMapper and QTableView

    i create a QTableView to show databases conten,and use some QLineEdits to eidit the record,i use the QDataWidgetMapper to connect the QSqlRelationalTableModel with the QLineEidt,i am wondering is there any ways to have this function that when i click the QTableView rows and the QLineEdit will show the relatived record.
    Qt Code:
    1. QString address=projectAddress;
    2. address+="//";
    3. address+="Data";
    4. address+="//";
    5. address+="SystemData";
    6. address+=".db3";
    7.  
    8. if (!QFile::exists(address))
    9. {
    10. QMessageBox::information(this,tr("Information"),tr("There is something wrong with the wells databases"),QMessageBox::Ok,QMessageBox::Ok);
    11. }
    12.  
    13. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    14. db.setDatabaseName(address);
    15. db.open();
    16.  
    17.  
    18. welldatamodel = new QSqlRelationalTableModel;
    19. welldatamodel->setTable("wells");
    20. welldatamodel->setEditStrategy(QSqlTableModel::OnManualSubmit);
    21. welldatamodel->setSort(0,Qt::AscendingOrder);
    22.  
    23. //set header name
    24. welldatamodel->setHeaderData(0,Qt::Horizontal,tr("Name"));
    25. welldatamodel->setHeaderData(1,Qt::Horizontal,tr("Group"));
    26. welldatamodel->setHeaderData(2,Qt::Horizontal,tr("X"));
    27. welldatamodel->setHeaderData(3,Qt::Horizontal,tr("Y"));
    28. welldatamodel->setHeaderData(4,Qt::Horizontal,tr("Type"));
    29. welldatamodel->setHeaderData(5,Qt::Horizontal,tr("Production"));
    30. welldatamodel->setHeaderData(6,Qt::Horizontal,tr("Depth"));
    31. welldatamodel->setHeaderData(7,Qt::Horizontal,tr("BeginDepth"));
    32. welldatamodel->setHeaderData(8,Qt::Horizontal,tr("EndDepth"));
    33. welldatamodel->setHeaderData(9,Qt::Horizontal,tr("Altitude"));
    34.  
    35.  
    36. welldatamodel->select();
    37. welldatamodel->removeColumn(0);
    38.  
    39. wellTableView->setModel(welldatamodel);
    40. wellTableView->setSelectionBehavior(QAbstractItemView::SelectRows);
    41. // wellTableView->resizeColumnsToContents();
    42.  
    43. // wellTableView->horizontalHeader()->setStretchLastSection(true);
    44.  
    45. welldatamapper->setSubmitPolicy(QDataWidgetMapper::AutoSubmit);
    46. welldatamapper->setModel(welldatamodel);
    47. welldatamapper->setItemDelegate(new QSqlRelationalDelegate(this));
    48.  
    49. welldatamapper->addMapping(wellNameEdit,0);
    50. welldatamapper->addMapping(wellGroupEdit,1);
    51. welldatamapper->addMapping(wellXPositionEdit,2);
    52. welldatamapper->addMapping(wellYPositionEdit,3);
    53.  
    54. welldatamapper->addMapping(wellProductionEdit,5);
    55. /*welldatamapper->addMapping(wellDepthEdit,6);*/
    56. welldatamapper->addMapping(wellBeginDepthEdit,7);
    57. welldatamapper->addMapping(wellEndDepthEdit,8);
    58. welldatamapper->addMapping(wellAltitudeEdit,9);
    59.  
    60. //create connect of the buttons
    61. connect(firstAction,SIGNAL(triggered()),welldatamapper,SLOT(toFirst()));
    62. connect(lastAction,SIGNAL(triggered()),welldatamapper,SLOT(toLast()));
    63. connect(previousAction,SIGNAL(triggered()),welldatamapper,SLOT(toLast()));
    64. connect(nextAction,SIGNAL(triggered()),welldatamapper,SLOT(toNext()));
    65. //connect(addAction,SIGNAL(triggered()),welldatamapper,SLOT())
    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: things on QSqlRelationalTableModel , QDataWidgetMapper and QTableView

    Use QDataWidgetMapper::setCurrentIndex() or QDataWidgetMapper::setCurrentModelIndex() as a reaction to an appropriate signal from the table or its selection model.
    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:

    xiongxiongchuan (13th June 2010)

  4. #3
    Join Date
    May 2010
    Location
    China
    Posts
    66
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: things on QSqlRelationalTableModel , QDataWidgetMapper and QTableView

    i used the connect as this below
    Qt Code:
    1. connect(welldatamapper,SIGNAL(setCurrentModelIndex()),wellTableView,SLOT(currentChanged()));
    2. connect(wellTableView,SIGNAL(currentChanged()),welldatamapper,SLOT(setCurrentModelIndex()));
    To copy to clipboard, switch view to plain text mode 

    but it din't work!

  5. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: things on QSqlRelationalTableModel , QDataWidgetMapper and QTableView

    Quote Originally Posted by xiongxiongchuan View Post
    Qt Code:
    1. SIGNAL(setCurrentModelIndex())
    To copy to clipboard, switch view to plain text mode 
    That's not a signal.

    Qt Code:
    1. SLOT(currentChanged())
    To copy to clipboard, switch view to plain text mode 
    That's not a slot.

    To quote the documentation:
    The following example illustrates how to update all widgets with new data whenever the selection of a QTableView named myTableView changes:
    Qt Code:
    1.  
    2. connect(myTableView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
    3. mapper, SLOT(setCurrentModelIndex(QModelIndex)));
    To copy to clipboard, switch view to plain text mode 

  6. The following user says thank you to tbscope for this useful post:

    xiongxiongchuan (13th June 2010)

  7. #5
    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: things on QSqlRelationalTableModel , QDataWidgetMapper and QTableView

    The first statement is obviously incorrect.
    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.


Similar Threads

  1. Replies: 2
    Last Post: 29th December 2012, 15:14
  2. QSqlRelationalTableModel QDataWidgetMapper
    By kawoN in forum General Programming
    Replies: 4
    Last Post: 26th May 2010, 10:30
  3. Replies: 1
    Last Post: 18th March 2009, 22:26
  4. QDataWidgetMapper to synchronize widgets with QTableView
    By ehamberg in forum Qt Programming
    Replies: 4
    Last Post: 21st February 2008, 21:46
  5. QDataWidgetMapper and QSqlRelationalTableModel problem
    By larry104 in forum Qt Programming
    Replies: 1
    Last Post: 14th November 2007, 16:46

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.