0

i have a CRUD form (more or less) in c++ with lineEdits and Labels upside, and a TableView down. Both have the same QSqlRelationalTableModel. I understood the "A Simple Widget Mapper" example, but how can i do a integration between the TableView and the LineEdits?.

Example: When i click a row in the Table, show those datas upside, and when i double click, i want to open a new window with those datas to Edit them.

I am new in this, i thank you very much. Greetings from Colombia.

bluesky777
  • 400
  • 6
  • 23

1 Answers1

1

Connect to the clicked() signal from the QTableView. See the docs for QAbstractItemView.

Use the provided QModelIndex from the signal to lookup the value in the table and then populate it in the QLineEdit.

For double clicking you can use the doubleClicked() signal.

Cory Klein
  • 51,188
  • 43
  • 183
  • 243
  • ok, but can you show some code of the slot, how do i populate the lineEdit with the QModelIndex, please, sorry my ignorance. – bluesky777 Jul 19 '13 at 13:35
  • I would recommend checking out the Qt Examples. They have exmaples of how to do most of the basic stuff. Spend some time reading the code there to familiarize yourself with how signals and slots work. http://qt-project.org/doc/qt-4.8/all-examples.html – Cory Klein Jul 19 '13 at 16:34
  • Thanks, i've been learning more, but i can't pass the QModelIndex &index from the tableView in a Dialog to a QModelIndex variable of another Dialog, i don't undertand the indirection operator &. – bluesky777 Jul 31 '13 at 17:06
  • @user1658967 Sounds to me like you need a crash course in C++. It will be difficult to write a full Qt application if you don't have an understanding of the fundamentals like what `&` does. Try reading a text book, studying tutorials on the web, or even take a cheap community college course. – Cory Klein Jul 31 '13 at 17:27
  • Ok, i have this code: void MainWindow::calcular(int &num1) { qDebug() << "Número: " << num1; // This shows the number. this->valor = &num1; qDebug() << "Valor: " << this->valor; // Shows a Direction. return; } I UNDERSTAD POINTERS, but how can i pass a Variable &QModelIndex to a pointer that i have in another Form?? – bluesky777 Jul 31 '13 at 17:52
  • @user1658967 - Since that is different from the current question, I would recommend posting that as a new question, then you will have more people than just me available to answer. – Cory Klein Jul 31 '13 at 18:00