Results 1 to 3 of 3

Thread: How to read and write data into the QTableView

  1. #1
    Join Date
    Jul 2009
    Location
    Bangalore
    Posts
    68
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default How to read and write data into the QTableView

    Hi All,

    I have made a QTableView which has 200 rows and 4 columns, when the user press the enter Key it opens a new QDialog which has 4 QlineEdits and these QlineEdits values has to be displayed in QTableView. here is the code snippet for QDialog

    tooladddialog.cpp
    Qt Code:
    1. QString ToolAddDialog::toolgetValues()
    2. {
    3. QString line;
    4.  
    5. toolnolineEdit->selectAll();
    6. line.append( toolnolineEdit->text() );
    7. line.append( " " );
    8.  
    9. diameterlineEdit->selectAll();
    10. line.append( diameterlineEdit->text() );
    11. line.append( " " );
    12.  
    13. lengthlineEdit->selectAll();
    14. line.append( lengthlineEdit->text() );
    15. line.append( " " );
    16.  
    17. unitslineEdit->selectAll();
    18. line.append( unitslineEdit->text() );
    19. return line;
    20. }
    To copy to clipboard, switch view to plain text mode 

    tooform.cpp
    Qt Code:
    1. void ToolForm::keyPressEvent( QKeyEvent *event )
    2. {
    3. qDebug( "Key Press Event" );
    4. switch ( event->key() )
    5. {
    6. case Qt::Key_Return: //Mapped with Enter Key
    7. add_tool();
    8.  
    9. break;
    10.  
    11. case Qt::Key_Escape: //Mapped with Cancel key
    12. close();
    13. break;
    14.  
    15. default:
    16. QWidget::keyPressEvent(event);
    17. }
    18. }
    19.  
    20. void ToolForm::add_tool()
    21. {
    22. ToolAddDialog tooladddialog;
    23.  
    24. if( tooladddialog.exec())
    25. {
    26. QString str = tooladddialog.toolgetValues();
    27. QStringList fields = str.split(" ");
    28.  
    29. if (!tooltableView)
    30. return;
    31. // now values should be added to the QTableView
    32. }
    33. }
    To copy to clipboard, switch view to plain text mode 

    How to resolve this issue. if any snippet would be advantage.
    Thanks & Regards
    Sandeep G.R.

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to read and write data into the QTableView

    use QAbstractItemModel::setData for setting data into model.
    PS. read about Model/View programming also.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Jul 2009
    Location
    Bangalore
    Posts
    68
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How to read and write data into the QTableView

    Hi Spirit,

    Thanks for the reply.
    Thanks & Regards
    Sandeep G.R.

Similar Threads

  1. GUI Freezes unless there's incoming data
    By crisp in forum Qt Programming
    Replies: 17
    Last Post: 7th February 2009, 17:56
  2. QTcpSocket waiting for write to be read
    By spraff in forum Qt Programming
    Replies: 1
    Last Post: 23rd December 2008, 19:12
  3. [Java] read and write a file
    By mickey in forum General Programming
    Replies: 3
    Last Post: 22nd June 2008, 10:43
  4. FSWriteFork in MAC OS to write data to a file.
    By vishal.chauhan in forum General Programming
    Replies: 5
    Last Post: 2nd July 2007, 06:48
  5. How to write bytes read from serial port to a QFile
    By shamik in forum Qt Programming
    Replies: 19
    Last Post: 25th June 2007, 14:12

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.