I have this problem with the code below, that when I double click on an row, then nothing happens. I have written about the same code without a designer form and it works. I must be doing several things wrong in the designer form reuse.

Can you point out the where the trouble(s) is(are) :

main.cpp
Qt Code:
  1. #include <QtCore>
  2. #include <QtGui>
  3.  
  4. #include "dialog.h"
  5.  
  6. int main(int argc, char *argv[])
  7. {
  8. QApplication app(argc, argv);
  9. Dialog *window = new Dialog;
  10. window->show();
  11. return app.exec();
  12. }
To copy to clipboard, switch view to plain text mode 

dialog.h
Qt Code:
  1. #include "ui_dialog.h"
  2. #include <QStandardItemModel>
  3.  
  4. class Dialog : public QDialog
  5. {
  6. Q_OBJECT
  7.  
  8. public:
  9. Dialog(QWidget *parent = 0);
  10.  
  11. private:
  12. Ui::Dialog ui;
  13.  
  14. protected slots:
  15. void selection(const QModelIndex&);
  16. };
To copy to clipboard, switch view to plain text mode 

dialog.cpp
Qt Code:
  1. #include <QtCore>
  2. #include <QtGui>
  3.  
  4. #include "ui_dialog.h"
  5. #include "dialog.h"
  6.  
  7.  
  8. Dialog::Dialog(QWidget *parent) : QDialog(parent)
  9. {
  10. ui.setupUi(this);
  11. QStandardItemModel *model = new QStandardItemModel(0, 2, this);
  12. model->setHeaderData(0, Qt::Horizontal, "Mois");
  13. model->setHeaderData(1, Qt::Horizontal, "Facture");
  14.  
  15. QPalette palette;
  16. QPixmap pixmap = QPixmap("./images/bBackground.png");
  17. palette.setBrush((this)->backgroundRole(), QBrush(pixmap));
  18. (this)->setPalette(palette);
  19.  
  20. ui.treeView->setModel(model);
  21. QItemSelectionModel *selectionModel = new QItemSelectionModel(model);
  22. ui.treeView->setSelectionModel(selectionModel);
  23.  
  24. model->removeRows(0, model->rowCount(QModelIndex()), QModelIndex());
  25.  
  26. QString month = "October";
  27. QString amount = "5 Euros";
  28. int row = model->rowCount(QModelIndex());
  29. model->insertRows(row, 1, QModelIndex());
  30. model->setData(model->index(row, 0, QModelIndex()), month );
  31. model->setData(model->index(row, 1, QModelIndex()), amount );
  32.  
  33. month = "November";
  34. amount = "10 Euros";
  35. row = model->rowCount(QModelIndex());
  36. model->insertRows(row, 1, QModelIndex());
  37. model->setData(model->index(row, 0, QModelIndex()), month );
  38. model->setData(model->index(row, 1, QModelIndex()), amount );
  39.  
  40. ui.treeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
  41. ui.treeView->setRootIsDecorated( false );
  42. // works perfect up to here, does not seem to connect then...:o
  43. connect( ui.treeView, SIGNAL( doubleClicked(const ui.QModelIndex&) ),
  44. this, SLOT( selection(const ui.QModelIndex&) ) );
  45. }
  46.  
  47. void Dialog::selection(const QModelIndex& idx)
  48. {
  49. QString month = "Selection added";
  50. QString amount = "below:";
  51. int row;
  52. row = model->rowCount(QModelIndex());
  53. model->insertRows(row, 1, QModelIndex());
  54. model->setData(model->index(row, 0, QModelIndex()), month );
  55. model->setData(model->index(row, 1, QModelIndex()), amount );
  56.  
  57. QString col0 = model->data(idx.sibling(idx.row(), 0)).toString();
  58. QString col1 = model->data(idx.sibling(idx.row(), 1)).toString();
  59. row = model->rowCount(QModelIndex());
  60. model->insertRows(row, 1, QModelIndex());
  61. model->setData(model->index(row, 0, QModelIndex()), col0 );
  62. model->setData(model->index(row, 1, QModelIndex()), col1 );
  63. }
To copy to clipboard, switch view to plain text mode 

ui_dialog.h // generated by Qt
Qt Code:
  1. #ifndef UI_DIALOG_H
  2. #define UI_DIALOG_H
  3.  
  4. #include <QtCore/QVariant>
  5. #include <QtGui/QAction>
  6. #include <QtGui/QApplication>
  7. #include <QtGui/QButtonGroup>
  8. #include <QtGui/QDialog>
  9. #include <QtGui/QTreeView>
  10.  
  11. class Ui_Dialog
  12. {
  13. public:
  14. QTreeView *treeView;
  15.  
  16. void setupUi(QDialog *Dialog)
  17. {
  18. Dialog->setObjectName(QString::fromUtf8("Dialog"));
  19. Dialog->resize(QSize(400, 230).expandedTo(Dialog->minimumSizeHint()));
  20. treeView = new QTreeView(Dialog);
  21. treeView->setObjectName(QString::fromUtf8("treeView"));
  22. treeView->setGeometry(QRect(89, 60, 201, 80));
  23. retranslateUi(Dialog);
  24.  
  25. QMetaObject::connectSlotsByName(Dialog);
  26. } // setupUi
  27.  
  28. void retranslateUi(QDialog *Dialog)
  29. {
  30. Dialog->setWindowTitle(QApplication::translate("Dialog", "Dialog", 0, QApplication::UnicodeUTF8));
  31. Q_UNUSED(Dialog);
  32. } // retranslateUi
  33.  
  34. };
  35.  
  36. namespace Ui {
  37. class Dialog: public Ui_Dialog {};
  38. } // namespace Ui
To copy to clipboard, switch view to plain text mode