Results 1 to 7 of 7

Thread: Error when trying to update TableView

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2009
    Location
    New Zealand
    Posts
    54
    Thanks
    23
    Qt products
    Qt4
    Platforms
    Windows

    Default Error when trying to update TableView

    Hi,

    I am new to Qt programming and Im having problems trying to insert new data into a QTableView, via a QStandardItemModel,

    Specifically, I am having trouble trying to update the table from within a function "void Loader::addChannelToTable() "

    Qt Code:
    1. #include <QtGui>
    2. #include "loader.h"
    3. #include <QString>
    4. #include <QTextStream>
    5. #include "qextserialport.h"
    6. #include "addDialog.h"
    7. #include <QtGui/QApplication>
    8. #include <QCoreApplication>
    9. #include <QString>
    10. #include <QTextStream>
    11. #include <QThread>
    12. #include <QTime>
    13. #include <QtGlobal>
    14. #include <qdatetime.h>
    15. #include <QByteArray>
    16. #include <QBitArray> // probably shouldnt use as RS232 works with bytes.
    17. #include <QStandardItem>
    18. #include <QStandardItemModel>
    19. #include <QVariant>
    20. #include <QModelIndex>
    21.  
    22.  
    23. Loader::Loader(QWidget *parent)
    24. : QWidget(parent)
    25. {
    26.  
    27.  
    28. QTableView *channelsView = new QTableView();
    29.  
    30. // for (int row = 0; row < 4; ++row) {
    31. // for (int column = 0; column < 2; ++column) {
    32. // QStandardItem *item = new QStandardItem(QString("%0, %1").arg(row).arg(column));
    33. // //QStandardItem *item = new QStandardItem(QString("row %0, column %1").arg(row).arg(column));
    34. // model->setItem(row, column, item); //This item is put in the model by using the setItem(int, int, QStandardItem*) method.
    35. // }
    36. // } //When I uncomment this section the Table is updated
    37.  
    38. channelsView->setModel(model);
    39.  
    40.  
    41. QLabel *titleLabel = new QLabel(tr("COMMUNICATIONS"));
    42. QLabel *descriptionLabel = new QLabel(tr("Determines Distribution"));
    43. QLabel *netNameLabel = new QLabel(tr("Net Name:"));
    44. QLabel *currentChannelsLabel = new QLabel(tr("Descriptionfor Net:"));
    45. QLabel *cloningLabel = new QLabel(tr("Enable Cloning"));
    46. netNameLine = new QLineEdit;
    47. currentChannelsText = new QTextEdit;
    48. QPushButton *saveButton = new QPushButton(tr("Save Configuration Data As..."));
    49. QPushButton *uploadButton = new QPushButton(tr("Upload Configuration "));
    50. QPushButton *quitButton = new QPushButton(tr("Quit"));
    51. QPushButton *addChannelButton = new QPushButton(tr("Add Channel")); // the 'tr' is for translate...
    52. QPushButton *removeChannelButton = new QPushButton(tr("Remove Channel"));
    53. QCheckBox *cloningEnabled = new QCheckBox();
    54. QHBoxLayout *secondLayout = new QHBoxLayout();
    55. secondLayout->addWidget(saveButton);
    56. secondLayout->addWidget(uploadButton);
    57. secondLayout->addWidget(quitButton);
    58.  
    59. QHBoxLayout *thirdLayout = new QHBoxLayout();
    60. thirdLayout->addWidget(cloningLabel);
    61. thirdLayout->addWidget(cloningEnabled);
    62.  
    63. QGridLayout *mainLayout = new QGridLayout;
    64. mainLayout->addWidget(titleLabel, 0, 1); //The title widget (WInDows GadgET) is situated at row 0, column 1, in the grid layout.
    65. mainLayout->addWidget(descriptionLabel, 1, 1, Qt::AlignTop);
    66. mainLayout->addWidget(netNameLabel, 4, 0);
    67. mainLayout->addWidget(netNameLine, 4, 1);
    68. mainLayout->addLayout(thirdLayout,5,1);
    69. mainLayout->addWidget(addChannelButton, 6, 1);
    70. mainLayout->addWidget(removeChannelButton, 7, 1);
    71. mainLayout->addWidget(channelsView, 8, 1);
    72. mainLayout->addWidget(currentChannelsLabel, 8, 0, Qt::AlignTop);
    73. mainLayout->addLayout(secondLayout,9,1);
    74. setLayout(mainLayout);
    75. setWindowTitle(tr("Unit Loader"));
    76.  
    77. QObject::connect(quitButton, SIGNAL(clicked()),
    78. this, SLOT(close()));
    79.  
    80. QObject::connect(uploadButton, SIGNAL(clicked()),
    81. this, SLOT(calculateRandomCode()));
    82.  
    83. QObject::connect(uploadButton, SIGNAL(clicked()),
    84. this, SLOT(send()));
    85.  
    86. QObject::connect(addChannelButton, SIGNAL(clicked()), // So I click the addChannel button and the addChannel Dialog opens
    87. this, SLOT(addChannelDialog())); // So I click the addChannel button and the addChannel Dialog opens
    88. }
    89.  
    90.  
    91. void Loader::addChannelDialog() // the addChannelDialog SLOT or Function..
    92. {
    93. AddDialog *dialog = new AddDialog(this); // Creates a new object; *dialog of class AddDialog
    94. dialog->show(); //Shows the dialog..
    95.  
    96. QObject::connect(dialog, SIGNAL(addThisChannel()),
    97. this, SLOT(addChannelToTable()));
    98. }
    99.  
    100. void Loader::addChannelToTable() // I want this SLOT to be activated when the addButton (from the AddDialog::dialog object) is clicked.
    101.  
    102. {
    103. QMessageBox::information(
    104. this,
    105. tr("Yes,"),
    106. tr("It works.") );
    107.  
    108. for (int row = 0; row < 4; ++row) {
    109. for (int column = 0; column < 2; ++column) {
    110. QStandardItem *item = new QStandardItem(QString("%0, %1").arg(row).arg(column));
    111. model->setItem(row, column, item); //This item is put in the model by using the setItem(int, int, QStandardItem*) method.
    112. }
    113. } // I think my problem is in the line above or below.
    114.  
    115. channelsView->setModel(model);
    116. }
    117.  
    118.  
    119.  
    120. void Loader::send()
    121.  
    122.  
    123. {
    124. }
    125.  
    126.  
    127.  
    128. void Loader::calculateRandomCode()
    129. {
    130.  
    131. }
    To copy to clipboard, switch view to plain text mode 


    My code compiles and runs, but as soon as I get to the part where I can run "void Loader::addChannelToTable() " the information box "yes it works" is displayed, then windows shows and error screen and I am forced to close my program.


    When I update the table from within the

    Qt Code:
    1. Loader::Loader(QWidget *parent)
    2. : QWidget(parent)
    3. {
    4. //
    5. }
    To copy to clipboard, switch view to plain text mode 
    section it works fine.



    Thanks for reading, any help would be greatly appreciated
    Last edited by Ferric; 12th January 2010 at 04:55.

Similar Threads

  1. tableview
    By GuL in forum Newbie
    Replies: 1
    Last Post: 26th August 2008, 17:18
  2. TableView and QDataWidgetMapper
    By kramed in forum Qt Programming
    Replies: 1
    Last Post: 17th June 2008, 04:41
  3. tableView Problem
    By hrcariaga in forum Newbie
    Replies: 5
    Last Post: 7th February 2008, 08:29
  4. help in tableview
    By bala in forum Qt Programming
    Replies: 3
    Last Post: 12th November 2007, 15:46
  5. tableview and layouts
    By zorro68 in forum Qt Programming
    Replies: 1
    Last Post: 10th February 2007, 17:21

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.