Results 1 to 6 of 6

Thread: QtabkeView, QStandardItemModel and QSortFilterProxyModel problem.

  1. #1
    Join Date
    Nov 2019
    Posts
    4
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default QtabkeView, QStandardItemModel and QSortFilterProxyModel problem.

    Hello all,

    I want to do a QTableView with a custom calculate cell. In the first column I have the name of the device. In the second column I have millisecond field and in the third column I have the rest of the previous millisecond field row and the actual row and write in the second column. Also a have a filter to select the device.

    I have a QStandardItemModel for update the data, and a QSortFilterProxyModel for the filter.

    My code is:

    Qt Code:
    1. this->model = new QStandardItemModel();
    2. this->model->setColumnCount(3);
    3. this->model->setHeaderData(0, Qt::Horizontal, QObject::tr("Time"));
    4. this->model->setHeaderData(1, Qt::Horizontal, QObject::tr("Milliseconds"));
    5. this->model->setHeaderData(2, Qt::Horizontal, QObject::tr("Spend Time"));
    6.  
    7. this->dataTable = new QTableView();
    8. this->dataTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
    9. this->dataTable->setSortingEnabled(false);
    10. this->dataTable->sortByColumn(1, Qt::AscendingOrder);
    11.  
    12.  
    13. QRegExp filterString = QRegExp("ARM1", Qt::CaseInsensitive);
    14. this->filterModel->setFilterRegExp(filterString);
    15. this->filterModel->setFilterKeyColumn(-1);
    16. this->dataTable->setModel(filterModel);
    To copy to clipboard, switch view to plain text mode 


    When I don't use the filter, I can write in the data model without problem like this:

    Qt Code:
    1. QStandardItemModel *auxModel = (QStandardItemModel*)this->dataTable->model();
    2. int rows = auxModel->rowCount();
    3. for (int i = 0; i < rows; i++) {
    4. if (i == 0) {
    5. auxModel->setItem(i, 2, new QStandardItem("0"));
    6. } else {
    7. unsigned long aux1 = auxModel->data(auxModel->index(i,1)).toString().toLong();
    8. unsigned long aux2 = auxModel->data(auxModel->index(i-1,1)).toString().toLong();
    9. QString s = QString::number(aux1 - aux2);
    10. auxModel->setItem(i, 2, new QStandardItem(s));
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 

    But when I use the filter I get a segmentation fault and I cannot found a solution.

    Can anyone hellp me?
    Thanks
    Last edited by d_stranz; 4th January 2024 at 21:03. Reason: missing [code] tags

  2. #2
    Join Date
    Oct 2009
    Location
    Mexico
    Posts
    81
    Thanks
    6
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QtabkeView, QStandardItemModel and QSortFilterProxyModel problem.

    seems to you need call the sourceModel() fuction in proxyModel, and then set the model in the TableView.

    Qt Code:
    1. this->filterModel->setSourceMode(this->model) //<--- need to setSourceModel in filterProxy
    2. this->dataTable->setModel(this->filterModel);
    To copy to clipboard, switch view to plain text mode 

    if this is not correct, please post the minimum code needed to run the program.
    Last edited by ecanela; 24th December 2023 at 04:54. Reason: reformatted to look better

  3. #3
    Join Date
    Nov 2019
    Posts
    4
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: QtabkeView, QStandardItemModel and QSortFilterProxyModel problem.

    Than you for your reply ecanela,

    After some test I think the problem is edit a cell from the QSortFilterProxyModel.

    My .h code is:

    Qt Code:
    1. #include <QDialog>
    2. #include <QCloseEvent>
    3. #include <QPushButton>
    4. #include <QHBoxLayout>
    5. #include <QVBoxLayout>
    6. #include <QGroupBox>
    7. #include <QCheckBox>
    8. #include <QTableView>
    9. #include <QStandardItemModel>
    10. #include <QSignalMapper>
    11. #include <QSortFilterProxyModel>
    12. #include <QHeaderView>
    13. #include <QMenu>
    14. #include <QScrollBar>
    15. #include <QFileDialog>
    16. #include <QItemSelectionModel>
    17.  
    18. #include <fstream>
    19.  
    20. #include "VariablesBuffer.h"
    21. #include "StringFunctions.h"
    22. #include "CommandsBuffer.h"
    23.  
    24. #include "WindowInclude.h"
    25.  
    26. #include <unistd.h> /* Unix standard function definitions */
    27.  
    28. class WindowTimeMonitoring : public WindowInclude {
    29. Q_OBJECT
    30. private:
    31. QHBoxLayout * layoutMonitoring;
    32.  
    33. CommandsBuffer * commands;
    34. VariablesBuffer * variables;
    35.  
    36. /** @brief Reference to the signal mapper for the filter */
    37. QSignalMapper* signalMapper;
    38.  
    39. /** @brief Reference to the filter data */
    40. QSortFilterProxyModel *filterModel = NULL;
    41.  
    42. /** @brief Reference to the header of the table to show data */
    43. QHeaderView *tableHeader = NULL;
    44.  
    45. std::map<std::string, QCheckBox *> mapAviables;
    46.  
    47. std::map<std::string, QCheckBox *> mapFilter;
    48.  
    49. QTableView * dataTable;
    50.  
    51. /** @brief Reference to model with data */
    52.  
    53.  
    54. public slots:
    55. void filterAction();
    56. void clearSlot();
    57. void exportSlot();
    58. void udpateTimeSlot();
    59.  
    60. public:
    61. WindowTimeMonitoring(VariablesBuffer * variables, CommandsBuffer * commands, QWidget *parent = nullptr);
    62. void addCommand(Command * command);
    63. virtual ~WindowTimeMonitoring();
    64. };
    To copy to clipboard, switch view to plain text mode 


    And my Cpp code is





    Quote Originally Posted by ecanela View Post
    seems to you need call the sourceModel() fuction in proxyModel, and then set the model in the TableView.

    Qt Code:
    1. this->filterModel->setSourceMode(this->model) //<--- need to setSourceModel in filterProxy
    2. this->dataTable->setModel(this->filterModel);
    To copy to clipboard, switch view to plain text mode 

    if this is not correct, please post the minimum code needed to run the program.
    Qt Code:
    1. #include "WindowTimeMonitoring.h"
    2.  
    3. WindowTimeMonitoring::WindowTimeMonitoring(QWidget *parent) : QDialog(parent) {
    4.  
    5. this->setWindowTitle("Time Monitoring");
    6. this->resize(800,600);
    7.  
    8. std::string modules("ARM1, ARM2, ARM3");
    9.  
    10. QVBoxLayout * layoutMain = new QVBoxLayout();
    11. std::vector<std::string> listaModulos = strFunctions::split(modules, ',');
    12.  
    13. QHBoxLayout * layoutButtons = new QHBoxLayout();
    14. QPushButton *buttonClear = new QPushButton("Clear table");
    15. QObject::connect(buttonClear, SIGNAL(clicked()), this, SLOT(clearSlot()));
    16.  
    17. QPushButton *buttonClose = new QPushButton("Close");
    18. QObject::connect(buttonClose, SIGNAL(clicked()), this, SLOT(closeSlot()));
    19.  
    20. QPushButton *buttonExport = new QPushButton("Export to file");
    21. QObject::connect(buttonExport, SIGNAL(clicked()), this, SLOT(exportSlot()));
    22.  
    23. QPushButton *buttonRecal = new QPushButton("Calculate spend time");
    24. QObject::connect(buttonRecal, SIGNAL(clicked()), this, SLOT(udpateTimeSlot()));
    25.  
    26. layoutButtons->addWidget(buttonRecal);
    27. layoutButtons->addWidget(buttonClear);
    28. layoutButtons->addWidget(buttonClose);
    29. layoutButtons->addWidget(buttonExport);
    30.  
    31. QGroupBox *groupFilter = new QGroupBox("Filter Monitoring:");
    32. QHBoxLayout * layoutFilter = new QHBoxLayout();
    33. for(auto item: listaModulos) {
    34.  
    35. mapFilter[item] = new QCheckBox(QString::fromStdString(item));
    36. QObject::connect(mapFilter[item], SIGNAL(clicked()), this, SLOT(filterAction()));
    37.  
    38. mapFilter[item]->setChecked(true);
    39.  
    40. layoutFilter->addWidget(mapFilter[item]);
    41. }
    42. groupFilter->setLayout(layoutFilter);
    43.  
    44. this->model = new QStandardItemModel();
    45. this->model->setColumnCount(5);
    46.  
    47. this->filterModel = new QSortFilterProxyModel();
    48.  
    49. model->setHeaderData(0, Qt::Horizontal, QObject::tr("Time"));
    50. model->setHeaderData(1, Qt::Horizontal, QObject::tr("Milliseconds"));
    51. model->setHeaderData(2, Qt::Horizontal, QObject::tr("Time Spend"));
    52. model->setHeaderData(3, Qt::Horizontal, QObject::tr("Module"));
    53. model->setHeaderData(4, Qt::Horizontal, QObject::tr("Message"));
    54.  
    55. QGroupBox *groupTimeMonitoring = new QGroupBox("Time Monitoring:");
    56. layoutMonitoring = new QHBoxLayout();
    57. dataTable = new QTableView();
    58. this->dataTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
    59. this->dataTable->setSortingEnabled(false);
    60. this->dataTable->sortByColumn(1, Qt::AscendingOrder);
    61. this->dataTable->setModel(this->model);
    62. dataTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    63.  
    64. layoutMonitoring->addWidget(dataTable);
    65. groupTimeMonitoring->setLayout(layoutMonitoring);
    66.  
    67. layoutMain->addWidget(groupAviable);
    68. layoutMain->addWidget(groupFilter);
    69. layoutMain->addWidget(groupTimeMonitoring);
    70. layoutMain->addLayout(layoutButtons);
    71.  
    72. this->setLayout(layoutMain);
    73.  
    74. }
    75.  
    76. void WindowTimeMonitoring::udpateTimeSlot() {
    77.  
    78. QStandardItemModel *auxModel = (QStandardItemModel*)this->dataTable->model();
    79.  
    80. int rows = auxModel->rowCount();
    81.  
    82. for (int i = 0; i < rows; i++) {
    83. if (i == 0) {
    84.  
    85. auxModel->setItem(i, 2, new QStandardItem("0"));
    86.  
    87. } else {
    88. unsigned long aux1 = auxModel->data(auxModel->index(i,1)).toString().toLong();
    89. unsigned long aux2 = auxModel->data(auxModel->index(i-1,1)).toString().toLong();
    90.  
    91. QString s = QString::number(aux1 - aux2);
    92. auxModel->setItem(i, 2, new QStandardItem(s));
    93.  
    94. }
    95. }
    96. }
    97.  
    98. void WindowTimeMonitoring::clearSlot() {
    99. model->clear();
    100. model->removeRows( 0, model->rowCount());
    101.  
    102.  
    103. }
    104.  
    105. void WindowTimeMonitoring::exportSlot() {
    106.  
    107. QString aux_filename = QFileDialog::getSaveFileName(this,
    108. tr("Select File"), "", tr("All Files (*)"));
    109. if (! aux_filename.isEmpty()) {
    110.  
    111. QStandardItemModel *auxModel = (QStandardItemModel*)this->dataTable->model();
    112.  
    113. QString textData("Time,Milliseconds,Time Spend, Module, Message");
    114. int rows = auxModel->rowCount();
    115. int columns = auxModel->columnCount();
    116.  
    117. for (int i = 0; i < rows; i++) {
    118. for (int j = 0; j < columns; j++) {
    119.  
    120. textData += auxModel->data(auxModel->index(i,j)).toString();
    121. textData += ", "; // for .csv file format
    122. }
    123. textData += "\n"; // (optional: for new line segmentation)
    124. }
    125.  
    126. std::ofstream MyFile(aux_filename.toStdString());
    127. MyFile << textData.toStdString();
    128. MyFile.close();
    129.  
    130. }
    131. }
    132. /** **************************************************************************
    133.  * void WindowShowBufferPackaged::filterAction(QString cadena)
    134.  * @brief Filter table buffer data.
    135.  * @details Filter the table with the buffer data.
    136.  *
    137.  * @param cadena Conditions to filter the table. The first character is
    138.  * the column to apply the filter.
    139.  ****************************************************************************/
    140. void WindowTimeMonitoring::filterAction() {
    141. std::vector<std::string> lista;
    142.  
    143. for(auto item: mapFilter) {
    144. if (item.second->isChecked()) {
    145. lista.push_back(item.first);
    146. }
    147. }
    148.  
    149. if (lista.size() == mapFilter.size()) {
    150. this->dataTable->setModel(model);
    151. //QRegExp filterString = QRegExp("", Qt::CaseInsensitive);
    152. //filterModel->setFilterRegExp(filterString);
    153.  
    154. } else {
    155.  
    156. QString cadena("^(");
    157. QString aux;
    158. for (std::string item: lista) {
    159. cadena += aux + QString(item.c_str());
    160.  
    161. aux = "|";
    162. }
    163. cadena += ")$";
    164.  
    165. this->filterModel->setSourceModel(model);
    166.  
    167. //QRegExp filterString = QRegExp("", Qt::CaseInsensitive);
    168. //filterModel->setFilterRegExp(filterString);
    169.  
    170.  
    171.  
    172. QRegExp filterString = QRegExp(cadena, Qt::CaseInsensitive);
    173. filterModel->setFilterRegExp(filterString);
    174. filterModel->setFilterKeyColumn(-1);
    175. this->dataTable->setModel(filterModel);
    176. }
    177.  
    178. }
    179.  
    180. void WindowTimeMonitoring::addCommand(Command * command) {
    181.  
    182. this->model->setColumnCount(5);
    183.  
    184. QList<QStandardItem *> items;
    185. item = new QStandardItem(QString(command->getTimeStr().c_str()));
    186. items.append(item);
    187.  
    188. item = new QStandardItem(QString::number(command->getMiliSeconds()));
    189. items.append(item);
    190.  
    191. item = new QStandardItem(QString(""));
    192. items.append(item);
    193.  
    194. item = new QStandardItem(QString(command->origen.c_str()));
    195. items.append(item);
    196.  
    197. item = new QStandardItem(QString(command->params.c_str()));
    198. items.append(item);
    199.  
    200. this->model->appendRow(items);
    201. }
    202.  
    203. WindowTimeMonitoring::~WindowTimeMonitoring() {
    204. // TODO Auto-generated destructor stub
    205. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Oct 2009
    Location
    Mexico
    Posts
    81
    Thanks
    6
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QtabkeView, QStandardItemModel and QSortFilterProxyModel problem.

    please provide a short self-contained correct example, the code is extense and dont provide some classes.

    https://stackoverflow.com/help/minim...ucible-example

    commandBuffer and VariableBuffer classes are not provided, and maybe not necesary for the example code.

  5. #5
    Join Date
    Nov 2019
    Posts
    4
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: QtabkeView, QStandardItemModel and QSortFilterProxyModel problem.

    Dear Ecanela,

    sorry for my mistake. I try to do quickly and I don't read the rules. Sorry again.

    Ok, I do a short self-cointaned example. The example has a QTimer to add elements for the table. There is a button ("Calculate spend time") to recalculate the difference between the rows. To reproduce the error, you can unselect one of the elements of the filter and then recalculate the difference between rows.

    The Cpp class.
    Qt Code:
    1. #include "WindowTimeMonitoringShort.h"
    2.  
    3. WindowTimeMonitoringShort::WindowTimeMonitoringShort(QWidget *parent) : QDialog(parent) {
    4.  
    5. this->setWindowTitle("Time Monitoring");
    6. this->resize(800,600);
    7.  
    8. QTimer * clock =new QTimer(this);
    9.  
    10. /* Conections */
    11. connect(clock, SIGNAL(timeout()), this, SLOT(addCommand()));
    12. clock->start(20000); /* Check every 20 second */
    13.  
    14. QVBoxLayout * layoutMain = new QVBoxLayout();
    15.  
    16.  
    17. listaModulos.push_back("ARM1");
    18. listaModulos.push_back("ARM2");
    19. listaModulos.push_back("ARM3");
    20. listaModulos.push_back("ARM4");
    21.  
    22. QHBoxLayout * layoutButtons = new QHBoxLayout();
    23.  
    24. QPushButton *buttonClose = new QPushButton("Close");
    25. QObject::connect(buttonClose, SIGNAL(clicked()), this, SLOT(closeSlot()));
    26.  
    27. QPushButton *buttonRecal = new QPushButton("Calculate spend time");
    28. QObject::connect(buttonRecal, SIGNAL(clicked()), this, SLOT(udpateTimeSlot()));
    29.  
    30. layoutButtons->addWidget(buttonRecal);
    31. layoutButtons->addWidget(buttonClose);
    32.  
    33. QGroupBox *groupFilter = new QGroupBox("Filter Monitoring:");
    34. QHBoxLayout * layoutAviables = new QHBoxLayout();
    35. QHBoxLayout * layoutFilter = new QHBoxLayout();
    36. for(auto item: listaModulos) {
    37. mapFilter[item] = new QCheckBox(QString::fromStdString(item));
    38. QObject::connect(mapFilter[item], SIGNAL(clicked()), this, SLOT(filterAction()));
    39.  
    40. mapFilter[item]->setChecked(true);
    41. layoutFilter->addWidget(mapFilter[item]);
    42. }
    43. groupFilter->setLayout(layoutFilter);
    44.  
    45. this->model = new QStandardItemModel();
    46. this->model->setColumnCount(5);
    47.  
    48. this->filterModel = new QSortFilterProxyModel();
    49.  
    50. model->setHeaderData(0, Qt::Horizontal, QObject::tr("Time"));
    51. model->setHeaderData(1, Qt::Horizontal, QObject::tr("Milliseconds"));
    52. model->setHeaderData(2, Qt::Horizontal, QObject::tr("Time Spend"));
    53. model->setHeaderData(3, Qt::Horizontal, QObject::tr("Module"));
    54. model->setHeaderData(4, Qt::Horizontal, QObject::tr("Message"));
    55.  
    56. QGroupBox *groupTimeMonitoring = new QGroupBox("Time Monitoring:");
    57. layoutMonitoring = new QHBoxLayout();
    58. dataTable = new QTableView();
    59. this->dataTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
    60. this->dataTable->setSortingEnabled(false);
    61. this->dataTable->sortByColumn(1, Qt::AscendingOrder);
    62. this->dataTable->setModel(this->model);
    63. this->dataTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    64.  
    65. this->dataTable->horizontalHeader()->resizeSection(0, 120);
    66. this->dataTable->horizontalHeader()->resizeSection(1, 120);
    67. this->dataTable->horizontalHeader()->resizeSection(2, 100);
    68. this->dataTable->horizontalHeader()->resizeSection(3, 100);
    69.  
    70. layoutMonitoring->addWidget(dataTable);
    71. groupTimeMonitoring->setLayout(layoutMonitoring);
    72.  
    73. layoutMain->addWidget(groupFilter);
    74. layoutMain->addWidget(groupTimeMonitoring);
    75. layoutMain->addLayout(layoutButtons);
    76.  
    77. this->setLayout(layoutMain);
    78.  
    79. }
    80.  
    81.  
    82. /**
    83.  * Ths method recalculate the differences between the rows.
    84. */
    85. void WindowTimeMonitoringShort::udpateTimeSlot() {
    86.  
    87. QStandardItemModel *auxModel = (QStandardItemModel*)this->dataTable->model();
    88.  
    89. int numRows = auxModel->rowCount();
    90. for (int i = 0; i < numRows; i++) {
    91. if (i == 0) { // In the frist line I put a 0.
    92. auxModel->setItem(i, 2, new QStandardItem("0"));
    93. } else {
    94. unsigned long aux1 = auxModel->data(auxModel->index(i,1)).toString().toLong();
    95. unsigned long aux2 = auxModel->data(auxModel->index(i-1,1)).toString().toLong();
    96.  
    97. QString s = QString::number(aux1 - aux2);
    98. auxModel->setItem(i, 2, new QStandardItem(s));
    99. }
    100. }
    101. }
    102.  
    103.  
    104. /** **************************************************************************
    105.  * This method filter the model to show in the table.
    106.  *
    107.  * In this case, if there are all modules selected, I select the original model without
    108.  * the filter. In this case, I can execute the udpateTimeSlot to recalculate the difference
    109.  * between rows. If I eliminate a select of the filter and execute the updateTimeSlot,
    110.  * I get the error.
    111.  ****************************************************************************/
    112. void WindowTimeMonitoringShort::filterAction() {
    113. std::vector<std::string> lista;
    114.  
    115. for(auto item: mapFilter) {
    116. if (item.second->isChecked()) {
    117. lista.push_back(item.first);
    118. }
    119. }
    120.  
    121. if (lista.size() == mapFilter.size()) {
    122. this->dataTable->setModel(model);
    123. } else {
    124.  
    125. QString cadena("^(");
    126. QString aux;
    127. // COn esta funciona "^(ARM1_RENDER|POLAR|ARM1)$"
    128. for (std::string item: lista) {
    129. cadena += aux + QString(item.c_str());
    130.  
    131. aux = "|";
    132. }
    133. cadena += ")$";
    134.  
    135. this->filterModel->setSourceModel(model);
    136.  
    137. //QRegExp filterString = QRegExp("", Qt::CaseInsensitive);
    138. //filterModel->setFilterRegExp(filterString);
    139.  
    140.  
    141.  
    142. QRegExp filterString = QRegExp(cadena, Qt::CaseInsensitive);
    143. filterModel->setFilterRegExp(filterString);
    144. filterModel->setFilterKeyColumn(-1);
    145. this->dataTable->setModel(filterModel);
    146. }
    147.  
    148. }
    149.  
    150.  
    151. /**
    152.  * Slot to add a row per module list items to the table with the basic information
    153.  *
    154. */
    155. void WindowTimeMonitoringShort::addCommand() {
    156.  
    157.  
    158. for(auto it: listaModulos) {
    159.  
    160. auto nowDate = std::chrono::system_clock::now();
    161.  
    162.  
    163. unsigned long long milliseconds_since_epoch =
    164. std::chrono::duration_cast<std::chrono::milliseconds>(nowDate.time_since_epoch()).count();
    165.  
    166.  
    167.  
    168. QList<QStandardItem *> items;
    169. item = new QStandardItem(QString(date::format("%T", nowDate).c_str()));
    170. items.append(item);
    171.  
    172. item = new QStandardItem(QString::number(milliseconds_since_epoch));
    173. items.append(item);
    174.  
    175. item = new QStandardItem(QString(""));
    176. items.append(item);
    177.  
    178. item = new QStandardItem(QString(it.c_str()));
    179. items.append(item);
    180.  
    181. item = new QStandardItem(QString(it.c_str()));
    182. items.append(item);
    183.  
    184. this->model->appendRow(items);
    185.  
    186. usleep(2000);
    187. }
    188. }
    189.  
    190. WindowTimeMonitoringShort::~WindowTimeMonitoringShort() {
    191. // TODO Auto-generated destructor stub
    192. }
    To copy to clipboard, switch view to plain text mode 

    and de h

    Qt Code:
    1. #ifndef SRC_POLAR_GUI_QT_WINDOWS_WindowTimeMonitoringShort_H_
    2. #define SRC_POLAR_GUI_QT_WINDOWS_WindowTimeMonitoringShort_H_
    3.  
    4. #include <QDialog>
    5. #include <QCloseEvent>
    6. #include <QPushButton>
    7. #include <QHBoxLayout>
    8. #include <QVBoxLayout>
    9. #include <QGroupBox>
    10. #include <QCheckBox>
    11. #include <QTableView>
    12. #include <QStandardItemModel>
    13. #include <QSignalMapper>
    14. #include <QSortFilterProxyModel>
    15. #include <QHeaderView>
    16. #include <QMenu>
    17. #include <QScrollBar>
    18. #include <QFileDialog>
    19. #include <QItemSelectionModel>
    20. #include <QTimer>
    21.  
    22. #include <fstream>
    23. #include "date.h"
    24. #include <unistd.h> /* Unix standard function definitions */
    25.  
    26. class WindowTimeMonitoringShort : public QDialog {
    27. Q_OBJECT
    28. private:
    29. QHBoxLayout * layoutMonitoring;
    30.  
    31. /** @brief Reference to the signal mapper for the filter */
    32. QSignalMapper* signalMapper;
    33.  
    34. /** @brief Reference to the filter data */
    35. QSortFilterProxyModel *filterModel = NULL;
    36.  
    37. std::vector<std::string> listaModulos;
    38.  
    39. /** @brief Reference to the header of the table to show data */
    40. QHeaderView *tableHeader = NULL;
    41.  
    42. std::map<std::string, QCheckBox *> mapAviables;
    43.  
    44. std::map<std::string, QCheckBox *> mapFilter;
    45.  
    46. QTableView * dataTable;
    47.  
    48. /** @brief Reference to model with data */
    49.  
    50.  
    51. public slots:
    52. void filterAction();
    53. void udpateTimeSlot();
    54. void addCommand();
    55. public:
    56. WindowTimeMonitoringShort(QWidget *parent = nullptr);
    57.  
    58. virtual ~WindowTimeMonitoringShort();
    59. };
    60.  
    61. #endif /* SRC_POLAR_GUI_QT_WINDOWS_WindowTimeMonitoring_H_ */
    To copy to clipboard, switch view to plain text mode 


    Thank you in advance, and sorry again for my mistake.
    Last edited by d_stranz; 4th January 2024 at 21:05. Reason: missing [code] tags

  6. #6
    Join Date
    Nov 2019
    Posts
    4
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: QtabkeView, QStandardItemModel and QSortFilterProxyModel problem.

    Hello everybody,

    I get a solution. It isn't the best solution, but it's work. I use a QTableWidget to show the data from the QSortFilterProxyModel.

    Thanks to everybody.

Similar Threads

  1. Problem in updating QstandardItemmodel.
    By urmila in forum Qt Programming
    Replies: 7
    Last Post: 1st September 2014, 17:12
  2. Replies: 4
    Last Post: 19th April 2013, 13:40
  3. Replies: 2
    Last Post: 11th February 2012, 00:28
  4. Replies: 2
    Last Post: 7th December 2009, 14:15
  5. QStandardItemModel save/load Problem
    By sun in forum Newbie
    Replies: 9
    Last Post: 1st October 2008, 18:20

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.