Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [SOLVED] 2 QTableViews data

    General and Desktop
    2
    3
    645
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • guidupas
      guidupas last edited by

      Hello all!

      I have a code that create 2 QTableViews dynamically when a QPushButton is clicked:

      @
      void MainWindow::on_pushButtonNovoInvestimento_clicked()
      {
      QTableView *tableViewLancamentosInvestimento = new QTableView(boxInvestimento2);
      QTableView *tableViewIndicadoresInvestimento = new QTableView(boxInvestimento2);

      QStandardItemModel *modeloLancamentosInvestimento = new QStandardItemModel(0, 3, tableViewLancamentosInvestimento);
      QStandardItemModel *modeloIndicadoresInvestimento = new QStandardItemModel(0, 2, tableViewIndicadoresInvestimento);
      
      tableViewLancamentosInvestimento->setModel(modeloLancamentosInvestimento);
      tableViewIndicadoresInvestimento->setModel(modeloIndicadoresInvestimento);
      

      connect(modeloLancamentosInvestimento, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(alteraModeloLancamentoInvestimento(QModelIndex,QModelIndex)));
      }
      @

      But I need that when data of the first model changes, some data of the second model changes too.

      How can I do that once the 2 models are created dynamically?

      I am trying to do something like the code above, but its not working:
      @
      void MainWindow::alteraModeloLancamentoInvestimento(QModelIndex topLeft, QModelIndex bottomRight)
      {
      QStandardItemModel *modeloLancamentosInvestimento = qobject_cast<QStandardItemModel *>(sender());
      }
      @

      How can I access the second model?

      Att.
      Guilherme Cortada Dupas

      1 Reply Last reply Reply Quote 0
      • X
        Xander84 last edited by

        I would suggest you just save a reference to the model or the QTableView in your class?!

        The sender of a signal is always, well the sender (the button in your case?) and not the model, unless that signals is emitted from your first model I can't tell from the code.
        Anyway I would still save a reference to that model or table, why not? it's just a simple pointer :)

        1 Reply Last reply Reply Quote 0
        • guidupas
          guidupas last edited by

          Hey Xander84!

          It worked, thanks a lot.

          Att.
          Guilherme Cortada Dupas

          1 Reply Last reply Reply Quote 0
          • First post
            Last post